Add Dual Chunk Attention (DCA) for long-context training#4048
Draft
Ternura143 wants to merge 5 commits intoNVIDIA:mainfrom
Draft
Add Dual Chunk Attention (DCA) for long-context training#4048Ternura143 wants to merge 5 commits intoNVIDIA:mainfrom
Ternura143 wants to merge 5 commits intoNVIDIA:mainfrom
Conversation
Implement DCA as experimental_attention_variant='dca' for efficient training on 100K+ token sequences with sub-quadratic memory complexity. Key changes: - Add DualChunkAttention module with intra-chunk, successive-chunk, and inter-chunk attention using modified RoPE position encodings - Add dca_chunk_size and dca_local_size to TransformerConfig - Integrate DCA into SelfAttention with RoPE bypass - Add DCA module spec to experimental attention variant framework - Add comprehensive unit tests
Contributor
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
- Add FlashAttention path with native GQA support and LSE-based merging - Fix missing YARN mscale in RoPE application (was defaulting to 1.0) - Auto-dispatch between FlashAttention (CUDA) and unfused (CPU) backends - Add tests for mscale, FlashAttention availability, and FA vs unfused equivalence
Author
|
Hi @ko3n1g , this is a draft PR implementing Dual Chunk Attention. Would appreciate any early feedback on the architecture direction before I proceed with Context Parallelism integration. Thank you! |
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.
What does this PR do ?
Implement Dual Chunk Attention (DCA) for efficient long-context training on 100K+ token sequences with sub-quadratic memory complexity.
Resolves #2797.
Changes
New:
megatron/core/transformer/experimental_attention_variant/dca.pyDualChunkAttentionmodule with three attention components:chunk_lenModified:
transformer_config.py— Adddca_chunk_size(default: 8192),dca_local_size(default: 1024) config parameters with validationModified:
attention.py— DCA integration: skip standard RoPE and passrotary_pos_embto DCA core_attentionModified:
experimental_attention_variant_module_specs.py— Addget_dca_module_spec()and register"dca"in the experimental attention variant frameworkNew:
tests/unit_tests/transformer/test_attention_variant_dca.py— Unit tests for output shape, short-sequence equivalence, GQA, gradient flow, multi-chunk, causality, YARN mscale, FlashAttentionUsage
Status: Draft
Planned next steps:
References
Pre-checks