[PR #3983] [Other] mac_fit: decide resident vs streaming with the engine's rule (Gyro-S looped on a 48 GB Mac) #4864

Open
opened 2026-11-07 16:30:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3983
Author: @Thomas-Zenkel
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: fix/mac-fit-stream-rule


📝 Commits (3)

  • 358cc5e mac_fit: setup decides resident vs streaming with the engine's rule (12 GiB beside the weights, resident_cap)
  • 4d56071 docs/MAC.md: Gyro-S on 64 GB is resident by the rule but runs out of Metal memory there (#3784)
  • d66f731 Merge Niko1221/Strata main into fix/mac-fit-stream-rule

📊 Changes

3 files changed (+34 additions, -17 deletions)

View changed files

📝 docs/MAC.md (+12 -9)
📝 strata_control/mac_fit.py (+11 -7)
📝 tools/test_setup_mac.py (+11 -1)

📄 Description

Problem and result

On a 48 GB Mac (Apple M4 Pro, macOS 27.0, Strata 0.2.3, engine 0.1.48 metal), Gyro-S at 32K never answered. Setup wrote STRATA_METAL_STREAM=0 into the run config, so the engine kept the model resident instead of streaming it. The weights were paged in and out (7.5 GB swap). A 53-token prompt did not finish in 60 s. The watchdog stopped the engine (no progress for 60 s … reading the prompt, exit -6), and the server started it again, in a loop.

Cause: setup (strata_control/mac_fit.py) and the engine (metal/src/engine/stream.cpp, ExpertStream::wanted) decide "resident or stream" with different numbers. The engine follows setup's value.

rule Gyro-S on 48 GB
setup before weights + 8 GB ≤ 3/4 of the RAM 37.7 ≤ 38.7 GB → resident (0)
engine weights + 12 GiB ≤ resident_cap (here the working set, 40.2 GB on this Mac) 42.6 > 40.2 GB → stream

After: setup uses the engine's rule. With STRATA_METAL_STREAM=1 on the same Mac the engine loaded in 15 s, filled a 19.5 GB expert arena and answered a short question (59 prompt tokens, 48 completion tokens) in 4 s.

#3784 is related: Gyro-S resident on a 64 GB Mac runs out of Metal memory, because the whole 58.5 GB file is wrapped. This PR does not fix that (see Limits). No scope was agreed in an issue for this change.

Approach

  • OVERHEAD_GB is 12 GiB, the engine's figure, instead of 8 GB. On the 48 GB Mac the process held 10.8 GB beside the weights, without the draft layer.
  • gpu_budget_gb also leaves macOS 7 GB or 15% of the RAM on a small Mac, as resident_cap in arena_budget.h does.

Compatibility: I compared setup's decision before and after for every pack at 16, 24, 32, 36, 48, 64, 96, 128, 192 and 256 GB. Three cases change, each to what the engine itself decides when no value is set:

  • Q2_0 on 64 GB: now streams (and so gets no MTP draft layer, STREAM_MTP_FROM_GB = 96)
  • Gyro-S on 48 GB: now streams
  • Gyro-M on 96 GB: now streams

This changes a default on 64 GB Macs (Q2_0) without a measurement there. On 64 GB Macs the old resident start of Q2_0 was 50.5 GB against a cap of 48.1 GB by the engine's own rule.

docs/MAC.md: the "needs about" and "recommended from" columns are recomputed with the new overhead. The Gyro-S row points to #3784.

Validation

Passed:

  • python3 tools/test_setup_mac.py at 4d56071a on macOS (M4 Pro): 27 tests OK. The new test_setup_decides_streaming_as_the_engine_does and the updated test_by_memory fail on the old mac_fit.py (checked by stashing it).
  • The 48 GB M4 Pro with Strata 0.2.3 / engine 0.1.48 metal: with STRATA_METAL_STREAM=1 (set by hand in the installed config, the same value this change makes setup write), Gyro-S 32K loaded and answered as above; no more watchdog restarts.

Failed:

  • python3 tools/test_picture_defaults.py: 2 failures (test_pictures_off_stays_available, test_yes_means_pictures_on_for_qwen_swift_and_coder). They fail the same way without this change.
  • python3 tools/test_strata_mcp.py: 7 failures, 3 errors (Install, StartStop, MixedGraphics, Validation). Same set without this change; the StartStop tests ran while a Strata server was on port 8080.

Not run:

  • No Mac with 64 or 96 GB was available: the three changed decisions are not measured there (Q2_0 streamed on 64 GB, Gyro-M on 96 GB).
  • python -m pytest tests/terminal and npm test in apps/host: not run.
  • No engine build: no C++/Metal file is touched.
  • Speed of Gyro-S streamed on 48 GB on long answers or long prompts: not measured; only the one short question.

Limits

  • Setup still estimates Metal's working set as 3/4 of the RAM (GPU_SHARE); the engine reads the real value (40.2 GB = 78% on this Mac). Both gave the same decision for every pack and size in the comparison above, at 75% and 78%.
  • #3784 stays open: on 64 GB the rule says Gyro-S stays resident, but the engine wraps the whole file and runs out of memory. Counting Gyro's whole file (file_gb) in setup would be the fix on this side; it is left out to keep this PR to one problem.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3983 **Author:** [@Thomas-Zenkel](https://github.com/Thomas-Zenkel) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mac-fit-stream-rule` --- ### 📝 Commits (3) - [`358cc5e`](https://github.com/Niko1221/Strata/commit/358cc5e0c0031d2a07ecd9eb836a563ce4bf2d3d) mac_fit: setup decides resident vs streaming with the engine's rule (12 GiB beside the weights, resident_cap) - [`4d56071`](https://github.com/Niko1221/Strata/commit/4d56071aaabcfca9cef39abd2c8c626cdf6939cc) docs/MAC.md: Gyro-S on 64 GB is resident by the rule but runs out of Metal memory there (#3784) - [`d66f731`](https://github.com/Niko1221/Strata/commit/d66f73157113f42b42c4114f3aea6b0afd56008a) Merge Niko1221/Strata main into fix/mac-fit-stream-rule ### 📊 Changes **3 files changed** (+34 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/MAC.md` (+12 -9) 📝 `strata_control/mac_fit.py` (+11 -7) 📝 `tools/test_setup_mac.py` (+11 -1) </details> ### 📄 Description ## Problem and result On a 48 GB Mac (Apple M4 Pro, macOS 27.0, Strata 0.2.3, engine 0.1.48 metal), Gyro-S at 32K never answered. Setup wrote `STRATA_METAL_STREAM=0` into the run config, so the engine kept the model resident instead of streaming it. The weights were paged in and out (7.5 GB swap). A 53-token prompt did not finish in 60 s. The watchdog stopped the engine (`no progress for 60 s … reading the prompt`, exit -6), and the server started it again, in a loop. Cause: setup (`strata_control/mac_fit.py`) and the engine (`metal/src/engine/stream.cpp`, `ExpertStream::wanted`) decide "resident or stream" with different numbers. The engine follows setup's value. | | rule | Gyro-S on 48 GB | |---|---|---| | setup before | weights + 8 GB ≤ 3/4 of the RAM | 37.7 ≤ 38.7 GB → resident (`0`) | | engine | weights + 12 GiB ≤ `resident_cap` (here the working set, 40.2 GB on this Mac) | 42.6 > 40.2 GB → stream | After: setup uses the engine's rule. With `STRATA_METAL_STREAM=1` on the same Mac the engine loaded in 15 s, filled a 19.5 GB expert arena and answered a short question (59 prompt tokens, 48 completion tokens) in 4 s. ## Related discussion #3784 is related: Gyro-S resident on a 64 GB Mac runs out of Metal memory, because the whole 58.5 GB file is wrapped. This PR does not fix that (see Limits). No scope was agreed in an issue for this change. ## Approach - `OVERHEAD_GB` is 12 GiB, the engine's figure, instead of 8 GB. On the 48 GB Mac the process held 10.8 GB beside the weights, without the draft layer. - `gpu_budget_gb` also leaves macOS 7 GB or 15% of the RAM on a small Mac, as `resident_cap` in `arena_budget.h` does. Compatibility: I compared setup's decision before and after for every pack at 16, 24, 32, 36, 48, 64, 96, 128, 192 and 256 GB. Three cases change, each to what the engine itself decides when no value is set: - Q2_0 on 64 GB: now streams (and so gets no MTP draft layer, `STREAM_MTP_FROM_GB = 96`) - Gyro-S on 48 GB: now streams - Gyro-M on 96 GB: now streams This changes a default on 64 GB Macs (Q2_0) without a measurement there. On 64 GB Macs the old resident start of Q2_0 was 50.5 GB against a cap of 48.1 GB by the engine's own rule. `docs/MAC.md`: the "needs about" and "recommended from" columns are recomputed with the new overhead. The Gyro-S row points to #3784. ## Validation **Passed:** - `python3 tools/test_setup_mac.py` at 4d56071a on macOS (M4 Pro): 27 tests OK. The new `test_setup_decides_streaming_as_the_engine_does` and the updated `test_by_memory` fail on the old `mac_fit.py` (checked by stashing it). - The 48 GB M4 Pro with Strata 0.2.3 / engine 0.1.48 metal: with `STRATA_METAL_STREAM=1` (set by hand in the installed config, the same value this change makes setup write), Gyro-S 32K loaded and answered as above; no more watchdog restarts. **Failed:** - `python3 tools/test_picture_defaults.py`: 2 failures (`test_pictures_off_stays_available`, `test_yes_means_pictures_on_for_qwen_swift_and_coder`). They fail the same way without this change. - `python3 tools/test_strata_mcp.py`: 7 failures, 3 errors (Install, StartStop, MixedGraphics, Validation). Same set without this change; the StartStop tests ran while a Strata server was on port 8080. **Not run:** - No Mac with 64 or 96 GB was available: the three changed decisions are not measured there (Q2_0 streamed on 64 GB, Gyro-M on 96 GB). - `python -m pytest tests/terminal` and `npm test` in `apps/host`: not run. - No engine build: no C++/Metal file is touched. - Speed of Gyro-S streamed on 48 GB on long answers or long prompts: not measured; only the one short question. ## Limits - Setup still estimates Metal's working set as 3/4 of the RAM (`GPU_SHARE`); the engine reads the real value (40.2 GB = 78% on this Mac). Both gave the same decision for every pack and size in the comparison above, at 75% and 78%. - #3784 stays open: on 64 GB the rule says Gyro-S stays resident, but the engine wraps the whole file and runs out of memory. Counting Gyro's whole file (`file_gb`) in setup would be the fix on this side; it is left out to keep this PR to one problem. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4864
No description provided.