{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/arxiv-2605-15422","title":"DualKV: Shared-Prompt Flash Attention for Efficient RL Training with Large Rollouts and Long Contexts","arxiv_id":"2605.15422","date":"2026-05-14","proceeding":null,"authors":["Jiading Gai","Shuai Zhang","Xiang Song","Bernie Wang","George Karypis"],"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.","url_abs":"https://arxiv.org/abs/2605.15422","url_pdf":"https://arxiv.org/pdf/2605.15422","source":{"archive":null,"snapshot":"2025-07-28","note":"not in the Papers with Code archive (frozen at the snapshot)","row_kind":"graph","title_abstract_authors_date":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)"},"code_links":[],"tasks":[],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2605.15422","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2605.15422"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"mentioned_in_github":null,"is_official":null,"provenance":"deterministic:regex_extraction","mentioned_in_paper":null,"url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl","reach":null}],"summary":{"ran":12,"unverified":1},"by_repo_kind":{"found_in_text":{"samples":13,"ran":12,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":13,"samples":[{"code_sha256_prefix":"5ec949977c334f87","entry":"apply_rotary_emb_torch","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/layers/rotary.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/layers/rotary.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"5ec949977c334f87"}},{"code_sha256_prefix":"ae22707df86d95e3","entry":"baichuan_config_to_gpt2_config","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/models/baichuan.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/models/baichuan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"ae22707df86d95e3"}},{"code_sha256_prefix":"cc628b160e090ba1","entry":"convert_blockmask","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/flash_blocksparse_attn_interface.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/flash_blocksparse_attn_interface.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"cc628b160e090ba1"}},{"code_sha256_prefix":"7541ce9614862680","entry":"flash_attn_qkvpacked_func","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/flash_attn_interface.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/flash_attn_interface.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"7541ce9614862680"}},{"code_sha256_prefix":"1586b639a5abd0b0","entry":"init_to_zero","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/flash_attn_triton.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/flash_attn_triton.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"1586b639a5abd0b0"}},{"code_sha256_prefix":"19ad2ccd82e378c1","entry":"maybe_contiguous","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/flash_attn_interface.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/flash_attn_interface.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"19ad2ccd82e378c1"}},{"code_sha256_prefix":"a8cf6124094beaab","entry":"pad_input","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/bert_padding.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/bert_padding.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"a8cf6124094beaab"}},{"code_sha256_prefix":"b83af9adbdeec661","entry":"remap_state_dict_hf_baichuan","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/models/baichuan.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/models/baichuan.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"b83af9adbdeec661"}},{"code_sha256_prefix":"163292f43a3c861b","entry":"rotate_half","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/layers/rotary.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/layers/rotary.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"163292f43a3c861b"}},{"code_sha256_prefix":"a0595f1c95cacf06","entry":"round_multiple","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/flash_attn_interface.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/flash_attn_interface.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"a0595f1c95cacf06"}},{"code_sha256_prefix":"d84093c20a0ed8fd","entry":"unpad_input","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/bert_padding.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/bert_padding.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"d84093c20a0ed8fd"}},{"code_sha256_prefix":"62394c842aafb022","entry":"unpad_input_for_concatenated_sequences","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/flash_attn/bert_padding.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/flash_attn/bert_padding.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"62394c842aafb022"}},{"code_sha256_prefix":"a264f868efe9ee7a","entry":"setup_fa2","repo":"amazon-science/dualkv-flash-attn-for-rl","repo_kind":"found_in_text","path":"flash-attention/benchmarks/benchmark_attn.py","file_url":"https://github.com/amazon-science/dualkv-flash-attn-for-rl/blob/HEAD/flash-attention/benchmarks/benchmark_attn.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NOASSERTION","inline_ok":false,"mcp_get_code":{"code_sha256":"a264f868efe9ee7a"}}]},"arxiv_metadata":{"licence":"arXiv metadata, CC0 1.0 (https://info.arxiv.org/help/license)","fields":["title","abstract","authors","date"],"primary_category":"cs.LG","source":"arxiv_2026.jsonl"},"syntology_extracted_results":{"kind":"leaderboard_placements","source":"Syntology's leaderboard-shaped extractor over the paper's own arXiv-HTML tables: a model pointed at a cell, the number was read from that cell and checked against the board's metric, dataset, split and scale, and an independent check accepted the entry; not reviewed by the paper's authors or the archive's editors","extractor_model":"global.anthropic.claude-sonnet-4-5-20250929-v1:0","verifier_model":null,"prompt_sha":"fa63d4bb9d755694","coverage":{"sentence":"Syntology has checked 6,795 of the 9,581 papers on this site that are newer than the archive; results from the others appear after they are checked.","papers_newer_than_archive":9581,"papers_checked":6795},"entries":[],"not_placed":{"boards":0,"rejected_by_independent_check":0,"refused_by_a_rule":0,"check_did_not_answer":0,"proposed_without_a_cell":0,"declined_by_site":0}}}