Repository navigation
Conversation
|
@zihaomu Prefill: please drop it from this PR. For prefill we want the E4M3 decode to happen inside the extend kernel, not as an explicit dequantization of the KV cache into a BF16 copy before it. Decode looks correct. I ran the decode path on an H100 with the gate forced on and the No change on CUDA. On an H100, For the rebase, please follow the structure PR 897 landed with on main:
|
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.
cf44001 to
3422824
Compare
|
@jason-fxz Thanks for the careful review and for running the H100 checks. I reworked the PR on current Prefill dropped. Structure follows #897 on main.
Multi-row decode. The reader serves every Split rule.
Tests.
Results on W7900D (gfx1100), commit
The PR description has the full tables. On CUDA the only changes are the default- |
Follow-up to #897 (gfx1201 packed FP8 KV reads); related to #894 and #893.
On RDNA3 (gfx11),
fp8_per_token_headKV decode is far slower than BF16 KV: gfx11 has no FP8 converts and no hardware FP32 to BF16 convert, so the generic E4M3 decode runs as integer code, and Triton repeats it for every dot-operand replica. This PR gives gfx11 a dedicated decode reader. With it, FP8 KV decode on a Radeon PRO W7900D is faster thanmain's FP8 path at every measured context and row count. End to end (batch 1, one row per step) it matches BF16 KV decode at 512 tokens and is 20% faster at 64K, while keeping FP8's KV capacity.Scope: gfx11 +
fp8_per_token_head, decode only. Prefill/extend is unchanged; an in-kernel prefill reader will be a separate PR. RDNA4 (including #897's packed reader), CUDA, BF16 KV and INT8 KV keep their current code (evidence below).Changes
_use_gfx11_f16_reader(kv_format)sits next to_use_gfx12_fp8_readerinattention.py. It is true forfp8_per_token_headwhenget_rocm_gfx_arch()starts withgfx11andFREETOKEN_FORCE_E4M3_EMUis not set._kv_tile_gfx11_f16inkv_rows.pyturns each E4M3FN code into the fp16 bit pattern of value/256,((c & 0x80) << 8) | ((c & 0x7F) << 7).v_mov_b32inline-asm pin keeps the decode in the load layout, so each byte is decoded once rather than once per WMMA operand replica.kv_row_scale(..., F16=True)restores the 256.v_wmma_f32_16x16x16_f16with FP32 accumulation.ROWS <= MAX_DECODE_ROWS._gfx11_f16_decode_launch(rows * block_h)gives 16-key tiles, 1 stage (the pipeliner cannot predicate the asm pin), and 2 warps up to M = 16, 4 above; these values come from a W7900D sweep over 1/2/4/8 rows.decode_kv_split_cap(..., kv_format)allows 8 programs per SM, up to 256 splits, instead of 4 and 64. The Triton backend sizes decode scratch with its KV cache's format._max_request_splits(keys, min_split_len)takes the same minimum, so the sliding-window cap matches the kernel; thedecode_paged_attentiondocstring and the_decode_num_splitscomment state the rule withL= 128, or 32 for this reader.test_rocm_kv_decode_preserves_every_finite_fp8_code(the renamed RDNA4 per-code test) gains a gfx11 case comparing all 256 codes bit-for-bit, signed zero and subnormals included. It skips inline onget_rocm_gfx_arch().test_decode_triton_attention_splits_long_requestsandtest_decode_triton_attention_multi_row_matches_referencenow also run with FP8 and INT8 KV against the dequantized reference. On gfx11 the FP8 cases exercise the new reader across head_dim 256/512, GQA 2/6/8, mixed-length batches up to 8,193 keys, 1 to 8 rows per request, sliding windows, sinks and a scratch smaller than the split cap.test_quantized_kv_attention_matches_dequantized_referencedecode and decode_rows cases (head_dim 64 to 512) also go through the reader on gfx11.FakeKVCachenow subclasses the file's_PlainKVStorage, because the backend readskv_formatwhen sizing decode scratch; production pools define it by default.Numerics
p x scale_v x 256is rounded to fp16.main's FP8 path (hash table below).Isolation
get_rocm_gfx_arch()isNoneon CUDA), so host launch parameters, split caps and scratch sizes are unchanged.F16_KV=FalseandF16=Falseremove the new branches at compile time.main(a7a8236) and this commit (3422824) with a Triton target override (no launch) and compared the instruction streams. All 20 are identical: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. It has 24 layers, of which 6 are full attention, with head_dim 256 and 8 query / 2 KV heads (GQA4).Tests (all on
3422824)pytest tests/kernels/test_triton_attention.py: 142 passed, 2 skipped. The skips are the gfx1201 cases oftest_rocm_kv_decode_preserves_every_finite_fp8_code.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. The skips are becausesgl_kernel/flashinferare not installed.FREETOKEN_FORCE_E4M3_EMU=1 pytest tests/kernels/test_triton_attention.py -k 'quantized_kv_attention_matches or splits_long_requests or multi_row_matches', with a separate Triton cache: 80 passed. Forced emulation disables the gfx11 reader.End-to-end A/B (
maina7a8236vs3422824)temperature=0,ignore_eos=true,--cache-type naive.cached_tokens == 0.main/ FP8main/ FP83422824mainmain/ FP83422824main/ FP83422824main's FP8 path because prefill is out of scope. Long-context end-to-end time is therefore still dominated by FP8 prefill until the follow-up.main) and 2.316 GiB (3422824).3422824matches BF16 at 512 and 32,768 tokens and matches neither BF16 normainFP8 at 8,192 and 65,536.Kernel microbenchmark: decode stage 1+2 per layer (us)
3422824against the BF16 kernel on the dequantized cache.mainmain3422824With 4 rows at 8K keys or fewer, the reader is still 7-9% slower than BF16 KV; everywhere else in this table it is within 2% or faster.
Open questions
gfx11*(gfx1100/1101/1102 and RDNA3.5 gfx1150/1151), which share the missing converts, but only gfx1100 was measured. It can be narrowed to measured targets.Scripts
bench_service.py (end-to-end SSE client)
bench_kernels.py (decode microbenchmark; `--rows` for multi-row)
xcompile_main.py (ROCm cross-compile isolation check)