Skip to content

qwen27: a refusal that no --parallel or --context fixes names the wired-limit raise - #2123

Merged
ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:qwen27-wired-limit-2101
Nov 6, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:qwen27-wired-limit-2101

Conversation

@devopsfortunato

@devopsfortunato devopsfortunato commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

On a 32 GB Mac with the default iogpu.wired_limit_mb=0, the Qwen3.8-27B startup refusal tells you to lower --parallel or --context even when that can't help, because one stream at the smallest context still doesn't fit under Metal's working set. Now, when even one stream doesn't fit, the refusal names Metal's working set and the iogpu.wired_limit_mb value that fits one stream at the requested context. With numbers like the issue's 8K case (the new test uses them):

--parallel 1 needs 4.3 GiB for its streams and 512-row prompt scratch at a 8192-token context; 2.7 GiB remains beside the weights and an 8 GiB margin: Metal lets this Mac use 21.3 GiB; sudo sysctl iogpu.wired_limit_mb=23449 raises that limit enough for one stream at this context until reboot (or lower --context)

A raise is suggested only when the suggested limit still leaves 4 GiB of RAM outside the GPU's share for macOS and other processes. Otherwise it says no wired-limit raise fits one stream and leaves 4 GiB of this Mac's 16.0 GiB of RAM to the system: lower --context instead. The old text stays byte-for-byte when fewer streams would fit, or when TF_QWEN27_WORKING_SET_BYTES lowers the working set (the sysctl advice would be wrong there).

  • prompt_memory.zig: the 8 GiB margin is one constant now; wiredRaise (used + need + margin, rounded up to MiB, null unless that limit leaves a 4 GiB floor) and advice/Advice choose and format the refusal's tail. They're pure functions, so Linux CI tests them.
  • qwen27_served.zig: the refusal adds that tail. room() and the advice read the cap through one cap() helper, so the "Metal lets this Mac use" figure is the same working set the "remains" figure came from.
  • zig/build/qwen27_host.zig: test-qwen27-memory-host now also runs under zig build test (it was a named step only, so CI didn't run it).
  • README: the Qwen3.8-27B row says a 32 GB Mac needs iogpu.wired_limit_mb raised, and that the refusal names the value (suggestion 2 in the issue).

Suggestion 3 in the issue, the prompt cache holding nothing at a 32K window, is left out. It's a separate change.

Checks on this head

  • Head commit: 2f8a13cd2 (base b331731e6). The full suite below ran on 76a9084c5; 2f8a13cd2 changes only prompt_memory.zig and its tests, and for it I reran test-qwen27-memory-host (9/9; the new floor edge fails on the old code with expected null, found 23552), zig fmt --check and the lean checker (425, 0 new). CI covers the rest.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: base 425 problems, head 425 problems; lean_new.py: 0 new.
  • Tests run, with the command and pass, fail and skip counts (DGX Spark, GB10, Linux aarch64, Zig 0.17.0; the no-GPU CI steps):
    • zig build test --test-timeout 10m: 532/532 steps succeeded, 0 failed (base: 530/530; the two new steps are the memory test's compile and run). Test count on this run: 6865/6924 passed, 59 skipped, the same as the base run.
    • zig build test-qwen27-memory-host: 9/9 (3 new tests). Red before the change: the new tests don't compile against the old prompt_memory.zig (no member named 'wiredRaise', 'Advice').
    • zig build test-kernel-contract: 22/22 steps, 179/179
    • zig build test-golden: 5/5 steps, no golden changed
    • zig build test-server-security test-pull-security: 14/14 steps, 28/28
    • zig build fuzz-cortheon: 3/3 steps, 19/19
    • zig build (plain): 31/31 steps
    • python3 -m unittest discover -s tools/tests -p "test_bench*.py": 74 OK; flashnext_batch_serve_test.py: 8 OK; build_options_test.py: 5 OK; cuda_common_check.py: exit 0
    • zig fmt --check build.zig zig: clean; git diff --check: clean
    • qwen27_served.zig only builds on macOS, so I type-checked it with a throwaway build step (not committed). The step compiled zig/qwen27_speed_compile.zig, which reaches open → attach, for aarch64-macos, wired like compileHost but without frameworks: success. Renaming memory.advice in that copy made the same step fail at the refusal line, so the step does compile this branch.
  • CI: runs on this pull request.
  • Not run, and why: there's no Mac here, so I didn't run on a 32 GB Mac or the macOS and Windows CI legs. The macOS dev-tools job compiles qwen27_served.zig for real. I also skipped the NFKD table check, which needs Python 3.14's unicodedata; this change doesn't touch the tables.

Receipt

n/a: the change is only the text of a startup refusal plus a host test, and it never reaches inference. No token, kernel, precision, scheduling or memory-admission decision changes. The refusal fires in exactly the same cases as before.

Floor: a fixed 4 GiB. macOS's own default keeps a third of RAM below about 96 GB, so using that as the floor would rule out any raise on a 32 GB Mac. The issue's case still gets a value: 23449 MB, which leaves 9.1 GiB. The reporter's 29696 left 3 GiB, under the floor, but one stream there needs much less than that.

Known limitation: the suggested value is the exact MiB ceiling of what room() counts (weights and buffers allocated so far, one stream's scratch, the 8 GiB margin). If macOS reports a working set slightly under the sysctl value, the next 128 MiB up would cover it. @ghaslbe offered to test on the M1 Max 32 GB, and that run would show whether 23449-style values start the server as they are.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency (host-only; no dependency).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato, this turns a refusal that pointed at the wrong knob into one that names the right one, and the pure functions make it testable on Linux. One change: wiredRaise allows the suggested limit to reach the Mac's whole RAM, since the 8 GiB margin sits inside the GPU's share, not outside it. On a 32 GB Mac that could tell someone to wire nearly all of it. Could it suggest a raise only when it leaves the system a floor, say what macOS keeps by default, and otherwise say to lower --context? A test at the edge would pin it. @ghaslbe's M1 Max run would then show whether the value starts the server as is.

@devopsfortunato

Copy link
Copy Markdown
Contributor Author

Thanks, done in 2f8a13cd2. wiredRaise now suggests a limit only when that limit, rounded up to whole MiB, still leaves a 4 GiB floor of RAM outside the GPU's share. Otherwise the refusal says no wired-limit raise fits one stream and leaves 4 GiB of this Mac's N GiB of RAM to the system: lower --context.

I used a fixed 4 GiB instead of what macOS keeps by default. Below about 96 GB, macOS's default limit is two thirds of RAM, so it keeps a third. On a 32 GB Mac that's about 10.7 GiB, which would cap the suggestion at the default limit, and a raise could never be suggested there. With 4 GiB, the issue's 8K case still gets 23449 MB, which leaves 9.1 GiB.

The test now pins the edge: at RAM = limit + 4 GiB it suggests the value, and one byte less returns null. Another case fits in RAM but not above the floor, and the advice table has a 26 GiB row where only the floor rules a raise out. test-qwen27-memory-host passes 9/9, and on the old code the edge fails with expected null, found 23552. The lean checker still reports 425, the same as main, so nothing new. I'm happy to change the floor if you'd rather have a different number.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @devopsfortunato. A fixed 4 GiB floor is a sensible choice, and your reasoning about macOS's default limit on 32 GB Macs is right. The edge test pins it. Ready to land. @ghaslbe, if your M1 Max run happens, it'll show whether the suggested value starts the server as is.

devopsfortunato and others added 3 commits November 6, 2026 03:37
…ed-limit raise (ashhart#2101)

When even one stream does not fit beside the weights and the 8 GiB margin, the startup refusal now names
Metal's working set and the iogpu.wired_limit_mb value that fits one stream at this context, or says no raise
fits this Mac's RAM. The text is unchanged when fewer streams would fit or TF_QWEN27_WORKING_SET_BYTES caps the set.
The qwen27 memory host tests now run under zig build test.
)

wiredRaise suggests a limit only when its whole MiB still leaves 4 GiB of RAM outside the GPU's share;
otherwise the refusal says no raise fits and to lower --context. Tests pin the edge.
@ashhart
ashhart force-pushed the qwen27-wired-limit-2101 branch from 2f8a13c to 7106eae Compare November 6, 2026 03:37
@ashhart
ashhart merged commit 51b830e into ashhart:main Nov 6, 2026
11 checks passed
@ashhart

ashhart commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Thank you @devopsfortunato. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Qwen3.8-27B on 32 GB Macs: refused at every context until iogpu.wired_limit_mb is raised, and the refusal doesn't say so

2 participants