Skip to content

GLM-5.3-Flash: TENSORFOLD_MEMORY_LIMIT_GB sets the one-Mac load limit on Metal - #580

Closed
BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:glm-one-mac-limit
Closed

BobClawblaw wants to merge 1 commit into
ashhart:mainfrom
BobClawblaw:glm-one-mac-limit

Conversation

@BobClawblaw

Copy link
Copy Markdown
Contributor

Refs #498.

Problem

The native GLM engine refuses TensorFold/GLM-5.3-Flash-MLX-4bit-MTP on one 256 GB Mac before any weight is read. Engine.loadLimit() is fixed at 70% of RAM (179.2 GB), the language model alone is 180.6 GB, and nothing overrides the limit on Metal.

Change

  • glm/config.zig: loadLimit(ram, budget). With TENSORFOLD_MEMORY_LIMIT_GB set to a positive number, the limit is that many GB, capped at 90% of RAM. Otherwise it stays at 70%, so the default does not change.
  • glm/engine.zig: loadLimit() reads hw.memsize and the variable and calls it. The refusal now names the variable.
  • A host test covers the default, an explicit value, whitespace, the 90% cap, 0, and text that doesn't parse.

Receipts (M5 Ultra, 256 GB, macOS 27.0, this branch on f6dbc6f)

  • zig build test -Dcpu=apple_m1: 129/129 steps, 945/947 tests passed (2 skipped).
  • Full checkpoint, no variable: refused as before, "180.6 GB of weights and 6.3 GB of caches pass this Mac's 179.2 GB load limit (70% of RAM, or TENSORFOLD_MEMORY_LIMIT_GB)".
  • GLM_LAYERS=4 --context 8192:
    • TENSORFOLD_MEMORY_LIMIT_GB=2: refused, "9.6 GB of weights and 3.9 GB of caches pass this Mac's 2.0 GB load limit".
    • TENSORFOLD_MEMORY_LIMIT_GB=40: loads and serves.

A higher limit needs wiring on 256 GB

I'm sending this as a separate PR, since it's a separate change. With the limit raised and the full model loaded, past roughly 110 GB of freshly written buffers the GPU driver's wired collector hands the buffers no command has touched yet to the VM compressor. We saw up to 145 GiB compressed at normal pressure. Once, with a large file cache present as well, the load ended in a jetsam event that killed about 300 system daemons, and then the server.

With the weights wired (mlock) and resident before their reads, the same load takes 22 s instead of 80 s. The compressor stays flat, 183 GiB is wired, and pressure stays normal. I'll open that PR next, referencing #498.

… on Metal

The native GLM engine refused the 4-bit checkpoint on one 256 GB Mac: its load
limit was 70% of RAM (179.2 GB) with no override, and the language model alone
is 180.6 GB. The limit now honours TENSORFOLD_MEMORY_LIMIT_GB as the Python
engine does, capped at 90% of RAM; 70% stays the default. Refs ashhart#498.
@ashhart

ashhart commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw. We've settled the question this was waiting on: 70% of RAM stays the default, and a load past it is allowed only when you ask for it explicitly, with the risk named. One of the 256 GB Macs we test on had a watchdog panic on 6 Oct when a full GLM load wired about 181 GB, which is why we're careful here.

Since you opened this, main gained GLM_LOAD_LIMIT_GB (60c4851), which raises the limit up to 70% of the RAM's bytes, and a one-Mac load that leaves the MTP head on disk when only the head is over (2a6755b). We'll keep one name, so the step past 70% will extend GLM_LOAD_LIMIT_GB rather than add TENSORFOLD_MEMORY_LIMIT_GB. That commit takes your refusal message and credits you as co-author, together with @heitke from #521. Thanks for the receipts here and in #498; I'll close this when it lands.

@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @BobClawblaw. We settled the question this was waiting on: 70% of RAM stays the default, and a load past it happens only when you ask for it, with the risk named. One of the 256 GB Macs we test on had a watchdog panic on 6 Oct when a full GLM load wired about 181 GB, which is why we're careful here.

To keep one name, 601417f extends GLM_LOAD_LIMIT_GB (in main since 60c4851) instead of adding TENSORFOLD_MEMORY_LIMIT_GB. It's in GB. It now goes past 70% of RAM, up to the GPU's recommended working set (about 239 GB on a 256 GB M5 Ultra), and whenever the limit passes the 70% default the server logs the panic risk at startup. A value that isn't a number above 0 stops the server instead of quietly meaning the default, and the refusal names the variable, as yours did. The limit is read once a load, so the load check, stream admission and the prompt-cache budget use one number.

The commit credits you as co-author, with @heitke from #521. Thanks for the receipts here and in #498. I'm closing this in favour of 601417f.

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