Skip to content

lanes: the GPU sampling rule once (gpu_rule.Rule): Metal's cfg and CUDA's Rule filled from it - #731

Merged
ashhart merged 1 commit into
ashhart:mainfrom
jschmied:gpu-rule
Oct 13, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
jschmied:gpu-rule

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

What this changes

The follow-up to #654 you agreed to: the GPU sampling rule (1 / T, top_p, the near window of 20, ln(min_p), top_k and the seed) is built once, in core/lanes/gpu_rule.zig, next to the host reference it already matches. gpu_rule.Rule and rule(Sampling) hold the values. cfg() and seedHalves() give Metal's four floats and two seed halves, and sample.Rule.from() gives CUDA's struct.

What now reads it:

  • Metal: Forward.sample in families/nemotron/forward.zig, and tests/nemotron_sample_check.zig.
  • CUDA: families/nemotron/cuda_sampler.zig. cuda/sample.zig loses its rule().
  • gpu_rule.sample and gpu_full.plan, the host references.
  • tests/cuda/sample_tests.zig, which loses its copy of the struct.

The kernels and their arguments are unchanged; the values are the same expressions, so the bits are too. Host tests pin both layouts: Metal's cfg row and seed halves in gpu_rule, and sample.Rule's size and field offsets in cuda/sample.zig.

#524's glm/draw_rule.zig builds the same values again for GLM on Metal; it could fill from gpu_rule.rule once both land.

Receipt

  • Environment: TensorFold 0efbd447 (1.0.8) plus this commit. CUDA: one DGX Spark (GB10, sm_121, driver 580.173.02, CUDA 13), TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, built-in kernels. Metal: an M3 Pro, Zig 0.17.0, Xcode 27.0.
  • Exactness, CUDA:
    • tf-cuda-test sample: 2,880 draws equal the host references.
    • Served Nemotron, --parallel 1, base (0efbd447) against this branch: 2 prompts x (greedy, and 5 settings x 4 seeds: temperature 0.6 to 1.2, top_p 0.8 to 1.0, top_k 0, 5, 20, 50, min_p 0.05), drafted and "draft": false. All 84 replies equal; greedy logprob rows byte-equal (4 of 4); drafted == plain 42 of 42 in both builds. 39 of 40 seeded sampled replies differed from each other, so the draws were live.
  • Exactness, Metal: tf-nemotron-sample-check on base and branch, "all draws match": 8 cases (flat, peaked, past 1,024 candidates, tied levels, top_k 3000, top_k with top_p, min_p, a draft vocabulary through an id map), 16 of 16 rows each.
  • Decode and prompt speed: unchanged (no kernel or launch changes).
  • Tests run: zig build test 44/44 steps on Linux; on the M3 Pro 154/156 steps, as on base. The one failing step is the same on base: core.checkpoint_metal "a split checkpoint keeps later tensors in the file..." logs checkpoint tensor text.weight stays in its file: read it through a Stage. New tests: "the rule once: its values, and the Metal cfg row and seed halves it packs", "sample.cu's Rule layout", "a rule in the kernels' layout keeps every field". Swapping two of cfg()'s values fails 4 checks. lean_check.py: 539 findings, as on main.
  • Not run, and why: served Nemotron replies on Metal. The Mac here has no Nemotron checkpoint, and it's on a metered connection. If you can run your reply-hash gate on a Mac, that is the missing receipt. RTX cards: no hardware here.

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. (No bits change.)
  • 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.

…tal's cfg and seed halves and sample.cu's Rule filled from it, the host references read it, the CUDA test drops its copy; host tests pin both layouts
@ashhart
ashhart merged commit e3238bf into ashhart:main Oct 13, 2026
2 checks passed
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
jschmied pushed a commit to jschmied/TensorFold that referenced this pull request Oct 13, 2026
…when the CUDA server uses its own kernels

--kernels native is the CUDA CLI's flag; the server runs its own kernels whenever it has no captured Triton set.
@ashhart

ashhart commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Thank you, @jschmied. One rule built in one place is the right shape for this, and it landed in 1.0.9 as you wrote it: your commit is dc49fd5c4, under your name, and the PR's head is merged into the history with no change to the tree (e3238bf12), so GitHub shows this PR as merged.

You asked for the receipt you couldn't take, so here it is, with Nemotron 3.5 Lightning MLX 4-bit served before and after your change on the same machines.

  • Metal, M3 Ultra. All 17 release cells (8 prompts greedy, the same 8 with a seeded sampler, one with thinking on) gave the same reply drafted and with "draft": false, with the same token SHAs as before.
  • The rule's fields. 12 more seeded cells, drafted and plain, cover temperature 0.6 to 1.5, top_p 0.8 to 1.0, top_k 0, 5, 20, 50 and 3000 (past the 1,024 candidates), and min_p 0.05 and 0.1. All 12 gave the same tokens drafted and plain, and the same tokens as before. The 12 replies all differ from each other, so the draws were live. The top_k none, 0 and 20 cells at temperature 1.5 matched too.
  • CUDA, GB10. The same 17 and 12 cells matched in the same way, with the captured Triton set and with our own kernels, and tf-cuda-test sample drew 2,880 draws equal to the host references on both builds.
  • Metal with tensor units, M5 Max. In the 1.0.9 release gate, the released binary gave 1.0.8's tokens in all 17 release cells and all 12 rule cells, drafted and with "draft": false (12 of 12 drafted equal to plain on both releases, 12 of 12 equal across them).

Nothing changed on our side. #524's GLM sampler is the next place this rule should feed, once it moves onto the shared sampler.

@ashhart ashhart mentioned this pull request Oct 14, 2026
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, rebased onto the commits after 1.0.8; 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
…when the CUDA server uses its own kernels

--kernels native is the CUDA CLI's flag; the server runs its own kernels whenever it has no captured Triton set.
@jschmied
jschmied deleted the gpu-rule branch October 23, 2026 21:02
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