Skip to content

cuda: Nvfp4Experts.packGateUp packs gate and up in place, no scratch - #763

Merged
ashhart merged 1 commit into
ashhart:mainfrom
Bizuayeu:pr/nvfp4-pack-in-place
Oct 16, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
Bizuayeu:pr/nvfp4-pack-in-place

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

packGateUp packed each matrix into a scratch half and copied the halves into their interleaved places: two
allocations and a copy per expert. A loader packs every routed expert of every layer this way, and on
GLM-5.3-Flash at TP=2 the fresh pages and copies added about 20 s to the load. packOne's loop now takes the
matrix's place among the stacked parts, so packGateUp writes gate and up straight where they go and needs no
allocator. The words are the same.

Receipt

  • Environment: TensorFold 1.0.9 (c36b536d) plus this change; one GB10 (DGX Spark, sm_121, CUDA 13.3).
  • Exactness: the packed words are byte-equal; a host test checks packGateUp against packOne's blocks
    interleaved.
  • Decode and prompt speed: not applicable (load time only).
  • Tests run:
    • zig build test-cuda-host: 430 passed, 0 failed; the new "packGateUp stacks packOne's gate and up blocks per
      (column block, k32 group)" needs this change.
    • tf-cuda-test quant-ref: 4 PASS (the experts' products from the packed words).
    • zig build test: 316 passed, 5 skipped, 0 failed. zig fmt --check: clean. lean_check: 538, as main.
  • Not run, and why: Metal (CUDA only).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

packGateUp packed each matrix into a scratch half and copied the halves into their interleaved places, two
allocations and a copy per expert. A loader packs every routed expert of every layer this way (GLM at TP=2: 45 x
256 experts, 2.4 MB a half), and the fresh pages and the copies put about 20 s on the load. packOne's loop now takes
the matrix's place among the stacked parts, so packGateUp writes gate and up straight where they go, and it needs
no allocator. The words are the same: a host test checks packGateUp against packOne's blocks interleaved.
@Bizuayeu
Bizuayeu force-pushed the pr/nvfp4-pack-in-place branch from a3e74aa to a055fb6 Compare October 13, 2026 19:24
@Bizuayeu

Copy link
Copy Markdown
Contributor Author

Rebased onto 1.0.9 (c36b536d), the commit's lines unchanged. Host tests 430/430, zig build test 316 passed, 5 skipped.

@ashhart
ashhart merged commit 4d9cfc8 into ashhart:main Oct 16, 2026
4 checks passed
ashhart added a commit that referenced this pull request Oct 16, 2026
ashhart added a commit that referenced this pull request Oct 16, 2026
The contributor's five GLM commits landed above, with our fixes after them; the head's first seven commits are the same changes as #757, #758, #766, #762, #764 and #763, which the candidate already has from their own heads. This keeps the PR's head in the history with no change to the tree.
@ashhart

ashhart commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Thank you, @Bizuayeu. Packing gate and up straight into their places takes two allocations and a copy off every routed expert of every layer, which adds up fast at GLM-5.3-Flash's expert count.

It ships in TensorFold 1.0.12 under your name (204d4e416), with our 033163a58 wrapping the rewritten call in quant-ref at 120 columns. Your head is merged after them with no change to the tree (4d9cfc8d0), so this pull request shows as merged.

Your host test (packGateUp against packOne's blocks interleaved) passes on macOS and Linux. On a GB10, tf-cuda-test quant-ref and tf-cuda-test modelopt pass with the same largest differences as the build before, number for number. Nemotron's NVFP4 experts have no gate, so it never calls packGateUp, and its replies are the same tokens as before.

The load-time saving comes with the loader that packs every routed expert (#804); we have not timed it on our side.

Posted by Ash's AI Assistant Synthena

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The contributor's commit landed above with the same code; this keeps the PR's head in the history with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…date

The contributor's five GLM commits landed above, with our fixes after them; the head's first seven commits are the same changes as ashhart#757, ashhart#758, ashhart#766, ashhart#762, ashhart#764 and ashhart#763, which the candidate already has from their own heads. This keeps the PR's head in the history with no change to the tree.
@Bizuayeu
Bizuayeu deleted the pr/nvfp4-pack-in-place 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