Repository navigation
Conversation
…round The CUDA backend now runs under ROCm's PyTorch on one GPU for Qwen3.8-27B's MLX 4-bit checkpoint with DFlash2 drafts. Drafted replies equal serial ones and any prompt chunking gives the same bits, as on NVIDIA. Other families, EXL3 packs and two ranks are refused at startup with a message. - Build: extensions compile with hipcc for the GPU present (--offload-arch), nvcc flags mapped to clang's. DeltaNet kernels take ROCm's 64-bit shuffle mask and bf16 rounding. - Decode matmul (qmm_rocm.cu): WMMA on 4-bit words repacked at load into 16-output tiles, persistent blocks, split-K reduced in-kernel by the last block, up to 32 rows per weight read; [gate|up], [z|b|a] and [k|v] fused as views. Row arithmetic never depends on the row count. - Prompt matmul: NVIDIA's FP8 prompt arithmetic (prefill_glue's e4m3 rows, exact e4m3 codes, per-group scales) as a fixed-tile Triton e4m3 GEMM with grouped tile order. - Attention and DeltaNet: 16-key attention tiles and ROCm schedules for the verify and prompt chains; buffer loads off (they read zeros for negative offsets from the attention base). - Startup estimate counts the 4-bit drafter at its packed size (it counted fp32 and refused every window on 32 GB). - Every backend: timing-only syncs in draft_decode run only when tracing; fused projection slices reach their kernels as strided views instead of copies; the drafter computes shared group sums, pointer tables and window updates once per round (~200 fewer launches a round). Measured on a Radeon AI PRO R9700 (localeval speed sweep, greedy, thinking off): prompts 2,326 tok/s at 4k, 1,849 at 16k, 1,582 at 30k (marginal); decode 112 / 130 / 95 tok/s at 4k / 16k / 30k. The recipe's AMD section has the setup, tuning variables and limits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
M5's fused SDPA takes head size 256 in flat memory, so the 128-row parts (and their evals) that bound memory on M1-M4 are not needed there. On an M5 Max, 2,048 queries against 6k-32k keys: 1.38x the parts (41.4-41.9 against 28.6-30.8 TFLOPS). End to end the gain is within run-to-run noise: marginal prefill +1.6% at 16k and +5.7% at 32k (localeval speed sweep, 3 reps). tests/test_prompt_attention.py still pins the stock causal bits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A HIP flash attention kernel for ROCm prompts (attention_rocm.cu): a block per 16 query rows and KV head, a wave per query head of the group sharing each 16-key K/V tile in shared memory. S^T = K Q^T puts a query's scores in its lane pair, so its row max and sum take one shuffle and P is already the A operand of P V. Keys fold in 16-key tiles by absolute position and a row is rescaled only by its own factor, so any chunking gives a row the same bits. The Triton kernel stays for other head sizes and behind TF_ROCM_ATTN_KERNEL=triton. On an R9700: 70.5 TFLOPS at 4k queries over 32k keys, against 48.9 for the Triton kernel. A 4,096-token chunk at 28k-32k context takes 2.41 s of GPU time instead of 2.89 (attention 0.72 s instead of 1.04). Served, marginal prefill 1,974 tok/s at 16k (was 1,854) and 1,784 at 30k (was 1,577); cold 16k prompts 2,069 tok/s (was 1,971). Co-Authored-By: Claude Opus 5.5 <[email protected]>
ROCm's unsorted top-k returns tied logits in a varying order and set, and the tree policy breaks ties by position, so the same drafter context could propose different trees. On ROCm the top 16 now go by value, then lower column. Replies were unaffected (every draft is verified); proposals are now repeatable, and test_blocks_of_several_streams_equal_their_own passes on the R9700. Co-Authored-By: Claude Opus 5.5 <[email protected]>
tree_attention_rocm.cu replaces the Triton _shared and _tail kernels on ROCm (the Triton merge stays). A block per committed 512-key chunk and KV head stages each 16-key tile once for all of a window's (row, head) pairs, a wave per 16 pairs; up to 64 chunks, four loader waves keep two tiles in flight through a double buffer, past it every wave loads then folds (twice the blocks fit). A row's tail chunk folds the same way, so a chunk read whole as committed keys gets the bits a drafted row's tail gives it; compute waves and loaders never change a pair's bits (a new test checks 1-8 waves, both schedules). TF_ROCM_TREE_KERNEL=triton keeps the Triton kernels. R9700, 12-row drafted rounds on a fixed prompt, WMMA against Triton: 40.4 / 40.5 ms at 3k, 43.0 / 43.0 at 16k, 44.4 / 47.8 at 38k, 51.9 / 63.3 at 77k, 61.7 / 75.2 at 120k tokens of context (decode 101 against 83 tok/s at 120k). Served greedy replies drafted and with "draft": false were identical on 44,826- and 4,726-token prompts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e bits attention_rocm.cu now holds both WMMA attention kernels (tree attention moves in from tree_attention_rocm.cu; one extension). The prompt kernel shares the tree kernel's 16-key fold and loader machinery: a block per 32 prompt rows (16 below 192 rows) and KV head, a compute wave per 16 rows and query head, and four loader waves keeping the next tiles in flight through a double buffer. Every row folds the same tiles in the same order, so its bits are the committed kernel's (checked on all head groupings and layouts, 60 of 60) and chunking still never changes them; a new test checks rows a block and loaders for every head grouping against each other and float64. TF_ROCM_ATTN_RB and TF_ROCM_ATTN_PIPE override the layout for tuning. R9700, 24 query / 4 KV heads: 4,096 queries after 28,672 / 61,440 keys went from 42.9 / 93.0 ms to 39.9 / 82.0 ms (about 78 TFLOPS); 1-57 queries after 24k keys from 1.8-1.9 to 1.3 ms. A 4,096-token prompt chunk at 64k / 96k tokens of context: 3.35 -> 3.19 s and 4.19 -> 3.88 s (1,223 -> 1,285 and 977 -> 1,056 tok/s). Splitting head dims across wave pairs measured 66-72 TFLOPS before any exchange of scores, so this layout stays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The drafter's window keeps up to 2,047 context keys, and its block attention ran one program per KV head: 8 programs a call on a 64-CU R9700, 0.46 ms each, 2.3 ms a drafted round. On ROCm a program now takes one query head and 512 context keys (or the block's own keys), and a merge adds the parts in key order: 0.27 ms a round. A stream's drafts stay independent of the streams beside it; NVIDIA keeps the one-pass kernel. R9700, 16k tokens of context, a code prompt: 43.0 -> 41.2 ms a round. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rget 64 On ROCm, prepare stacks a GDN layer's [qkv | z | b | a] and an attention layer's [q | k | v] into one matmul each, the members kept as views (no memory added); the forward reads qkv and [q | gate] as strided views, so gdn_pre, attn_prep and gate_mul take their row strides (NVIDIA passes the contiguous stride and runs as before). Prefill still calls the members. The WMMA K split now aims for 64 blocks instead of 128: every 27B projection read at 12 rows as fast or faster. Both change decode bits alike for every row count, so drafted still equals serial. R9700, 16k tokens of context, a code prompt, 12 verify rows: 41.2 -> 40.0 ms a round (matmuls 30.3 -> 29.2 ms, launches 1,007 -> 943), 68.7 -> 71.6 tok/s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… stride With the stacked [q | k | v] projection (0b469e7), [q | gate] rows are a view with a wider row stride. attn_prep loaded a query's first values by that stride but its rotary partner by the old contiguous one, so every verify window row past the first got another row's partner: drafted replies could differ from "draft": false ones and fewer drafts were accepted. A lone row (serial decoding, a window's first row) was unaffected. The glue test now reads every input as a slice of one stacked output, as the forward does; it fails with the old line. On the R9700: served greedy replies drafted and with "draft": false are identical again (4,726 and 28,676-token prompts), and a code prompt went from 6.79 back to 7.92 tokens a round. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he bytes Opt-in. Per token and KV head, the 256 values are stored as e4m3 codes of x * 2^-e (e the smallest exponent putting the row's largest magnitude at or under 448) followed by e: 272 bytes instead of 512 (cuda/kernels/kv8.py, one Triton launch per layer call). The WMMA prompt and tree attention kernels widen each packed row to bf16 while staging it in shared memory, so the tile and every fold are those of bf16 caches holding the rounded values; a verify window's own keys and values are rounded the same way before its attention. Drafted still equals serial, and any chunking gives the same bits. Quality, the same rounding on bf16 caches: localeval mmlu 0.860 -> 0.864 (228, noise), ifeval 0.900 -> 0.900 (60), judged core set 1.000 -> 0.990 (10); next-token distributions after 4k/16k/32k tokens of code: top-1 kept 96.9/99.2/97.7%, mean KL 0.007-0.012. The packed caches give those logits exactly. Speed on the R9700, a drafted round at 64k tokens of context: 48.7 -> 46.5 ms (tree attention 9.7 -> 7.3 ms); 40.1 -> 39.6 ms at 16k. The startup estimate counts the smaller cache. Refused on NVIDIA, with --tp 2, with the Triton attention kernels, and for head sizes other than 256. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The CUDA prompt kernel's Triton-bits test: on ROCm, prompt attention runs attention_rocm.cu (head size 256) or _attend with ROCm's tiles, each with bits of its own; the chunking test still runs. The MoE experts pack tests: those kernels are NVIDIA's (ROCm serves Qwen3.8-27B only); the direct reader's own tests run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1d1850c to
9f10542
Compare
The groups layout and its lane matmul serve ROCm only; on NVIDIA the test tried to build qmm_rocm.cu. Found running tests/cuda on a DGX Spark (GB10): with it skipped, the branch passes everything main passes there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Independent run on a second DGX Spark (GB10), container
Your description reports 828 passes on this branch plus the tier (#106) and 783 on Served from the PR head, That is relevant to #112: an RTX 5090 (32 GB) refuses the same model with drafts (weights 21.93 GiB + staging 7.27 GiB = 29.20 GiB against a 26.90 GiB budget, real load peak 16.6 GiB with a local test patch). We will try this PR head on that 5090 and report the result on #112. Runs and write-up by AI agents working for Niklas Lenz (Devin, Claude). |
|
Thanks, this helps. Your one-at-a-time runs pass everything on both trees, so the 8 failures in our parallel 91.05 → 84.85 GiB is the drafter going from fp32 (7.2 GiB) to its packed size (1.0 GiB). The packed estimate applies on NVIDIA too, so on your 5090 the resident term should drop from 21.93 to about 15.7 GiB. Resident plus loading memory then comes to about 23.0 GiB against the 26.90 GiB budget, so it should admit a window, unless 0.5.0 changed the 7.27 GiB loading term. This PR doesn't change how #112 adds loading memory to resident memory; it only makes the drafter smaller. Looking forward to the 5090 result. |
|
@jkuepker the 5090 result is posted on #112: #112 (comment). Short version: on a free card the PR head serves Qwen3.8-27B with DFlash2 at window 16384 ( Runs and write-up by AI agents working for Niklas Lenz (Devin, Claude). |
|
Thank you for this. It's a big piece of work, and the numbers are strong: 95.7-126.1 tok/s with DFlash2 on the R9700 against about 34 without, plus two real finds along the way (ROCm's unsorted We're closing this one because it's built on 0.3.4.1, and a lot has moved underneath it since: the memory estimate and much of the glue it touches were rebuilt. 0.6.0 also changes a default this PR relies on. CUDA now reads prompts at bf16 by default, with FP8 prompt inputs only behind an explicit flag, because we measured what FP8 prompts cost: on the 27B's code prompts, perplexity +4.1% against +0.03% at bf16. We'd love to have it back. If you rebase onto 0.6.0 once it's out, with bf16 prompts as the default on ROCm too and FP8 as the opt-in, we'll run the NVIDIA side here the day it lands. We don't have an AMD card, so your R9700 numbers are the ones the docs will quote. |
|
Thanks for the close note, and for landing the drafter-size fix in 0.6.0. A small correction for when we come back to this: #100 and #106 are based on 0.5.0, not 0.3.4.1 (merge-base Once 0.6.0 is public, we'll rebase #100 onto it with bf16 prompts as the ROCm default and FP8 prompt inputs behind 0.6.0's opt-in, then put #106 on top. We'll re-measure on the R9700: prefill at bf16 and FP8, and drafted replies against Two things would help us match 0.6.0: the name of the FP8-prompt flag, and whether your perplexity numbers (+4.1% against +0.03%) come from a script we can run on the R9700, so the ROCm figures compare directly with yours. |
|
Thank you, and you're right about the base: both #100 and #106 sit on 0.5.0 (9cd52ab). My note was wrong there, sorry. 0.6.0 goes out tonight and has moved a lot underneath both, so we'll do the rebase ourselves in 0.6.1, keeping your commits, with bf16 prompts as the ROCm default and FP8 as the opt-in. If you push #106's review fixes to its branch, they'll come along too. Then we'll ask you to re-measure on the R9700, since we have no AMD card. The flag is |
|
0.6.1 is out, and the ROCm work isn't in it: not #100, #106 or #144, and not the quality harness under
Which would you prefer? |
|
@ashhart @jkuepker I've rebased #100 and #106 onto 0.6.2 in a fork and kept going on a Radeon AI PRO R9700, so you may not need to do the rebase yourselves. The PRs would go onto 0.6.3. Before I open anything, I'd like to know which shape you want, so nobody builds it twice. Branch: https://github.com/millaguie/TensorFold/tree/rocm-r9700. A note on it: much of this was written with AI models (Claude Opus 5.5, Claude Fable 5.1, GLM-5.3 Flash and Kimi K3), and the branch's own commits still carry session lines. The PR branches will drop them, as CONTRIBUTING asks, and keep only commits I've reviewed and measured. The branch carries jkuepker's and ThinkOffApp's commits under their names, and follows the plan from this thread: bf16 prompts by default, What it adds on top:
On one R9700 with that MXFP4 checkpoint, against vLLM-radiance on the same card and checkpoint: prompts at 6.7K tokens 2,656-2,678 tok/s (radiance 2,588), at 67K 1,896-1,915 (2,066); decode 45-48 tok/s chat and 119-120 code (54.5 and 99.5); three clients 95-104 tok/s total with a 3.2 s first token (113.5, 5.9 s). These come from my own bench. The PRs would carry your receipt ( For quality I ported
MLX's FP8 prompts cost about 38x the bf16 KL here, against 20x in your 0.6.0 figures (0.0031 and 0.0624). The MXFP4 path's FP8 is 6x closer than MLX's, because its weight scales fold exactly into e4m3. I left the two chat sequences out. With them every configuration lands at KL 0.14-0.36. That comes from the model, not the kernels: on the tiled chat block the 27B, fp32 reference included, predicts My proposal is a stack of small PRs: (1) ROCm on 0.6.x with the |
|
@millaguie thanks for carrying this forward and for the numbers. The prompt_precision_cuda.py table is especially useful. Option A works for me: go ahead with the stack. (1) ROCm on 0.6.x with the Two requests:
I'll re-measure each PR on my R9700 as it opens: prompts at bf16 and with |
|
Correction to my request 2: none of those five commits needs adding. Checked against
One small ask instead: ecd9906 carries |
|
@jkuepker thank you, both for the go-ahead and for offering to re-measure each PR on your card. That helps a lot, since your R9700 is a second machine we can't otherwise get. Your commits will keep your authorship. Edit: I wrote this before seeing your correction above, sorry, so part of it repeats what you had already checked. Done on your ask: About the five tier commits, I owe you a clearer explanation than my first comment gave. When I ported the tier to 0.6.x I followed your note 1 on #106 and left the one-window buffer out, hooking the tier into
As you say, they can stay out. I still wanted to check that leaving the window out doesn't cost anything. So I ran both branches on one R9700, at the same 250 W cap and in the same session, alternating ours, yours, ours, yours. Both used the MLX 4-bit 27B with DFlash2, one stream,
Some caveats. Your branch sits on 0.5.0, so the first-turn gap is mostly 0.6.x's prompt path and the gfx1201 kernels, not your tier. The repeated-turn p90 looks like some turns on your branch being prefilled again rather than restored. I may well be missing a setting there, so if there is a flag or a step I should have used, please tell me and I'll rerun it. Without My proposal for (3) is to bring your original tier commits over first, under your name, and put my 0.6.x port on top, so the PR shows what's yours and what's the adaptation. If you think the window buffer is still worth having on top of 0.6's And is there something we're not seeing? You know the window buffer far better than I do. If it solves a case this bench doesn't exercise (other context lengths, more or fewer conversations, a different memory budget, something you saw on your setup), I'd rather hear it now and measure that too than leave it out by mistake. |
|
Thanks for measuring this so carefully. You didn't miss a flag: the p90 is a bug in my window-buffer path. When a conversation comes back, Your port doesn't have this path, and your numbers show the window buffer costs 2.8 GiB at startup without a measured gain on this bench. So I agree: leave it out, and bring my tier commits over first with your port on top, as you proposed. If you want to confirm, a rerun of my branch with |
On gfx1201 (RDNA4) this path's forward gives non-finite logits; with drafts the verify loop then never returns (reported on ashhart#144 with an R9700). gfx12 runs on ashhart#100's WMMA kernels, so this path now stops at startup there with a message that says so. Nothing changes on gfx1151. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reran it on the R9700 ( |
This PR lets the CUDA engine serve Qwen3.8-27B (the MLX 4-bit checkpoint, with DFlash2 drafts) on AMD GPUs under ROCm's PyTorch. Drafted replies equal
"draft": falseones and any prompt chunking gives the same bits, as on NVIDIA. It also removes about 200 kernel launches and 3 host syncs from every drafted round on both backends. Other families, EXL3 and NVFP4 checkpoints, image input and--tp 2are refused on ROCm at startup with a message.Benchmarks
One AMD Radeon AI PRO R9700: gfx1201, 32 GB, 640 GB/s; 639 GB/s measured streaming read. ROCm 7.14, torch 2.11.0+rocm7.14, Triton 3.6. Checkpoints
Vontra/Qwen3.8-27B-MLX-4bit@70ae7facandz-lab/Qwen3.8-27B-DFlash2@50307d4c. Launch:tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit --name bench, which fits a 32,768-token window beside the model and drafter.Public fixtures.
tools/bench_openai.py --tokens 64 --reps 5 --temperatures 1.0,0, median decode tok/s after the first token (seeds 1234-1238):--no-drafts, T=1--no-drafts, greedyCold prefill.
tools/prefill_cold.py, median of 3, unique first line per prompt. The 32k and 64k prompts don't fit the 32k window on a 32 GB card.Longer prompts. A private streamed sweep: fresh-nonce chat prompts, 256 forced tokens, greedy, thinking off, 3 reps. Marginal prefill is the rate between successive prompt lengths. Decode depends on how many drafts are accepted per prompt and spreads 10-40% across reps.
Where the time goes (torch profiler on the R9700):
Decode at long context. A 12-row drafted round on one fixed code prompt behind filler, with the KV preallocated beyond this PR's 32k window (a follow-up adds a larger window). Round time in ms; tokens and rounds are identical across columns:
main)Tree attention alone, 12 rows, 24 query / 4 KV heads, µs per layer call (committed chunks + tail + merge): 144 → 113 at 4k, 534 → 465 at 30k, 1,908 → 1,324 at 120k keys (chunk-major Triton → WMMA).
Decode at 16k (a code prompt from the stdlib corpus, greedy, 12 verify rows, 2.8 tokens a round; ms a round from the round profiler): 43.0 → 41.2 ms with the drafter's block attention in parts (2.3 → 0.27 ms of it), → 40.0 ms with stacked input projections and a K split target of 64 (matmuls 30.3 → 29.2 ms, launches 1,007 → 943); 65.8 → 71.6 tok/s. 16 verify rows accepted no more on this prompt and cost 1.2 ms a round.
Kernel level (M = 4,096, the 27B's projection shapes):
How the numbers moved during development (same card and sweep as the longer-prompts table):
FP8 keys and values (
--kv-dtype fp8, opt-in, its own commit): per token and KV head, 256 e4m3 codes and a power-of-two exponent, 272 bytes instead of 512. With the same rounding applied to bf16 caches: localeval mmlu 0.860 → 0.864 (228 questions, noise), ifeval 0.900 → 0.900 (60), judged core set 1.000 → 0.990 (10); after 4k/16k/32k tokens of code the next-token distribution kept bf16's top token 96.9/99.2/97.7% of the time (mean KL 0.007-0.012). The packed caches give exactly those logits. A drafted round at 64k tokens of context: 48.7 → 46.5 ms (tree attention 9.7 → 7.3 ms); at 16k 40.1 → 39.6 ms. gsm8k, now scorable withmain's JSON-schema replies, on the served packed caches against bf16 (same server otherwise): 0.980 vs 0.980 with thinking on (200 questions), 0.500 vs 0.500 with thinking off (100); ifeval 0.860 vs 0.880 (100, noise).The change
cuda/build.py):hip(); extensions compile with hipcc for the GPU present (--offload-arch, or the first ofPYTORCH_ROCM_ARCHon a host with no GPU); nvcc flags map to clang's (--fmad=falsebecomes-ffp-contract=off).gdn.cuandgdn_prefill.cutake ROCm's 64-bit shuffle mask and bf16 rounding.cuda/kernels/qmm_rocm.cu,qmm_groups.py): WMMA on 4-bit words repacked at load into 16-output tiles.[gate|up],[z|b|a]and[k|v]are stacked, with the members kept as views, so no memory is added.tests/cuda/test_qmm_rocm.pychecks 1-40 rows against each other and against float64.prefill_glue's e4m3 rows, the 4-bit codes exact in e4m3, per-group scales, bias on the group sums, row scale). The codes are widened once per chunk, then a fixed-tile Triton e4m3 GEMM runs with grouped tile order.cuda/kernels/attention_rocm.cu, its own commit): flash attention on WMMA for head size 256. A block per 16 query rows and KV head, a wave per query head sharing each 16-key K/V tile in shared memory. S^T = K Q^T puts a query's scores in its lane pair, so P is already the A operand of P V. A row is rescaled only by its own factor, so chunking never changes its bits. The Triton kernel stays for other head sizes and behindTF_ROCM_ATTN_KERNEL=triton.perf(rocm), same bits) gives it 32-row blocks (16 below 192 prompt rows) and four loader waves that keep the next K/V tiles in flight through a double buffer, sharing the tree kernel's fold; checked bit for bit against the first version on every head grouping and layout.TF_ROCM_ATTN_RB/TF_ROCM_ATTN_PIPEoverride the layout.draft_attention.py, its own commit): the drafter's window keeps up to 2,047 keys and its attention ran one program per KV head (8 a call). A program now takes one query head and 512 keys (or the block's own), then a merge adds the parts in key order. A stream's drafts stay independent of the streams beside it; NVIDIA keeps the one-pass kernel.[qkv | z | b | a]and an attention layer's[q | k | v]are one matmul each, their members kept as views (no memory added).gdn_pre,attn_prepandgate_multake row strides for the views (NVIDIA passes the contiguous stride). The WMMA K split target goes from 128 to 64 blocks: every 27B projection read at 12 rows as fast or faster. Decode bits change for every row count alike, so drafted still equals serial.--kv-dtype fp8,cuda/kernels/kv8.py, its own commit): one Triton launch per attention layer call packs a layer's keys and values; the WMMA prompt and tree attention kernels widen packed rows to bf16 while staging tiles (the same tile and fold as bf16 caches holding the rounded values); a verify window's own keys and values are rounded the same way, so drafted still equals serial. The startup estimate counts the smaller cache. Refused on NVIDIA, with--tp 2, with the Triton attention kernels, and for head sizes other than 256.cuda/kernels/attention_rocm.cuwith the prompt kernel, its own commit): replaces the Triton_sharedand_tailkernels on ROCm; the Triton merge stays.TF_ROCM_TREE_KERNEL=tritonkeeps the Triton kernels (different bits; a process uses one).main(0.5.0) now orders tree attention's work items chunk-major and launches a chunk's KV heads together, the same change this PR carried, so that commit is gone from here. The ROCm port builds on it; the Triton_sharedkeeps a key-tile parameter for ROCm's fallback.TF_ROCM_TREE_KERNEL/TF_ROCM_ATTN_KERNEL).AMDGCN_USE_BUFFER_OPS=0), because they read zeros at negative offsets fromattention.base.fix(rocm)): ROCm's unsortedtopkreturns tied logits in a varying order and set, so the same drafter context could propose different trees. On ROCm the top 16 are now picked by value, then column. Replies were never affected, since drafts are verified.draft_decodesynchronizes for its stage timers only whentraceis given;DecodeResultstage times are host-side otherwise.gdn_pre,gated_norm,attn_prep,swigluand tree attention as strided views instead of copies (176 launches a round).docs/recipes/qwen3.8-27b.mdwith the setup, tuning variables and limits, plus a pointer from the README.perf(mlx)), MLX only: on M5, prompt attention with head size 256 is one fused SDPA call instead of 128-row parts. It measures 1.38x at the kernel on an M5 Max, but end to end the gain is within noise (+1.6% at 16k, +5.7% at 32k marginal prefill). Drop the commit if you'd rather keep the parts.Checked
Rebased on
mainat 0.5.0 (JSON-schema replies, faster CUDA loading, chunk-major tree attention). Re-run on the R9700 after the rebase, on #106's branch (these commits plus the tier):The 27B's GPU suites pass, with
main's JSON-schema and direct-reader tests (257 tests), and again withTF_ROCM_TREE_KERNEL=triton TF_ROCM_ATTN_KERNEL=tritonfor the Triton fallbacks (57).Two NVIDIA-only tests are skipped on ROCm: the CUDA prompt kernel's Triton-bits check, and the MoE experts pack, whose kernels ROCm doesn't build.
Served greedy replies drafted and with
"draft": falseare identical at this branch's head too, and a JSON-schema request parses to the schema with the same reply both ways.The speed tables above were measured before the rebase (
main's_mergenow runs in column parts); not re-measured.The 409-test count below is from before the rebase.
On the R9700, 409 tests pass: the 27B's GPU suites (forward, prefill, multi-stream, glue, attention, DeltaNet, sampling), the new ROCm matmul tests, and the CUDA CLI/capacity tests. Details:
test_qwen27_dflash2_blocks.py::test_blocks_of_several_streams_equal_their_ownfailed on ROCm until the DFlash2 commit above; it passes now.Served greedy replies drafted and with
"draft": falseare identical at this head (4,726 and 28,676-token prompts, bf16 and--kv-dtype fp8; 44,826 tokens with the WMMA tree attention). The stacked input projections commit broke this on the real model:attn_prepread the rotary partner of every verify row past the first by the old row stride. Thefix(rocm)commit after it corrects that, andtest_qwen27_glue.pynow reads every glue input as a slice of one stacked output (it fails on the old line).On a Mac, 3,952 CPU tests pass (on
mainat 0.5.0).tests/test_cuda_build.py::test_the_lock_named_is_the_one_torch_waits_onfails here and onmainalike (this torch reaches its Ninja check before the lock).Triton 3.6 miscompiles on gfx1201, found and avoided:
num_stages2 or 3) e4m3 tiles give wrong sums for calls of a few rows at K=6144.tests/cuda/test_qwen27_prefill.pychecks both prompt GEMMs at the model's shapes and at 1-, 2- and 5-row chunks.Not claimed
main. On a DGX Spark (GB10, NGC PyTorch 26.07: torch 2.13, Triton 3.7.1):tests/cudaagainstmainat 0.5.0: 828 pass on this branch plus the tier (feat(cuda): host-RAM tier for Qwen3.8-27B prompt states (--ram-tier-gib), 126k window on a 32 GB R9700 #106), 783 onmain. Failures in the parallel runs were memory contention on the Spark's unified memory; each passes run alone, on both trees. One test of this PR, the ROCm-only group-major matmul, built the ROCm extension there and now skips off ROCm.Vontra/Qwen3.8-27B-MLX-4bit@70ae7facwith DFlash2, an 8,192-token window beside the Spark's other services): greedy replies drafted and with"draft": falseare identical at 926, 4,726 and 7,446 prompt tokens, and a JSON-schema reply is the same both ways.main, served the same way:maingive byte-identical replies at 926, 4,726 and 7,446 prompt tokens, so NVIDIA's arithmetic is unchanged. Decoding those identical replies takes the same time: 2.953 / 3.047 / 2.704 s on this branch against 2.962 / 3.055 / 2.706 s onmain, 256 tokens each.mainas released refuses to start the 27B with DFlash2 at any window on a Spark whose other services hold their memory, because its estimate counts the drafter at fp32. This branch's packed-drafter estimate fits 8,192 tokens there. For the comparison,main's copy took only that estimate (three admission lines, no kernels).These edits touch code NVIDIA runs:
gdn.cu: the mask macro andcudaFuncSetAttributecast.glue.py: new stride arguments, includinggdn_pre's qkv andattn_prep/gate_mul's[q | gate]rows.cuda/kernels/attention.py: value row stride, and a key-tile parameter for ROCm's Triton fallback.forward.py: views instead of copies, and the input projections through_gdn_inputs/_attn_inputs(unstacked on NVIDIA).decode.py: sync gating.dflash2.py,draft_attention.py: the drafter changes.capacity.py: the drafter estimate.hip()or__HIPCC__.--parallelis untested on ROCm beyond the multi-stream tests above.max_rowsstays 12. 16 rows helped code prompts (+13-19%) and hurt prose (-9%) in one test each.🤖 Generated with Claude Code