Repository navigation
[FEAT](kernels): implement Prefix-Shared Fused Attention for GRPO logprob computation - #71
Merged
Merged
Conversation
Signed-off-by: vensen <[email protected]>
Signed-off-by: vensen <[email protected]>
github-actions
Bot
requested review from
EthanZero2Hero,
bitborne and
inaniloquentee
June 3, 2026 17:27
Signed-off-by: vensen <[email protected]>
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.
Fixes #65
Purpose
In GRPO and PPO training pipelines, multiple generated responses (Group Size,$G$ ) share the exact same prompt prefix.$G$ dimension. This results in severe Memory-Bound bottlenecks and massive VRAM bloat (computing the same KV tiles $G$ times), which often leads to OOM during Long Context RL tasks.
When using standard SDPA backends (like PyTorch Native FlashAttention), the KV cache for the shared prompt must be expanded and repeated across the
This PR implements a hardware-aware Prefix-Shared Fused Attention CUDA kernel to solve this. By leveraging a 3D grid layout and L2 Cache broadcasting, the shared prompt KV tiles are loaded into SRAM once and naturally broadcasted across the$G$ queries in the registers. This reduces the global memory read complexity for the KV cache from $O(G \cdot L_{kv} \cdot D)$ down to $O(L_{kv} \cdot D)$ , fundamentally breaking the memory wall.
Test Plan
Test Result
Benchmark Environment: NVIDIA RTX A4000 (16GB VRAM, PCIe Gen4)
Benchmark Data:
(Note: TFLOPS represents hardware utilization. Native SDPA hits a memory-bound wall at higher len_kv due to redundant reads, whereas the Prefix-Shared kernel scales beautifully via L2 Cache)