Repository navigation
qwen3_5 cuda: a dense MLP's NVFP4 prompt gate, up and act in one lean launch, the same bytes - #3252
Conversation
|
Thanks @jschmied. The host tests pass, and the contract compares the fused result with the replaced operations without loosening byte equality. We will run the device check on our side for the new pair and the existing BF16 and FP32 lean launches, including partial tiles and shortened active row counts. Outputs must be bit identical, both planted controls must fail, and launch limits must pass for the compiled CUDA targets. We will also check served tokens and prompt and decode speed at one and four streams.
|
|
Numbers for the cold 8K and 32K prefill cells on an RTX 5090 (sm_120), which the description asks for ("A tester run (Maxrio9 sm_120) of the 8K/32K cells would be welcome"). On this card the pair launch is quicker by about 0.6 % at 8K and 0.5 % at 32K, the greedy replies are byte-identical, and decode is within 0.05 % of main. Setup
DFlash2 drafts, 12 arms
Same bits
Not run
Raw logs (server logs, every request report, hashes, build logs) are available if useful. Thanks for the pull request. |
|
Thanks @Nipale-ai, that's the sm_120 run the description asked for. On a card that isn't ours, the pair launch is 0.65 % / 0.54 % faster at cold 8K / 32K with drafts and 0.57 % / 0.45 % without, PR slower in 0 of 25 TTFT pairs. Decode is level and every hash is equal across all 20 arms. The kernel ratio (1.10x at 2048 rows, 1.02–1.04x at 4096–8192) also matches the shape we saw on the GB10. Two notes for the record. The nvidia checkpoint is a fair stand-in, because its gate and up are NVFP4 in all 64 layers, so the pair path runs in every layer. And the weights sat in the page cache in every arm, so it's equal for A and B. I don't need the raw logs unless @ashhart wants them. |
|
Thanks @jschmied and @Nipale-ai. The RTX 5090 results add useful evidence: greedy replies match, the shortened-row checks pass and both controls fail as they should. The small timing gain stays provisional, since clocks and throttle reasons weren't recorded. Two things block it on Linux, both reproducible against main: the serving check rejects the changed prompt kernel and launcher because their pinned hashes weren't updated (please re-pin both, with the PR's note), and once applied to main the CUDA test dispatcher comes to 604 lines, past the 600-line cap. The zig and zig-windows jobs fail at this head; once the pins and the line count are fixed, please push and we'll see whether Windows has anything of its own. After that our GB10 check covers the fused pair and the existing BF16 and FP32 lean launches, seeded replies, cache reuse and one- and four-stream serving, every output bit for bit.
|
|
@ashhart Both fixed in
On this head: |
|
Thanks @jschmied and @Nipale-ai. The GB10 check we promised is done, at
Nothing more is needed from you. It's in our landing queue.
|
…, not synthetic layer times # Conflicts: # CHANGELOG.md
… with the thank-you Drop the older synthetic M5 Max paragraph that the served-results line replaced, and end the kept line with "Thanks to @gilby." as main's lines for his work do. # Conflicts: # CHANGELOG.md
… pair launch, the same bytes prompt_lean gains a SwiGLU pair form: a 128 x 256 tile stages gate's two 64-column blocks and up's at the same features, each warp holds a feature's gate and up sums in one lane, and the epilogue rounds both to bf16 and takes tf_q35_mlp_act's steps. The two existing instances keep their SASS on sm_80/86/89/120/121 (renamed: int out kind, four trailing arguments). Qwen3.5 dense layers with NVFP4 gate and up take it for prompt rows past 16.
…ir; inline four single-use imports in the CUDA test dispatcher The dispatcher sat at 600 lines on main, so the two new commands pushed it to 604 once applied there.
|
Thank you @jschmied. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Head
625fe3102f=19cdfdfbdplus the serving re-pins of prompt16.cu and nvfp4.zig, and four single-use imports inlined inzig/tests/cuda/main.zig(600 lines once applied to main). No kernel, launcher or served code changes, so the rows below, measured on19cdfdfbd, stand. Base main223da7659b. GB10 only measured; exact, on by default for NVFP4 gate/up prompt rows past 16.On main a Qwen3.8-27B dense layer's prompt MLP runs two
prompt_leanproducts (gate, up: 17408 x 5120 each), writesboth as bf16, reads them back in
tf_q35_mlp_act, and writes the act. bound1110 measured that act kernel at 3.1-3.4 %of cold TTFT at the bandwidth floor. This PR computes gate and up of the same 128 features in one lean tile and takes
the act in the epilogue, so neither bf16 product is written or read again and the act kernel does not run.
Fresh server per arm, page cache dropped before each start, 90 s between arms; SM clock per arm 2279 / 2278 / 2283 /
2284 MHz (the box's 2300 MHz cap; throttle flags are that cap's, same in every arm). Decode texts identical in all arms.
These rows are on this head's binary; an earlier run on 3b21a9a68e (same kernels, comments since) gave -3.26 % / -2.87 %.
Kernel level (
tf-cuda-test prompt-swiglu-bench, same process, A-B-A): two lean products + act vs the pair launch at2048 / 4096 / 8192 rows: 9.16 vs 7.96 ms (1.15x), 18.44 vs 15.44 ms (1.19x), 36.17 vs 30.81 ms (1.17x).
What changes
zig/kernels/cuda/prompt16_lean.cuh(new;prompt16.cuincludes it, 397 lines):prompt_leanmoved here andtemplated on an output kind (
LEAN_BF16,LEAN_F32,LEAN_SWIGLU) with four trailing arguments (up's words,scales and scale, and the act kernel's device row count). For
LEAN_SWIGLUa tile is 128 features: gate's two64-column blocks and up's two at the same features are staged as the usual 256-column tile (no repack, no second
weight copy), and warp
wntakes gate subtiles2wn, 2wn+1and up's16+2wn, 17+2wn, so one lane holds a feature'sgate and up sums. Each sum is its own column's mma chain over the same K order as a plain lean product. The epilogue
rounds both to bf16 (
acc * scale, as the bf16 lean epilogue) and then takestf_q35_mlp_act's steps(
g / (1 + expf(-g)) * u, rounded), skipping rows pastP[2]as that kernel does.zig/src/cuda/nvfp4.zig:Prompt.swigluandPrompt.pairs(both FP4, same n/k/npad, whole 128-feature tiles);the lean launch passes the four trailing arguments (zeros for one product).
zig/src/families/qwen3_5/cuda_modelopt.zigswiglu+cuda_forward.zig: a dense layer whose gate and up are NVFP4takes the pair for prompt rows past 16 with no learning hook and no group sums; everything else (FP8/fp8g layers,
EXL3, affine-4, BF16, decode/verify rows,
--learn) runs today's three launches.Shared code: the kernel is the CUDA core prompt tile (
prompt16_lean.cuh), the launcher core (cuda/nvfp4.zig);only the wiring is qwen3_5's. Any family with NVFP4 gate/up prompt rows and SiLU can call
Prompt.swiglu. Metal andHIP are untouched (HIP has its own epilogue form, #2344).
Same bits
tf-cuda-test prompt-swiglu-contract, also run after the gates inkernel-contract; filezig/tests/cuda/contract_prompt_swiglu.zig): the pair against main's path (twoprompt_leanlaunches, thentf_q35_mlp_act) byte for byte,SUMMARY prompt_swiglu: 3 pass, 0 fail; 2 controls red, 0 missed:non-finite inputs and a NaN block scale included, five repeats byte-identical, guards intact;
P[2]= rows - 37): 3 shapes bit-equal, rows past it left as the act kernel leaves them;up values each, through the real kernel: bit-equal, NaN, Inf and denormals included;
contract_prompt_swiglu.zig.swapped), and the gate'sscale one fp32 ulp up (
.gate_ulp, a pre-rounding change the rule must see).cuobjdump -sassofprompt16from main and thisPR, per function, sm_80/86/89/120/121 (nvcc 13.0): 7 of 7 functions identical, 1 added (the pair). The built
zig build fatbins -Dsm=121set: 113 of 114 images byte-identical (sha256); prompt16 differs only by the addedfunction. Filtered
kernel-contract prompt16: 7 kernels pass gates 1-4, live limits PASS (247 registers recorded).--no-drafts): 49 of 49 identical: greedy and seeded (temp0.8, top-p 0.95, seed 1234) one at a time, 4 and 8 at once, greedy over 2K and 8K prompts (2048/4096-row pair
launches); drafted == plain greedy on both binaries.
resumed at row 8192, their 24-125 new rows on the pair launch) against the same turns on a cache-off server: equal on
both binaries, and main == this PR.
Checks on
19cdfdfbd(kernels, launcher and served code identical at625fe3102f;compile-cuda-testsandtest-gradient-servingpass there)-Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths,tools/pr_check.pylean 341 vs 341 (0 new),zig fmt --check,git diff --check): pass.test-cuda-host test-qwen35-launch-args-host test-qwen35-modelopt-admission-host test-qwen35-stack-symbols-host test-qwen35-formats-host test-qwen35-prefill-host400/400 steps, 6332 tests pass(30 skipped);
prompt-swiglu-contractandkernel-contract prompt16as above.kernel-contract(40-60 min; its other kernels' images are byte-identical to main's).Notes
qwen3_5 dense MLP site. This PR does the act in the epilogue, which is where the GB10 gain is. Either can land first;
I'll rebase onto the other when you say.
Prompt.swiglureturnsFormatMismatchfor a non-pair, but the forward asksPrompt.pairs()first and runs today's three launches otherwise, so nothing refuses on a served path.as much. A tester run (Maxrio9 sm_120) of the 8K/32K cells would be welcome.
launch; replies are byte-identical and cold prefill on GB10 is about 3 % quicker at 8K and 32K."