Skip to content

GLM on CUDA: under TF_GLM_LAYERS the start-up memory check counts the tensors the load reads (#2745) - #2788

Merged
ashhart merged 3 commits into
ashhart:mainfrom
wojo:up-thin-weights
Nov 11, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
wojo:up-thin-weights

Conversation

@wojo

@wojo wojo commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #2745, as you outlined there: with TF_GLM_LAYERS=N, GLM's start-up memory check counts by tensor from the shard headers, only what the loader reads. On main 14dea6c6a, two commits, authored and committed with my noreply address, no trailers.

What changes

  • zig/src/families/glm/cuda_thin_bytes.zig (new): count returns the files' total unless TF_GLM_LAYERS names a thin load; then bytes opens the checkpoint under model.language_model. and lm_head. (the loader's two prefixes, cuda_weights.zig load) and sums the stored bytes of layers below N, the MTP layers (index num_hidden_layers on) when the load takes them, and every tensor outside a layer (embedding, norm, head). The tower, which cuda_vision_offer counts on its own, is outside both prefixes.
  • weightShare (zig/src/families/glm/cuda_native.zig:143) divides that count by the rank's share, as it divided the files before.
  • The MTP layer loads only with drafts (.mtp = o.drafts), so weightShare takes the open's drafts: one argument added at its only caller, cuda_family_memory.weights. MiniMax M3 and Nemotron ignore it (each says why in a line).
  • Unset, malformed, 0 or more than the config's layers: the count is total, the files, exactly as before. The open still refuses a malformed value by name.

Tests

test-glm-thin-weights-host (new step, in the GLM host set): a synthetic index over two shards (three layers, one MTP layer at index 3, a layer 10, the embedding, norm and head, and a tower tensor in the first shard):

  • TF_GLM_LAYERS=2 counts exactly the embedding, norm, head and layers 0-1; with drafts, the MTP layers as well; 3 adds layer 2; the tower never counts.
  • count with the variable unset, x, 0 or 4 (past the config's 3) returns the files' total unchanged.
  • It fails when every tensor counts (the filter replaced by true).

On the real checkpoint (GLM-5.3-Flash, 45 layers + 1 MTP, read from the headers): the files are 163.6 GiB; TF_GLM_LAYERS=20 counts 66.6 GiB without drafts and 70.4 GiB with them. The 20-layer thin copy we serve from (layers 0-19 and 45 linked from the full checkpoint, 71.7 GiB of files) gives the same two numbers.

TP=2: the count is unchanged when TF_GLM_LAYERS is unset (the same total reaches the same share). With it set, the thin count is divided by the same share as the files were.

Host

  • On this head: test-glm-thin-weights-host, test-glm-startup-host, test-glm-pages-host, test-glm-tp3-host, test-golden and test-cuda-host (5,941 of 5,977, 36 skipped; main's image-route fixture fix makes it complete on macOS now) all pass.
  • fmt clean, cuda_fragment_check clean, lean 386 vs 386 on the base (0 new), tools/pr_check.py: 0 errors.
  • aarch64-linux-gnu native build at both commits.

No device run: the change is in the admission arithmetic before any GPU work, and the header counts above are from the real checkpoint.

🤖 Generated with Claude Code

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @wojo, this follows the outline closely and reads well. What I checked at d39d23f4:

  • bytes opens the checkpoint under the same two prefixes cuda_weights.zig load reads, and reads keeps the layers below N, the MTP layers from num_hidden_layers on, and everything outside a layer, so the tower stays with cuda_vision_offer.
  • The MTP layer counts only with drafts, which matches the load (with_mtp and c.mtp > 0, fed from the open's drafts at cuda_native.zig:273).
  • count parses the value the way cuda_ranks.zig:121 does, and keeps the files' total for unset, malformed, 0 or more than the config's layers, which the open then refuses by name. A failed header read also keeps the total, so the check is never looser than before.
  • With TF_GLM_LAYERS unset the figure is exactly main's at any TP, since count returns total before the same share; with it set, the thin count goes through that share.
  • The test pins the thin sums with and without drafts, leaves the tower out, and keeps the total for null, "x", "0" and "4". MiniMax M3 and Nemotron only gain an unused argument, each with its reason.

The only conflict with main is the CHANGELOG line, which we'll sort out when it lands, so there's nothing for you to do there. Thanks for picking this up so quickly after #2745.

  • Synthena (Ash's Agent)

wojo and others added 3 commits November 11, 2026 10:34
… tensors the load reads, not the files

weightShare took the checkpoint's file bytes and scaled them by the rank's share, so a thin load (TF_GLM_LAYERS=20)
was sized as the whole 163.6 GiB checkpoint. With TF_GLM_LAYERS=N it now counts, from the shard headers, the tensors
under model.language_model. and lm_head. that the loader reads: layers below N, the MTP layers when drafts are on,
and every tensor outside a layer. Unset, malformed, 0 or past the config's layers keep the files' count.

weightShare gains the open's drafts flag; MiniMax M3 and Nemotron ignore it.

Fixes ashhart#2745.
@ashhart
ashhart merged commit 16339c0 into ashhart:main Nov 11, 2026
2 of 10 checks passed
ashhart pushed a commit that referenced this pull request Nov 11, 2026
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thank you @wojo. 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 11, 2026

Copy link
Copy Markdown
Owner

Thanks @wojo! This is in TensorFold 1.2.7, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.7

  • Synthena (Ash's Agent)

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.

CUDA serve's start-up memory check counts the whole checkpoint under TF_GLM_LAYERS

2 participants