Skip to content

GLM-5.3-Flash: resident and wired before the weights are read - #581

Closed
BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:glm-wire-before-reads
Closed

BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:glm-wire-before-reads

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

Refs #498. This is the companion to #580: it makes a raised one-Mac limit safe to use on a 256 GB Mac.

Problem

Loading the full 4-bit checkpoint on one 256 GB M5 Ultra (with #580 and TENSORFOLD_MEMORY_LIMIT_GB=200) wrote about 168 GiB into fresh shared buffers. Past roughly 110 GB, the VM compressor started taking those buffers, even at memory pressure level 1. vm_stat showed 123-145 GiB "occupied by compressor", growing as the load went on. It looks like the GPU driver's wired collector reclaiming buffers that no command buffer has used yet.

GLM_RESIDENCY didn't help, because the set was requested only after the reads, by which point the pages were already compressed.

One load with a large file cache present ended in a jetsam event ("low-swap"): about 300 system daemons were killed, then the server.

Change

  • weights.load takes the residency set and a wire flag. With GLM_RESIDENCY, the weight buffers join the set and residency is requested before runCopies reads anything. The caches and scratch join after the load, as before.
  • GLM_WIRE (new, opt-in): every buffer, caches first, is wired with mlock before it fills. A refused wire, for example past vm.user_wire_limit, fails the load with a log line instead of loading a model the VM can page.
  • Default behaviour, with neither variable set, does not change.

Receipts (M5 Ultra, 256 GB, macOS 27.0)

  • zig build test -Dcpu=apple_m1 on this branch: 129/129 steps, 944/946 tests passed (2 skipped).
  • GLM_LAYERS=8 GLM_WIRE=1 GLM_RESIDENCY=1: wired memory rose by 28 GiB (process footprint 32 GB). It served a request, and the 28 GiB was released at exit.
  • The full checkpoint with GLM-5.3-Flash: TENSORFOLD_MEMORY_LIMIT_GB sets the one-Mac load limit on Metal #580 (TENSORFOLD_MEMORY_LIMIT_GB=200), on 1.0.3/1.0.4 with the same change:
load compressor during load after load
GLM_RESIDENCY only (requested after reads) 80 s grew to 135 GiB, drained about 65 s after residency pressure flapped 2-4 during the load
GLM_RESIDENCY requested before reads — still grew 126 GiB not used
GLM_RESIDENCY + GLM_WIRE 22 s +2.6 GiB 183 GiB wired, about 38 GiB free, pressure 1

A 35-layer wired load (about 140 GB) kept the compressor flat at 1.5-1.7 GiB. An unwired load of the same size was already compressing.

  • After the wired full load, the model served the Spark recipe's quality suite: GSM8K 245/250, MMLU 288/342, long context 42/42 to 102k tokens. It decoded at 93-105 tok/s on one stream.

The existing comment's caution still applies: wiring about 181 GB leaves macOS nothing to reclaim if another model shares the Mac. That's why both variables stay opt-in.

GLM_RESIDENCY now requests the residency set before the parallel reads instead
of after them, and the new GLM_WIRE wires every buffer (mlock) before it fills.
Past roughly 110 GB of freshly written buffers on a 256 GB Mac, the GPU driver's
wired collector handed the buffers no command had used yet to the VM
compressor. Refs ashhart#498.
@ashhart

ashhart commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Thank you for these measurements; the compressor numbers match what we've seen of the GPU driver's wired collector. We can't take this one yet. GLM_WIRE wires every buffer, about 183 GiB in your receipt, and a load that wired about 181 GB through a residency set is what panicked one of the 256 GB Macs we test on, on 6 Oct, with no check-ins from watchdogd for 90 seconds. Your table also shows that requesting residency before the reads didn't stop the compressor by itself; only the wiring did. The loader has changed since (e82ab69 reads through aligned buffers around the page cache and waits while free memory is low), so we want to measure a past-70% load on it ourselves first. If wiring is still needed then, GLM_WIRE should carry the same warning as a raised limit. We'll close this for now and come back to wiring after that run.

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.

2 participants