Repository navigation
Conversation
0f9e5f4 to
83f1997
Compare
…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]>
83f1997 to
116ecdc
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]>
…served round-robin Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prompt states the GPU prefix cache evicts or drops are copied to pinned host RAM and copied back (bytes, so replies are a fresh prefill's) when a later prompt extends one further than any state on the GPU. - Keys and values are stored once per token prefix: a state reuses the rows earlier states left on the host and copies only its new ones. - On one stream the GPU holds one window-sized attention buffer used by the conversation being served; the startup estimate charges one buffer, so a 32 GB R9700 serves a 126,553-token window instead of 32,768. - The budget is pinned at startup in 1 GiB slabs; startup refuses a budget above the host's available memory. R9700, 8 conversations of 24,000 tokens round-robin: repeat-turn TTFT 12.21 s -> 0.39 s, cold 12.15 s -> 12.27 s. Co-Authored-By: Claude Opus 5.5 <[email protected]>
116ecdc to
799206b
Compare
…n more reserve() pinned slabs until the host refused, so under a pinned-memory cap the tier held all of it and the decode path's per-round pin_memory() staging (tree attention, GDN and drafter plans) had no room left. After a refusal it now unpins at least one slab's worth of the last slabs and empties the host cache; that part of the budget is pageable, as the rest already was. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thank you, this is careful work: the side-stream copies with It's stacked on #100, so it closes with it for the same reason: the 0.3.4.1 base. A host-RAM tier is something we want, especially for 24-32 GB cards. If you bring it back on top of a rebased #100 against 0.6.0, we'll check that a restored state equals a fresh prefill and measure it with |
|
Pushed #106's review fixes to |
|
Notes for the 0.6.1 rebase of #106, from reading 0.6.0 and the open PRs that touch the same code:
Happy to re-measure whichever shape lands on the R9700. |
…ib), ported onto 0.6.x jkuepker's tier (ashhart#106, branch rocm-r9700-ramtier): prompt states the GPU prefix cache lets go are copied to pinned host RAM on a side stream, keys and values stored once per token prefix, and copied back when a later prompt extends one further than any state on the GPU, so a returning conversation skips its prefill. Ported without his one-window attention buffer, as he suggested for 0.6: KVRoom already admits one live window, so the tier only catches what PrefixCache lets go (its _leave hook, through add, evict, drop and clear). host_tier.py, its CPU tests and tools/bench_conversations.py come over as he wrote them; the three tests of the window buffer are skipped. The concurrent decoder takes the tier too (its cache evicts into it; an admitted stream resumes from it). Claude-Session: https://claude.ai/code/session_0177FjqB2W7svyUf7deveRJg
…ib), ported onto 0.6.x jkuepker's tier (ashhart#106, branch rocm-r9700-ramtier): prompt states the GPU prefix cache lets go are copied to pinned host RAM on a side stream, keys and values stored once per token prefix, and copied back when a later prompt extends one further than any state on the GPU, so a returning conversation skips its prefill. Ported without his one-window attention buffer, as he suggested for 0.6: KVRoom already admits one live window, so the tier only catches what PrefixCache lets go (its _leave hook, through add, evict, drop and clear). host_tier.py, its CPU tests and tools/bench_conversations.py come over as he wrote them; the three tests of the window buffer are skipped. The concurrent decoder takes the tier too (its cache evicts into it; an admitted stream resumes from it). Claude-Session: https://claude.ai/code/session_0177FjqB2W7svyUf7deveRJg Co-authored-by: jkuepker <[email protected]>
…ib), ported onto 0.6.x jkuepker's tier (ashhart#106, branch rocm-r9700-ramtier): prompt states the GPU prefix cache lets go are copied to pinned host RAM on a side stream, keys and values stored once per token prefix, and copied back when a later prompt extends one further than any state on the GPU, so a returning conversation skips its prefill. Ported without his one-window attention buffer, as he suggested for 0.6: KVRoom already admits one live window, so the tier only catches what PrefixCache lets go (its _leave hook, through add, evict, drop and clear). host_tier.py, its CPU tests and tools/bench_conversations.py come over as he wrote them; the three tests of the window buffer are skipped. The concurrent decoder takes the tier too (its cache evicts into it; an admitted stream resumes from it). Co-authored-by: jkuepker <[email protected]>
Depends on #100. This branch is stacked on it: review the last two commits (
tools: bench_conversationsandfeat(cuda): host-RAM tier). The rest is #100's and drops out of this diff once it merges.This adds
--ram-tier-gib N, a host-RAM tier for Qwen3.8-27B's prompt states on the CUDA engine (NVIDIA and, with #100, ROCm). Conversations the GPU has no room for come back over PCIe instead of being prefilled again. On one stream the GPU then holds a single window-sized attention buffer, so the startup estimate fits a much larger window: a 32 GB R9700 serves 126,553 tokens instead of 32,768, or 221,382 with #100's--kv-dtype fp8.Benchmarks
One AMD Radeon AI PRO R9700 (gfx1201, 32 GB) in a host with 62 GiB of RAM; pinned PCIe copies measured at 12.9 GiB/s each way. Same software and checkpoints as #100. Launch:
tensorfold serve Vontra/Qwen3.8-27B-MLX-4bit, with and without--ram-tier-gib 24.Repeat turns.
tools/bench_conversations.py(added here): 8 conversations of 24,000 tokens served round-robin, 4 turns each, 32-token greedy replies, thinking off. Each later turn sends the conversation back with the reply and a short question. Tier and no-tier runs sent the same prompts turn for turn (replies feed the next turn).--ram-tier-gib 24Long prompts in the larger window. localeval's speed sweep (fresh-nonce prompts, 256 forced tokens, greedy, one rep):
Decode follows how many drafts a prompt accepts (one rep each; the 104k prompt accepted more than the 69k one). At long context it relies on #100's tree attention commits. On one fixed prompt a drafted round takes 40 ms at 3k tokens of context and 62 ms at 120k (#100 has the table); before them, the 16k, 69k and 104k rows decoded at 108, 57 and 33 tok/s.
The change
cuda/host_tier.py(new):HostTier, prompt states in fixed-size host chunks under a byte budget.record_stream), and later work that may overwrite those rows waits for it (fence).pos, DeltaNet state, and the drafter snapshot. A restored state is the one that left.qwen3_5/cuda/engine.py):gdn_geometry(one_kv=True)charges one buffer, not two retained prefixes, the current state and a growth copy."draft": falserequests and misses take the buffer the same way.--parallel, the tier keeps evicted states forMultiDecoder. A restored state gets buffers of its own, and the window is the same as without the tier.capacity.host_room()),--tp 2, GPUs on the host's memory (DGX Spark), families without the tier, and MLX (which has--spill-gib).cuda/streams.py:PrefixCacheremoves entries through one hook (on_evict, unset without the tier), plusdrop(ids)andclear().docs/recipes/qwen3.8-27b.mdwith these measurements; a README option row.Checked
On the R9700, 135 GPU tests pass. They are the new
tests/cuda/test_qwen27_ram_tier.pyandtests/cuda/test_qwen27_window_buffer.py, plus the prompt-cache, multi-stream and DFlash2 block suites. Every restored state, every prefill ending on one, the first sampled logits and the replies are compared against fresh prefills and the serial reference, bit for bit. Covered:"draft": falserequests taking the window buffer;MultiDecoderrestores;On a Mac, 3,995 CPU tests pass (rebased with feat: Qwen3.8-27B on AMD GPUs (ROCm), measured on a Radeon AI PRO R9700 #100 on
main0.5.0).tests/test_cuda_host_tier.pyruns the tier on CPU tensors, including:tests/test_cuda_build.py::test_the_lock_named_is_the_one_torch_waits_onfails on the Mac here and onmainalike.After the rebase on 0.5.0, on the R9700: the windows are unchanged (126,553 tokens, 221,382 with
--kv-dtype fp8), and served replies drafted and with"draft": falseare identical at 4,726 and 44,826 tokens in bf16 and fp8.Not claimed
tests/cudapass on a DGX Spark (GB10) with this branch, but it has only served on the R9700, and DGX Spark refuses the flag (the GPU shares host memory).capacity.py(host_room()factored out ofavailable_bytes) andstreams.pychange code NVIDIA runs without the flag.--parallel. It is covered by one GPU test only.--context, it is the largest the estimate fits, so a 32 GB card prefills up to 126k tokens.🤖 Generated with Claude Code