Skip to content

glm metal: price the rows-store staging permit from the family's whole image - #4216

Merged
ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:glm-staging-permit-4114
Nov 24, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
devopsfortunato:glm-staging-permit-4114

Conversation

@devopsfortunato

Copy link
Copy Markdown
Contributor

Size the GLM-5.3-Flash Metal host's rows-store staging permit the way #2388 sized the Qwen3.8-27B host's — fixing #4114.

Today the GLM Metal host attaches the rows store without staging_bytes, so the permit stays at the store's 1 GiB default (zig/src/core/rows_store.zig). Once a conversation's pending save charge passes 1 GiB, every deep save is skipped with StagingFull, and after a restart the next turn is a full re-prefill.

Change:

  • Price the permit from the family's whole image at the window: glm.snapshot.bytes(&eng.c, window, false) — the same figure a disk read allocates (blank_bytes in glm_disk.zig). Floored at the 1 GiB default, capped by the store budget (--learn-gib), at the single attach call site (zig/src/native/glm_host.zig).
  • Operator override TF_GLM_STAGING_GIB: a GiB count that stands in for the priced figure, still clamped to the budget. A value that does not parse (or is 0) fails the open loudly, with the variable and offending value named in the log — never a silent fallback.
  • New dependency-free module zig/src/native/glm_staging.zig (std only) so the permit math is host-testable on Linux without Metal; wired as test-glm-staging-host and into the aggregate host test step (zig/build/glm_family_host.zig).

Behavior on an overflowing override (GiB count whose byte product leaves a u64): the priced figure stands rather than a wrapped 0 that would skip every save — pinned by a test.

Host verification (Linux, Zig 0.17.0 per .zig-version):

  • zig test zig/src/native/glm_staging.zig -lc — 6/6 tests pass
  • zig build test-glm-staging-host — 6/6 pass (also runs under test-cuda-host)
  • zig build test-cuda-host — pass on repeated runs
  • zig fmt --check on all three touched files — clean

ATC: issue #4114 claimed (comment 7038972091); atc overlap --json run before opening — the reported overlaps are repo-scale noise from open PRs sharing zig/src/native/glm_host.zig in its include graph; no scoped conflict with this change's three files' diff surface.

@AIFlowML

Copy link
Copy Markdown
Contributor

The six staging helper tests passed on M5 Max with Zig 0.17.0. At b7298b4e, the GLM tool-streaming changes under this branch are already on main. Trial-merging just 7cf24869 leaves two conflicts, in glm_family_host.zig and at the glm_disk.identity / rows attach call in glm_host.zig.

There is a smaller path on current main. The shared rows.attach already accepts .longest from #2388, and Qwen uses it. It prices the cold write, including metadata, trailers and worker bookkeeping. snapshot.bytes measures the payload, so its value alone can leave a cold write over the permit. In scratch I added .longest = serves at GLM's attach call, using the same effective context the host advertises. These targets passed 182 tests:

zig build test-rows-host test-glm-snapshots-host test-glm-request-starts-host \
  -Dcpu=apple_m1 -j5 --summary all

The focused test-rows-host -Drows-filter='a permit sized to the longest state writes a cold save' also passed. The regression verifies that the shared permit admits a cold save the fixed permit skips. A checkpoint restart on Metal is still needed to confirm the issue's specific workload.

Igor Lessio - AIFLOW LABS

@devopsfortunato
devopsfortunato force-pushed the glm-staging-permit-4114 branch 2 times, most recently from 355992b to 5b983fd Compare November 20, 2026 16:46
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

@devopsfortunato, thank you for this; it applies cleanly to today's main. One change to how the permit is priced, before it lands:

  • The explicit permit at zig/src/native/glm_host.zig:147-149 prices only the state payload (zig/src/families/glm/snapshot.zig:45-48), but a cold write also charges metadata, trailers and worker bookkeeping (zig/src/core/rows_write.zig:328-345), so a deep save can still skip with StagingFull. It also clamps against l.cap, the disk cap, where rows.attach clamps .longest to the RAM store budget (zig/src/core/rows_store.zig:69-76).

  • The smallest fix: replace glm_host.zig:146-149 with the existing attach options plus .longest = serves (serves is already at :115; Qwen does the same at zig/src/native/qwen27_disk.zig:137), and drop the manual staging_bytes and its import at :10.

  • That makes zig/src/native/glm_staging.zig, its build registration (zig/build/glm_family_host.zig:84-87), its cases in zig/src/families/glm/cuda_env_test.zig and TF_GLM_STAGING_GIB (zig/src/platform/environment.zig:146) unnecessary, so they can go. The regression at zig/src/core/rows_stage_test.zig:149-170 already tells a .longest cold save from a fixed-permit skip.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I tried Ash's suggested .longest = serves change on a clean trial of 5b983fda into 7d243251. In scratch, I kept the existing attach options, used .longest = serves, and removed the custom permit helper, test registration and environment key. The remaining diff against main is just the GLM rows-attach option.

On M5 Max with Zig 0.17.0, all 185 tests and 81 steps passed. The existing longest-state fixture in test-rows-host checks that the computed permit writes a cold save that the fixed permit skips. The native Metal server also built.

zig build test-rows-host test-environment-host test-slide-metal-host native \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all

The published head still has the explicit permit. These results cover the suggested replacement and the rows fixture, with a live GLM checkpoint outside this run.

Igor Lessio - AIFLOW LABS

@devopsfortunato

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart and @AIFlowML — agreed on both points: the explicit permit priced only the payload (not the metadata, trailers and worker bookkeeping a cold write also charges) and clamped against l.cap instead of the RAM store budget.

Reduced as suggested and force-pushed (bf6e688cd, rebased on b112ad68c): the whole PR is now one option, .longest = serves, on GLM's rows.attach call in zig/src/native/glm_host.zig (same shape as qwen27_disk.zig:138). glm_staging.zig, its build step, the TF_GLM_STAGING_GIB rule and the env-test cases are gone.

Linux host checks on the reduced head: test-rows-host 149/149, test-glm-snapshots-host, test-glm-prompt-settings-host, test-environment-host 32/32, test-cuda-host aggregate (2006 passed, 15 GPU-gated skipped), zig fmt clean, lean_check no new findings on glm_host.zig. Checking a live GLM checkpoint restart on Metal is still outstanding on my side (no Mac here); @AIFlowML's M5 Max run covers the build and the rows fixture, thank you.

@devopsfortunato

Copy link
Copy Markdown
Contributor Author

CI note: on head bf6e688 the only failing check was zig-windows, with 10635/10882 tests passed and a single test failure: core.rows_borrowed_test.test.borrowed spill: a newest keep waits for the earlier write and restores after its rows expire, plus error.Unexpected NTSTATUS=0xc000013b (LOCAL_DISCONNECT) / PIPE_DISCONNECTED and DeviceLost noise in unrelated lanes tests — Windows-environment flake, none of the failures touch this PR's surface (zig/src/native/glm_staging.zig, glm_host.zig, glm family build wiring). Pushed an empty commit (2643e9f) to retrigger the job.

@ashhart
ashhart force-pushed the glm-staging-permit-4114 branch from 2643e9f to 658992b Compare November 24, 2026 06:01
@ashhart
ashhart merged commit a061e05 into ashhart:main Nov 24, 2026
3 of 12 checks passed
@ashhart

ashhart commented Nov 24, 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 added a commit to plotarmordev/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
…never added

Twenty lines under Unreleased landed with a literal (#N); each now carries the PR
that added it. #4216's line named TF_GLM_STAGING_GIB, which is not on main.
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.

3 participants