# DualKV: Shared-Prompt Flash Attention for Efficient RL Training with Large Rollouts and Long Contexts

- **ID:** 500
- **Kind:** paper
- **URL:** https://arxiv.org/abs/2605.15422
- **Authors:** Jiading Gai, Shuai Zhang, Xiang Song, Bernie Wang, George Karypis
- **Venue:** arXiv / Amazon Web Services
- **Published:** 2026
- **Tags:** dualkv, flashattention, grpo, dapo, kv-cache, rl-training, verl, amazon, prefix-sharing
- **Topics:** RL training, FlashAttention, KV cache, long context
- **Added:** 2026-10-01
- **Research status:** done
- **Page:** https://papers.projxon.ai/entries/500

## Summary

Standard FA2 packs N same-prompt rollouts as N(P+R) tokens, recomputing the prompt N times. DualKV repacks to P+NR and splits attention into one prompt self-attention plus a fused kernel that reads shared KV once and accumulates N-way dK/dV with fp32 atomics; mathematically equivalent, no approximation. On Qwen3-8B GRPO (8xH100, N=32, 8K-context) policy-update is 1.63–2.09x faster, MFU 36%→76%; DAPO 2.47x / 77% MFU. At 30B MoE on 16xH100, 3.82x policy-update and 3.38x step vs FA2 that needs 4-way Ulysses SP. Also supports Gemma-4 hybrid d=512 / sliding-window at 64K. Code https://github.com/amazon-science/dualkv-flash-attn-for-rl.

## Attributes

- **Purpose:** Eliminate shared-prompt replication in GRPO/DAPO policy updates with a two-region FlashAttention kernel
- **Scale:** Qwen3-8B GRPO/DAPO LongReason, 8xH100, N=32, P=8K R=2K; Qwen3-30B-A3B 16xH100; Gemma-4-31B 8xH200 up to 64K SP=8; kernel benches A100/H100 vs FA2/Prefix Grouper
- **Time period:** 2026-05-14 (arXiv 2605.15422 v1); last revised 2026-08-07 (v4). HF paper publishedAt 2026-05-27.

## From the source (fetched 2026-10-03)

- **Published:** May 14, 2026 (arXiv)
- **Last revised:** Aug 7, 2026 (arXiv)
- **arXiv categories:** cs.LG (arXiv)
- **Citations:** 2 (Semantic Scholar)
- **References:** 24 (Semantic Scholar)

## Abstract

Modern RL post-training methods such as GRPO and DAPO train on N response sequences of R tokens sampled from a shared prompt of P tokens, but standard FlashAttention replicates all P prompt tokens N times across both forward and backward passes -- duplicating compute and memory on identical hidden states. In large-rollout, long-context RL training (N>=16, P>=8K), this redundancy dominates the policy update cost. We observe that in decoder-only models, causal masking makes prompt representations invariant across sequences at every layer, so all per-token operations (norms, projections, MLP) and attention can process the prompt once -- a property not yet exploited at the kernel level for training. We propose DualKV, the first FlashAttention kernel variant that eliminates shared-prompt replication during RL training, via (1) fused CUDA forward and backward kernels that iterate over two disjoint KV regions -- shared context and per-sequence response -- in a single kernel launch, and (2) a data-pipeline redesign in veRL that repacks N(P+R) tokens into P+NR tokens per micro-batch, extending the token reduction from attention to the entire model by a factor rho = N(P+R)/(P+NR). DualKV is mathematically equivalent to standard attention and introduces no approximation. On Qwen3-8B GRPO training with 8xH100 GPUs (N=32, 8K-context), DualKV achieves 1.63--2.09x policy-update speedup, enables 2x larger micro-batches, and raises MFU from 36% to 76%. Similar gains hold for DAPO (2.47x speedup, 77% MFU). At 30B MoE scale on 16xH100, DualKV achieves 3.82x policy-update and 3.38x end-to-end step speedup over FlashAttention (which requires 4-way Ulysses sequence parallelism to avoid OOM). DualKV also extends to hybrid sliding/global attention with head dimension 512 (which FA2 does not support) and integrates with Ulysses sequence parallelism, demonstrated on Gemma-4-31B GRPO at 64K context.

## Research notes

- Primary: arxiv abs (cs.LG). AWS (Gai/Zhang/Wang equal contrib); Song at Google (work done at AWS); Karypis at UMN. Correspondence jiadingg/shuaizs/yuyawang@amazon.com, xiangsx@google.com, karypis@umn.edu. Code CC-BY-NC-4.0 https://github.com/amazon-science/dualkv-flash-attn-for-rl (4 stars at check); gemma4-dev branch for hd512/SWA. HF paper page 1 upvote. Discord posted PDF. Uses LongReason/GSM8K; no new corpus, so no datasets_local row. ArXiv license widget not visible in converted abs HTML, so paper license left blank.

## Cites, within this collection

- [FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision](https://papers.projxon.ai/entries/575) (paper 2024, #575)
- [DAPO: An Open-Source LLM Reinforcement Learning System at Scale](https://papers.projxon.ai/entries/919) (paper 2025, #919)

## Related entries

- Discussed in: [RL for language models after GRPO: fixes, costs, rewards, agents (overview)](https://papers.projxon.ai/entries/1207) (note, #1207)

## Similar entries

- [rLLM / DeepScaleR: Agentic RL framework (Agentica)](https://papers.projxon.ai/entries/677) (code, #677)
- [vime × RL-Kernel × AMD: Bitwise Train–Rollout Consistency on ROCm (RL-Kernel v0.1.0)](https://papers.projxon.ai/entries/1044) (post, #1044)
- [The ultimate guide to multi-harness RL](https://papers.projxon.ai/entries/839) (post, #839)
- [KV cache as GPU-memory bottleneck in Transformer serving (GQA/MQA, quantization, sliding window)](https://papers.projxon.ai/entries/1066) (idea, #1066)
- [You Need Better Attention Priors](https://papers.projxon.ai/entries/1216) (paper, #1216)
- [Scaling KV Cache Compression to Frontier Models (X thread by @RampLabs)](https://papers.projxon.ai/entries/740) (thread, #740)
