Repository navigation
nemotron metal: overlap and preload taught-pocket decode work - #775
Conversation
…'s up and the routed experts' down, no barriers A taught MoE layer ran its pocket after the shared expert's down projection as three dispatches, each behind a barrier (tf_train_lora_in, tf_pocket_relu2, tf_train_lora_out), and the routed experts' up projection ran beside the last of them instead of beside the shared down. Now tf_pocket_in, tf_train_lora_in's loop and sum with tf_pocket_relu2 at its store and no row lengths, runs beside the router and the shared expert's up: it reads only x and the pocket's weights and writes only the pocket's z. tf_train_lora_out runs beside the routed experts' down: z and the shared expert's sum are done at the barrier before it, and the down projection reads and writes neither. Each run of taught rows gets one of each, as before. A taught layer now adds two dispatches and no barriers, and the shared down is beside the routed up again. Every product and sum keeps its order, and the pocket still adds into the shared sum after the residual and the adapter, so a reply's tokens should not change. The prompt path and the trainer keep the three dispatches. A test runs tf_pocket_in against tf_train_lora_in then tf_pocket_relu2 at 1 and 16 rows over 1, 6 and 64 neurons, byte-equal on an M5 Max; with the relu taken out of tf_pocket_in it fails.
… docstrings as one line each, at most 120 columns tools/zig/lean_check.py found the kernel's two-line comment and the two docstrings past 120 columns; the branch now adds no problem over its base.
…fore it adds them, in the same order Each lane of tf_pocket_in walked its 84 strided inputs one load and one add at a time, every add waiting on its own load, so the kernel ran longer alone than upRelu2, which it runs beside. A lane now loads 28 of its x and up elements before it adds them in tf_train_lora_in's order, then adds any rest one at a time as before; the simd_sum and the store are unchanged, so every lane's sum keeps its bits. Alone in the dev CLI's profile on an M5 Max (the four-fact folder, 16 taught layers, 32 steps, two runs) it takes 4.6 and 5.6 us a call instead of 28.4 and 28.2, against upRelu2's 20.9 to 21.7, and that folder's 256-token greedy reply keeps its token ids. The kernel test also runs a width of 2728, which leaves every lane a rest after its batches. It passes byte-equal on the M5 Max; it fails with a batch's 28 added in reverse, and with the rest's last element dropped.
|
Thank you, @ThinkOffApp. Folding the pocket's dot and squared relu into one kernel, and putting both halves beside work that never touches their buffers, is a neat trick, and the 28-wide loads put What we checked on an M3 Ultra (no tensor units):
The prompt path and the trainer keep the three-dispatch pocket, as your PR says. We haven't run a taught folder on an M5 ourselves, so your M5 Max profile is the M5 figure for now. |
|
Awesome @ashhart! good to see M3 ultras doing 8% on every reply. The CUDA side is #787 built based on philip-pentatonic's suggestions from #678. On our GB10 with 1.0.8, a folder with 64 facts went from 87 to 100 tps undrafted, the untaught speed, with the same tokens. It also fixes a small bug that is already in 1.0.8: when the learner captures the graphs again while another sequence is bound, the own sequence kept the capture's placeholder sampling rule. It is rebased on 1.0.9 and in draft while we re-run the receipt against 1.0.9. I'll mark it ready when that is in. |
The contributor's three commits landed above with the same code; this keeps the PR's head in the history with no change to the tree.
What this changes
On Metal, a Nemotron layer that has learned facts (its pocket has
used > 0) ran the pocket as three dispatches behind barriers, after the shared expert's down projection. On my M5 Max that made a model with four learned facts decode about 10% slower than the same model untaught.This PR runs that work beside work the layer already does:
tf_pocket_in, doestf_train_lora_in's sums with relu² applied at the store. Each lane loads its inputs 28 at a time before adding them, in the same order, so on every path I tested the bits did not change.tf_train_lora_outruns beside the routed experts' down projection. A taught layer adds two dispatches and no additional barriers.Result: no measurable overhead on this M5 Max with four learned facts, drafted (with
tools/bench_openai.py) and undrafted; answers identical on the tested paths.Part 3 of #678. The 1.0.8 numbers that showed this cost are Ash's. The CUDA findings in #678 are @philip-pentatonic's, and the CUDA side is untouched by this PR.
Receipt
0efbd447) against this branch (8b766bc6). Both were built withzig build dist -Dversion=1.0.8 -Ddist-host-only=trueand Zig 0.17.0. The engine is native Metal, with no MLX or PyTorch at runtime.d9d758fb: as published, and a copy with four learned facts.tools/bench_concurrent.py --alone --serial: on both builds and both folders:"draft": false(96 of 96 per build);token_shais the same before and after.tools/bench_openai.py: drafted, the taught model is 7.6% faster and the untaught one unchanged. Taught/untaught goes from 0.94 to 0.99.tools/prefill_cold.py: not run, because 1.0.8 does not have it.prefill_mixers.zigis unchanged. A 15-token prompt, which takes the decode path, started 0.6 ms sooner taught and the same untaught.zig build test -Dcpu=apple_m1: 1506 of 1514 passed, 8 skipped, and one inherited failing step that also fails on v1.0.8.tf_pocket_inwith the old two kernels byte for byte.lean_check.py: 539 before and after.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. Drafted and concurrent: yes. Resumed equals fresh: not run.prefill_cold.py, which 1.0.8 does not have. Chunks over 16 tokens run the same dispatches, and a 15-token prompt was not slower.Full receipt
Where the cost was
The dev CLI's
tensorfold run … --no-drafts --profile 32times each dispatch alone. On the four-fact folder (16 taught layers), two runs per build:5cf7c144)tf_train_lora_in(v1.0.8) ortf_pocket_inupRelu2, whichtf_pocket_inruns besideupRelu2should hide most of its 28 µs, and loading ahead brings it to about 5 µs, shorter thanupRelu2. That overlap is my reading of the separate timings, not a GPU trace.TensorFold's clients
bench_openai.py, drafted, one stream. tok/s, the mean of two rounds:bench_concurrent.py:"draft": false, 96 of 96 per build;bench_openai.py:How far to trust these:
bench_concurrent.py's throughput. I do not quote it. It runs during 90 s of 4-stream decoding, while this MacBook's GPU throttles, and it swung by up to 48% between two servers of the same build and folder.Undrafted decode speed
The dev CLI's
tensorfold run: greedy, one 36-token prompt, 256 tokens, drafts off. Ten bursts, each with one run per build and folder, order rotated, 90 s idle before each burst:On the server with my own client (256 tokens, 8 prompts,
"draft": false, 12 measured requests a mode), the round run with the machine otherwise quiet, thinking off / on:Same tokens
Greedy, thinking off and on, drafts on and
"draft": false, v1.0.8 against this PR:tf_pocket_inagainsttf_train_lora_inthentf_pocket_relu2, compared byte for byte.token_sha, text, reasoning, token count and finish reason.run --report: 60 of 60 id arrays identical on each folder, 9,440 and 17,298 tokens.--slideserver ran a learn request while 4 clients asked the 72 questions. 72 of 72 replies equal their solo runs and v1.0.8's. The 353 streams the learn request finished each have an exact twin in v1.0.8's run.*.safetensorsandconfig.jsonhashed the same before and after.Tests
zig build test -Dcpu=apple_m1: 1506 of 1514 passed, 8 skipped.python3 tools/zig/lean_check.py: 539 problems on v1.0.8 and 539 on this branch, all inherited.zig fmt --checkon the changed files: clean.zig build dist-smoke: passed.