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

*Jiading Gai, Shuai Zhang, Xiang song, Yuyang, George Karypis*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/148696) · [OpenReview](https://openreview.net/forum?id=viyAwqIA4H) · [alphaXiv](https://www.alphaxiv.org/abs/2605.15422) · [Open on the map](../papers.html#p148696)

Category: [LLM Post-Training: RL & Distillation](../pcat/18.md) › [On-Policy Distillation for Reasoning](../pgroup/351.md) · Type: new method · Keywords: FlashAttention, shared prompt optimization, RL post-training, GPU efficiency, large rollout training

Areas: [LLM Reasoning](../areas/reasoning.md) › Reasoning Optimization › Group Relative Advantage Estimation; [Long Context](../areas/longcontext.md) › Long-context mechanisms › Efficient long-context attention

## Summary
DualKV introduces a FlashAttention kernel variant that eliminates redundant prompt token replication in RL training, achieving significant speedups and higher hardware utilization.

## Explained to a 5-year-old
When teaching an AI model using reinforcement learning, they give it a long story (prompt) and many answers (responses). Right now, the computer reads the story many times, which is slow. The new idea is to read the story only once because the model already knows what it means, and then answer each part separately, making the computer work faster. This helps the robot learn quicker and uses the computer better. It makes training big AI models easier and faster.

## Explained to a 5-year-old, longer
When teaching an AI model using reinforcement learning, they give it a long instruction (prompt) and then let it generate many answers (responses). Usually, the computer processes the instruction over and over for each answer, which takes a lot of time and memory. The new trick is to look at the instruction only once because the model already knows what it means, and then handle each answer separately. This way, the computer does less work and finishes training faster. It also lets the training use more data at once, which makes the model learn better. The improvement works for both small and huge models, saving a lot of energy and money. It helps researchers train powerful AI assistants more quickly and efficiently. The method also works with different training methods like GRPO and DAPO, giving speedups across the board. By using the new approach, GPUs can do more work in less time, which is great for everyone who builds large AI systems.

## For a technical reader
DualKV modifies the FlashAttention kernel to process shared prompt tokens only once, using fused forward/backward CUDA kernels that handle context and responses separately. It also restructures the data pipeline to pack tokens more compactly, reducing overall token count per micro-batch. This yields 1.6-2.1× faster policy updates and up to 3.8× speedups at large model scales, while maintaining exact equivalence to standard attention.

## Problem
Training large language models with reinforcement learning using many response sequences from a shared prompt leads to duplicated computation because the prompt tokens are processed repeatedly for each sequence, causing high compute and memory cost.

## Method
The approach processes the shared prompt tokens only once by exploiting causal masking invariance, using fused CUDA kernels that handle shared context and per-sequence responses in a single pass, and redesigns the data pipeline to pack tokens more efficiently.

## Results
The approach achieves 1.63-2.10× policy-update speedup on Qwen3-8B GRPO, raises MFU from 36% to 76%, and on 30B MoE yields 3.82× policy-update and 3.38× end-to-end step speedup over FlashAttention.

## Contributions
The paper introduces a kernel-level optimization that eliminates redundant prompt token replication, a data-pipeline redesign for token packing, and demonstrates substantial speedups and hardware efficiency for large-rollout RL training.

## Limitations and assumptions
The approach assumes decoder-only models where prompt representations are invariant due to causal masking, limiting applicability to other architectures.

## Practical relevance
The method enables faster and more hardware-efficient RL training of large language models, allowing larger batches and better utilization of GPU resources.

## Research questions this paper is counted under

- [How can we reduce computational waste and improve throughput in large language model reinforcement learning rollouts?](../q/144.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/148696)
