Repository navigation
Conversation
gfx11 has no fp8 converts and lowers fp32 -> bf16 to integer RNE code, so the generic E4M3 decode dominates grouped decode, repeated for every dot-operand replica. On gfx11 the decode stage reads each E4M3 code as the fp16 bit pattern of value/256 (exact for every finite code), pins it to the load layout, restores the 256 in kv_row_scale and runs fp16 WMMA. It uses 16-key single-stage tiles, a minimum split length of 32 and up to eight programs per SM.
On gfx11 the split extend kernel decoded every FP8 prefix tile in software once per query block and GQA head, which made FP8 prefill several times slower than BF16 at long prefixes. Reuse the gfx11 fp16 bit-pattern reader from the decode path for the paged prefix tiles, so no extra memory is needed. Q is held as fp16 through the prefix loops and reloaded for the chunk's own keys, and head dims 129-256 use 64x16 tiles. Both keep the kernel's register spills under ROCr's single-dispatch scratch limit; above it every launch spends ~0.2 ms allocating scratch. Other architectures, formats and the non-split extend kernel are unchanged.
zihaomu
marked this pull request as ready for review
November 27, 2026 08:34
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #899 (RDNA3 FP8 KV decode). Until #899 merges, this diff also contains its commit
3422824; the change of this PR is the top commit0cc7bf3.Follow-up from the #899 review: instead of the transient dequantization workspace of the earlier revision, the prefill (split extend) kernel now reads paged FP8 K/V with the same in-kernel gfx11 reader that #899 uses for decode. No extra memory is allocated.
On RDNA3 (gfx11) the generic E4M3 decode is integer code (no FP8 converts, no hardware FP32 to BF16 convert), and the split extend kernel repeats it for every query block and GQA head that reads a prefix tile. On a Radeon PRO W7900D the prefix part of FP8-KV prefill ran 7-10x slower than with BF16 KV: Qwen3.5-0.8B 64K TTFT is 30.1 s with FP8 KV against 6.1 s with BF16 KV. With this PR it is 7.2 s.
Scope: gfx11 +
fp8_per_token_head, prefix reads of_extend_attention_split_kernelonly. The chunk's own keys (raw compute-dtype tensors), the non-split_extend_attention_kernel(not used by the Triton backend), RDNA4, CDNA, CUDA, BF16 KV and INT8 KV keep their current code (evidence below).Changes
_extend_attend_tilegainsF16_KV; when set it reads K/V tiles with perf(attention): fast fp8 kv decode on rdna3 (gfx11) #899's_kv_tile_gfx11_f16(E4M3 code to the fp16 bit pattern of value/256, exact for every finite code) andkv_row_scale(..., F16=True)restores the 256._extend_attention_split_kernelpasses it to the two paged-prefix loops only.extend_paged_attentionuses perf(attention): fast fp8 kv decode on rdna3 (gfx11) #899's_use_gfx11_f16_reader(kv_format):fp8_per_token_head,get_rocm_gfx_arch()starting withgfx11,FREETOKEN_FORCE_E4M3_EMUunset.F16_KV, Q is converted to fp16 once before the prefix loops and reloaded (volatile, so it is not merged with the first load) before the chunk's own keys, which keep the BF16 dot. Keeping both copies live pushed the D256 kernel over ROCr's scratch limit (next point).main). When a kernel's private segment is large enough that the device-wide scratch exceeds ROCr's single-dispatch limit (HSA_SCRATCH_SINGLE_LIMIT), every launch allocates and frees scratch, about 0.2 ms per launch here.HSA_SCRATCH_SINGLE_LIMIT=1073741824the same build took 61 us.HSA_ENABLE_SCRATCH_ASYNC_RECLAIM=0changed nothing. Builds at 1328 and 1340 B/lane had no overhead; builds at 1684 B/lane and above had it.test_extend_triton_attention_matches_referencenow also runs with FP8 and INT8 KV against the dequantized reference (the chunk's own rows come fromk_extend/v_extendin the split case), and gains two cases with long prefixes (1500/300 and 700/40 keys), chunks of several query blocks (130/200 and 150/9 rows) and a 100-key window inside the prefix. On gfx11 the FP8 split cases exercise the new reader; the existing quantized reference test'ssplit_extendcases (head_dim 64 to 512) and the bidirectional-block tests with FP8 also go through it.Numerics
p x scale_v x 256is rounded to fp16. The chunk's own keys are unchanged.main's FP8 path (table below).main's FP8 path (hash notes below). Task-quality evaluation has not been run.Isolation
get_rocm_gfx_arch()isNoneon CUDA), so tiles and launch parameters are unchanged, andF16_KV=Falseremoves the new branches at compile time._extend_attention_split_kernelthroughextend_paged_attention(Triton target override, warmup only, no launch) on perf(attention): fast fp8 kv decode on rdna3 (gfx11) #899 (3422824) and this commit (0cc7bf3) and compared instruction streams: head_dim 64/128/256/512 x BF16/FP8/INT8 KV for each target.Test environment
0000:A3:00.0. One GPU is visible viaROCR_VISIBLE_DEVICES;torch.cuda.get_device_properties(0)reports gfx1100 withmulti_processor_count=48.6.8.0-146-generic; amdgpu6.16.13.sha256:31cc953da2ee8345774f92c8f288dded6a19cbcd59c1ce96051970f48d627d18: ROCm 10.1.0, HIP7.16.26385, Python 3.13.13, Torch2.14.0+rocm10.1.0, Triton3.8.0, Transformers5.18.0.Qwen/Qwen3.5-0.8B, BF16,model.safetensorsSHA-25604b1c301231dd422b8860db31311ab2721511346a32cb1e079c4c4e5f1fe4696. 6 of its 24 layers are full attention, with head_dim 256 and 8 query / 2 KV heads.Tests (all on
0cc7bf3)pytest tests/kernels/test_triton_attention.py: 166 passed, 2 skipped (the gfx1201 cases of perf(attention): fast fp8 kv decode on rdna3 (gfx11) #899's per-code test).pytest tests/engine/test_attention_backend_arch.py tests/kvcache/test_kv_cache_rebuild.py tests/kvcache/test_pool_sizing_surface.py tests/attention/test_capture_rows_per_req.py: 62 passed, 4 skipped (sgl_kernel/flashinfernot installed).FREETOKEN_FORCE_E4M3_EMU=1 pytest tests/kernels/test_triton_attention.py -k fp8with a separate Triton cache: 52 passed, 2 skipped. Forced emulation disables the gfx11 reader.End-to-end A/B (
maina7a8236, #8993422824, this PR0cc7bf3)Same setup, server flags and client as #899 (one service at a time on one GPU; exact-length synthetic prompts; 1 warmup + 3 measured requests per point, medians; 128 output tokens,
temperature=0,ignore_eos=true,--cache-type naive,--max-prefill-length 2048; every request verified for exact prompt tokens, 128 completion tokens andcached_tokens == 0). All four services ran in one session.main/ FP8main/ FP8 #899 / FP8 this PRtorch.cuda.memory_reservedafter the run): BF16 2.816 GB; FP8main2.408 GB; perf(attention): fast fp8 kv decode on rdna3 (gfx11) #899 and this PR both 2.405 GB.mainFP8 at 32,768 and 65,536.Kernel microbenchmark: split extend per layer (ms)
mainBF16,mainFP8, this PR) per point.mainmainmainThe non-zero error at prefix 0 (D256 only) comes from the 64x16 tile changing the online-softmax accumulation order of the chunk's own (BF16) keys, not from the reader.
Open questions
max_q_lenis possible; I kept one tile for simplicity.main: 1188), so it pays the per-launch scratch allocation; it is still 6x faster thanmain's FP8 path with a prefix and equal without one.gfx11*; only gfx1100 was measured. The scratch limit is per device, so parts with fewer CUs have more headroom than the 96-CU W7900D.Scripts
bench_service.pyand the service A/B commands are the ones in #899.xcompile_extend.py (cross-compile and hash the split extend kernel)
bench_kernels.py (kernel microbenchmark; extend part used here)