Skip to content

cuda: the affine-4 repack beside its format (qlinear.zig, affine4_pack.cu); Nemotron's loader packs through it - #602

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-affine4-pack
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:cuda-affine4-pack

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

The follow-up you suggested on #587: the affine-4 packing moves next to its format.

  • zig/kernels/cuda/affine4_pack.cu: tf_pack_dense and tf_transpose_pad16, moved verbatim from nemotron_ops.cu. They're the MLX words into the lane tiles, and the (n, kg) scales and biases into (kg, npad). nemotron_ops.cu keeps its serial feed, routed plan and rests.
  • cuda/qlinear.zig:
    • Affine4.layout(n, k) gives the tiled sizes (rows to whole 128s, the words' and the scales' bytes).
    • Affine4Kernels.pack(s, words, scales, biases, q) launches the two kernels as the loader did.
    • resolve takes the pack module.
  • families/nemotron/cuda_weights.zig: tile sizes its buffers with Affine4.layout and packs through Affine4Kernels.pack. Kernels loads one module more and drops its two pack functions.

Receipts on GB10 (DGX Spark, sm_121, CUDA 13.0). main (2f8284e) and this branch were each built with nvcc for sm_121:

  • zig build test passes and lean_check is clean for the touched files. zig fmt --check build.zig zig flags only files outside this PR.
  • SASS (cuobjdump -sass -fun): tf_pack_dense (216 lines) and tf_transpose_pad16 (160) in affine4_pack.fatbin equal main's in nemotron_ops.fatbin. The three kernels left in nemotron_ops.cu (tf_serial_feed, tf_plan_routed, tf_rest_rows) are unchanged.
  • Nemotron 3.5 Lightning MLX-4bit @ d9d758fb, every projection packed through the moved code:
    • tensorfold check-kernels: 1,008 of 1,008 projection cases (976 split-K) and 384 of 384 forked-MoE cases, both builds.
    • tensorfold run: three prompts (11, 20, 1,090 tokens), greedy and sampled (0.8 / 20 / 0.95, seed 7). All six reply hashes equal main's: 5923b40d570b, d38725819372, ead827be94f5, bb8855c2f084, 068276d3ec75, a6961a8c7589.

@ashhart ashhart mentioned this pull request Oct 10, 2026
@ashhart
ashhart merged commit d2f883c into ashhart:main Oct 10, 2026
1 of 2 checks passed
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. This is merged into main (d2f883c), your commit as it was, and it ships in 1.0.6. On a GB10 against main, check-kernels passes 1,008 of 1,008 projection cases and 384 of 384 forked-MoE cases on both builds, and 29 of 29 served replies are equal, with drafted == plain and concurrent == solo 10 of 10 in each arm. The four release prompts give the same SHAs drafted and serial, decode is within 0.5% and cold prompts within 1%.

One fix on top: #591 had landed a tf-cuda-test train check that launched pack_dense from the Nemotron kernels, so tf-cuda-test no longer compiled on Linux after the merge. 9041e20 packs it through Affine4Kernels.pack, and its dequantization still matches MLX's in every value. The release fatbins gain affine4_pack.fatbin.

philip-pentatonic pushed a commit to machinegenieorg/TensorFold that referenced this pull request Oct 10, 2026
@jschmied
jschmied deleted the cuda-affine4-pack branch October 11, 2026 17:36
Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Oct 12, 2026
…moved tf_pack_dense and tf_transpose_pad16


After the rebase onto a6aa478 nemotron_ops no longer carries the affine-4 repack (0e0d32b put it beside its
format in affine4_pack.cu), so the GLM loader, the MTP head's 4-bit tiling and the GLM checks found no
tf_pack_dense. They load the same kernels from affine4_pack now.
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
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