Skip to content

native/cuda_memory: count every file the weight map names in weightBytes - #1022

Closed
Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/fp4local-weightbytes
Closed

Bizuayeu wants to merge 1 commit into
ashhart:mainfrom
Bizuayeu:pr/fp4local-weightbytes

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

weightBytes, the estimate that refuses a launch that cannot fit, now counts each file that model.safetensors.index.json's weight map names, once, so shards in a subfolder are no longer left out (#1015). Without an index, or with an index that has no weight map, it counts the folder's own *.safetensors as before. In 1.1.0 the estimate is called from native/cuda_family_memory.zig, which now passes its allocator.

  • nvidia/GLM-5.3-Flash-FP4-Local keeps one shard in tensors/ (tensors/native-QB.safetensors).
  • nvidia/Qwen3.8-Flash-Next-FP4-Local keeps all of its shards there.

Receipt

  • Environment: TensorFold 1.1.0 (76aafcf2) plus this commit, Zig 0.17.0. Host tests on x86_64 Linux, on an LF tree from git archive. The byte counts below are the files' sizes on a GB10.
  • The estimate before and after:
    • nvidia/GLM-5.3-Flash-FP4-Local@76348ddb: 176,710,148,760 → 177,463,841,024 bytes. The difference, 753,692,264, is tensors/native-QB.safetensors.
    • nvidia/GLM-5.3-Flash-NVFP4@da920bb: 204,439,103,396 both ways. All 33 of its files are in the folder.
  • Exactness: n/a. Only the admission estimate changes.
  • Decode speed before and after: n/a, for the same reason.
  • Prompt speed before and after: n/a, for the same reason.
  • Tests run:
    • zig build test: 152/152 steps, 2414/2423 tests passed, 9 skipped.
    • zig build test-kernel-contract, test-golden, fuzz-cortheon, the tools/zig unittest (flashnext_batch_serve_test.py) and a plain zig build: succeeded.
    • lean: 0 new problems (503 on main). git diff --check: clean.
    • The new test covers three cases: no index (the folder's own files, not the subfolder's); an index (each named file once, the subfolder's too); and an index without a weight map (the folder's own files).
  • Not run: a CUDA launch, since the estimate is checked by the host test and the byte counts above. Metal, since the file is CUDA's.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (Only the admission estimate changes.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (No inference path changes.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No arithmetic changes.)
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt. (No GPU kernel.)
  • Prompt processing is no slower than the last release. (No served path changes; the index is read once at admission.)
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (Host tests on x86_64 Linux; the byte counts on a GB10; no CUDA launch, no Metal.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (Before it, the indexed case counts 110 bytes instead of 17.)
  • Comments and docstrings are one line. No measurements or history in the source. (lean: 0 new problems.)
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@ashhart

ashhart commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu for finding the missing 753,692,264-byte shard in the admission estimate, while the existing NVFP4 checkpoint stays at 204,439,103,396 bytes. We're taking this with fixes for 1.1.1. Distinct indexed filenames, including subfolders, are counted once. Review added refusal for missing named files, malformed indexes and allocation/stat failures, so a broken index cannot silently become a smaller flat-folder estimate. Valid no-index folders retain their old counting behavior. This changes admission accounting, not inference. The host and admission-refusal controls cover those cases; complete FP4-Local loading and rank/device checks remain under #1015.

Posted by Ash's AI Assistant Synthena

@ashhart ashhart mentioned this pull request Oct 18, 2026
…s, so shards under tensors/ are no longer left out of the estimate
@Bizuayeu
Bizuayeu force-pushed the pr/fp4local-weightbytes branch from 41dca5c to 694c62a Compare October 18, 2026 13:14
@Bizuayeu

Copy link
Copy Markdown
Contributor Author

Rebased onto 1.1.0 (76aafcf2): the estimate's caller moved to native/cuda_family_memory.zig, so this now passes the allocator there. The receipt above is from the rebased commit.

ashhart pushed a commit that referenced this pull request Oct 19, 2026
Credit: @Bizuayeu for indexed shard counting and its original fixture.
Include mandatory maintainer refusal fixes for broken maps, missing files and allocation errors.
Route the named refusal through the maintained family-memory admission owner.
@ashhart

ashhart commented Oct 19, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu. 1.1.1 counts each indexed filename once, including subfolders, and refuses malformed indexes, missing/non-file shards, allocation/stat failures and overflow before loading. Only an absent index or weight map falls back. Your 694c62a rebase retains the original permissive reader; our maintained fail-closed equivalent already covers the required repair. Closing for the shipped accounting scope, with your credit retained. Mixed-format GLM serving remains a separate checkpoint gate.

Posted by Ash's AI Assistant Synthena

@ashhart ashhart closed this Oct 19, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…art#1022)

Credit: @Bizuayeu for indexed shard counting and its original fixture.
Include mandatory maintainer refusal fixes for broken maps, missing files and allocation errors.
Route the named refusal through the maintained family-memory admission owner.
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 22, 2026
…older; shard edits keep plain names

1.1.2's shared index check (46ce6df) takes a shard only as a plain file name, so an index that maps tensors into a
folder of the model folder is refused with BadIndex. nvidia/GLM-5.3-Flash-FP4-Local (ashhart#1050) is stored that way: its
index at revision 76348ddb maps 214 of its 295,041 tensors to tensors/native-QB.safetensors, the layout ashhart#1022's
cuda_memory test sizes.

- weightMap takes a plain name, or plain names joined by '/' with none starting with '.': each part goes through
  plainName (no empty part, no '.' or '..', no drive, backslash or device name), as cli/pull_file.zig's
  snapshotPathOk checks a hub path, so a shard stays inside the model folder and out of its hidden folders.
- shard_edit's bake, grow and overwrite, through which Living Weights, --slide and LoRA merges write shards, check
  with plainWeightMap and keep plain names: the link checks before --slide look at a shard's own entry only
  (shard_edit.linked at the folder's entries, Flash Next's and Qwen3.5's at each index path's last part), so a shard
  in a folder, or a linked folder, would pass them unseen.
- --slide refuses such a checkpoint at startup, after its link checks (slide_adapter.refusal), rather than at its
  first save, where shard_edit's refusal would leave the save pending until a rollback.
- RADIO's image shards compare the index's names with the shard paths past the model folder, not their basenames.
- Tests: the part rules in checkpoint_index.zig. In the security tests, a checkpoint with its shard in a folder
  opens; overwrite, grow and bake refuse such an index before writing; an overwrite through a linked folder leaves
  the file outside unchanged; sub/model.safetensors leaves the list of names that escape the folder. The slide
  adapter's tests hold the startup refusal; RADIO finds its image shard in a folder.
ashhart pushed a commit that referenced this pull request Oct 22, 2026
…older; shard edits keep plain names

1.1.2's shared index check (46ce6df) takes a shard only as a plain file name, so an index that maps tensors into a
folder of the model folder is refused with BadIndex. nvidia/GLM-5.3-Flash-FP4-Local (#1050) is stored that way: its
index at revision 76348ddb maps 214 of its 295,041 tensors to tensors/native-QB.safetensors, the layout #1022's
cuda_memory test sizes.

- weightMap takes a plain name, or plain names joined by '/' with none starting with '.': each part goes through
  plainName (no empty part, no '.' or '..', no drive, backslash or device name), as cli/pull_file.zig's
  snapshotPathOk checks a hub path, so a shard stays inside the model folder and out of its hidden folders.
- shard_edit's bake, grow and overwrite, through which Living Weights, --slide and LoRA merges write shards, check
  with plainWeightMap and keep plain names: the link checks before --slide look at a shard's own entry only
  (shard_edit.linked at the folder's entries, Flash Next's and Qwen3.5's at each index path's last part), so a shard
  in a folder, or a linked folder, would pass them unseen.
- --slide refuses such a checkpoint at startup, after its link checks (slide_adapter.refusal), rather than at its
  first save, where shard_edit's refusal would leave the save pending until a rollback.
- RADIO's image shards compare the index's names with the shard paths past the model folder, not their basenames.
- Tests: the part rules in checkpoint_index.zig. In the security tests, a checkpoint with its shard in a folder
  opens; overwrite, grow and bake refuse such an index before writing; an overwrite through a linked folder leaves
  the file outside unchanged; sub/model.safetensors leaves the list of names that escape the folder. The slide
  adapter's tests hold the startup refusal; RADIO finds its image shard in a folder.
@Bizuayeu
Bizuayeu deleted the pr/fp4local-weightbytes branch October 25, 2026 07:27
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