Repository navigation
qwen27 metal: opt-in idle weight release with Metal's purgeable states corrected - #5040
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/qwen27-idle-release
branch
from
November 25, 2026 12:19
76c0376 to
7b0c288
Compare
Owner
Author
|
Device checks on an M3 Ultra Mac with Qwen3.8-27B-MLX-4bit, main against this head:
Main's
|
ashhart
force-pushed
the
lead/qwen27-idle-release
branch
from
November 25, 2026 20:23
7b0c288 to
6260b2e
Compare
ashhart
force-pushed
the
lead/qwen27-idle-release
branch
from
November 25, 2026 22:59
6260b2e to
7690e36
Compare
Owner
Author
|
Rechecked at 7690e36, after we moved this change onto main's new lane loop (it now lives in
This goes into a landing train now. Thank you!
|
qwen27_idle.zig imported qwen27_engine.zig, the native file that picks the 27B or the pinned 2B engine for a checkpoint; it exports no model, so the macOS native Metal build failed on q.model.IdleRelease. The file now imports the family as its neighbours do, @import("tensorfold").qwen27, whose model.IdleRelease the idle release commit already made public. No other change; behaviour is unchanged.
…parison std.Io's clock returns nanoseconds as i96, but the idle release owner took and stored them as i64, so the native Metal server's two calls failed to compile on macOS. The owner now takes and keeps i96 timestamps, as the clock returns them; the configured quiet interval stays i64 and widens in the comparison. Values, comparisons and behaviour are unchanged.
…'s main Main's zig/src/core/lane_host.zig is 600 lines and the idle release's field and restore call make it 601. Main's comment on the queue's foreground-before-background order moves onto the statement it describes; no code changes.
…d NonVolatile with a discard check on restore The Metal bridge passed raw 2 (NonVolatile) to release and raw 1 (KeepCurrent) to restore, each one step off MTLPurgeableState, so released weights never became discardable and a restore never made them non-volatile again. metal/purgeable.zig names the states as the Metal ABI numbers them (KeepCurrent 1, NonVolatile 2, Volatile 3, Empty 4): makeVolatile asks for Volatile, and makeNonVolatile asks for NonVolatile and returns whether the previous state was Empty, the OS having discarded the contents. Restore now makes every released buffer NonVolatile before any read, then reloads and checks the SHA-256 of only the buffers whose contents were discarded; a buffer the OS kept holds the bytes that were serialized. An extent stays marked for reload until its reload succeeds, so a refused restore (short or corrupt snapshot) retries it in full. Off (TF_Q27_IDLE_RELEASE unset) nothing changes, and tokens stay those of the serial reference: every byte a GPU command reads is the serialized one. test-qwen27-idle-release-host gains purgeable.zig's ABI test, which fails with the old 2 and 1, and a restore test with one kept and one discarded buffer, which fails with the old reread-everything restore.
ashhart
force-pushed
the
lead/qwen27-idle-release
branch
from
November 26, 2026 02:50
7690e36 to
04022a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An opt-in idle weight release for Qwen3.8-27B on Metal, with Metal's purgeable states corrected.
What it does:
TF_Q27_IDLE_RELEASEtakes whole quiet seconds, from 0 through 86400. The default, 0, keeps the weights wired as now. With N > 0, after N quiet seconds the server:The next request makes every released buffer NonVolatile before any read, and reloads only the buffers the OS emptied, checking each one's SHA-256 against the snapshot. A buffer the OS kept was never written while released.
The fix over the first version:
MTLPurgeableStateis KeepCurrent 1, NonVolatile 2, Volatile 3, Empty 4. The first version passed 2 on release, so nothing was ever discardable, and 1 on restore, so a discarded buffer never became non-volatile again.zig/src/metal/purgeable.zignow names the states by their ABI numbers.Off is main: with the setting unset or 0, no release state exists,
lane_activity.restorereturns at once, and the idle turn runs exactly as main'slane_rounds.zigdid. One commit only moves a comment inlane_host.zigto keep it at 600 lines.Tests:
test-qwen27-idle-release-hostpins the four ABI values.Checks so far:
Device check to come: a real idle cycle on a Mac, with the setting unset, explicitly 0, and 40. Tokens must equal the serial reference in each.