Repository navigation
Port _fused_fp8_set_kv_buffer_kernel - #11
Merged
apinge merged 3 commits intoAug 10, 2026
Merged
Conversation
apinge
marked this pull request as ready for review
August 5, 2026 07:52
apinge
marked this pull request as draft
August 5, 2026 07:53
apinge
marked this pull request as ready for review
August 5, 2026 08:58
There was a problem hiding this comment.
Pull request overview
This PR ports an ROCm/AITER-specific fused Triton kernel (_fused_fp8_set_kv_buffer_kernel) and wires it into the KV cache write path to accelerate FP8 KV cache population (notably for head_dim=256, NHD layout).
Changes:
- Add additional eligibility checks for DFlash fused QKV weight slicing to avoid invalid/unsupported layouts.
- Add an ROCm FP8 KV-cache “fast path” in
MHATokenToKVPool.set_kv_buffer, including a warmup initializer. - Introduce a new Triton kernel module (
aiter_fp8_kv_kernel.py) that fuses scale division + FP8 KV-cache writes.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| python/sglang/srt/speculative/dflash_utils.py | Tightens validation for when DFlash is allowed to slice KV weights from fused QKV weights. |
| python/sglang/srt/mem_cache/memory_pool.py | Adds ROCm FP8 fused KV write initialization and a fast-path in set_kv_buffer. |
| python/sglang/srt/layers/attention/triton_ops/aiter_fp8_kv_kernel.py | New Triton fused kernel + Python wrapper for FP8 KV buffer writes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
python/sglang/srt/mem_cache/memory_pool.py:1744
- The fused FP8 KV write path accepts any float32 tensor scale, but the Triton kernel loads
tl.load(k_scale_ptr)/tl.load(v_scale_ptr)without an offset, so it only supports a single-element (scalar) scale tensor. As written, a multi-element tensor scale would silently use only the first element and produce incorrect KV values. Tighten the gate to requirenumel()==1for tensor scales (matching the per-tensor FP8 KV scale semantics elsewhere).
or (
isinstance(scale, torch.Tensor)
and scale.device == cache_k.device
and scale.dtype == torch.float32
)
python/sglang/srt/layers/attention/triton_ops/aiter_fp8_kv_kernel.py:114
fused_fp8_set_kv_buffer()doesn’t validate that the destination cache tensors are actually FP8 (or thatcache_locis an integer 1D index tensor). If a caller accidentally passes the uint8 storage view (used elsewhere for FP8 caches) or a non-integercache_loc, the kernel will still run and will store incorrectly-typed data or read invalid indices. Add explicit dtype/shape validation to fail fast with a clear error.
if k_cache.ndim != 3 or v_cache.ndim != 3:
raise ValueError("AITER fused FP8 KV write expects 3D K/V cache tensors")
if k.ndim != 3 or v.ndim != 3:
raise ValueError("AITER fused FP8 KV write expects 3D K/V input tensors")
if cache_loc.numel() == 0:
apinge
force-pushed
the
qwen3_5_fused_fp8_set_kv_buffer_kernel
branch
from
August 10, 2026 00:59
1529106 to
f1b693e
Compare
Signed-off-by: apinge <[email protected]>
sammysun0711
approved these changes
Aug 10, 2026
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.
Motivation
This PR ports the
_fused_fp8_set_kv_buffer_kernelfrom zejunchen-zejun#276Note that the kernel is only used for ptpc fp8.
Modifications
Accuracy Tests
Origin Acc
Dflash Acc
Speed Tests and Profiling
C1 8k in prefill before
C1 8k in prefill after
C1 8k in decode after
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ci