Repository navigation
[dev] DeepSeek V3.2 support #2154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2c7f33e
Initial draft version
kunlunl 501ad65
Run through single GPU version
kunlunl c3754a7
Fix the usage of attention_mask
kunlunl 451a36b
Update mask & indexer loss
kunlunl 186dcdc
Minor changes about code style
kunlunl 5271406
Fix TP
kunlunl 6e6fb50
Fix attn mask and norm type
kunlunl 237164e
Format
kunlunl 72ba916
Resolve minor comments
kunlunl 0e77355
Add unit test
kunlunl 8851f4e
Fix UT
kunlunl 7cdedf1
Use hidden_size to initialize indexer when q_lora_rank is None
kunlunl c915e4a
Add fused tilelang kernels
kunlunl de64232
Add indexer loss tracker
kunlunl 1d6f4d3
Fix sparse indexer loss
kunlunl 8495e03
Address minor comments
kunlunl ad04d58
Temporarily delete fused kernels
kunlunl 9dae1ce
Fix lint error
kunlunl 9cc697b
Make variable/class names more specific (SparseAttention -> DSA)
kunlunl b8f5c46
Merge branch 'dev' into kunlunl/deepseek_v3.2
kunlunl 0d7e1d1
Fix lint error
kunlunl 6630c7f
Merge linear-attention-type and sparse-attention-type to experimental…
kunlunl 4b7f3c5
Merge branch 'dev' into kunlunl/deepseek_v3.2
kunlunl b1e309e
Rename test_sparse_attention to test_attention_variant_dsa
kunlunl 6fe2f35
Minor fixes
kunlunl 33684d2
Fix qk norm spec in dsa spec
kunlunl a0b6fd9
Add fast-hadamard-transform to pyproject.toml
kunlunl f22344a
Remove fast-hadamard-transform
kunlunl ce99e9f
Minor fix for args
kunlunl 23ba310
Merge branch 'dev' into kunlunl/deepseek_v3.2
kunlunl cbfa053
Add mock hadamard_transformer
kunlunl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from megatron.core.models.backends import BackendSpecProvider | ||
| from megatron.core.transformer.sparse_attention import ( | ||
| Indexer, | ||
| IndexerSubmodules, | ||
| SparseAttention, | ||
| SparseAttentionSubmodules, | ||
| ) | ||
| from megatron.core.transformer.spec_utils import ModuleSpec | ||
|
|
||
|
|
||
| def get_indexer_spec_for_backend( | ||
| backend: BackendSpecProvider, normalization: Optional[str] = None | ||
| ) -> ModuleSpec: | ||
| """Helper function to get Indexer module spec for a given backend. | ||
|
|
||
| Args: | ||
| backend: Backend specification provider (TE or Local). | ||
| normalization: Normalization type ("RMSNorm" or None for LayerNorm). | ||
|
|
||
| Returns: | ||
| ModuleSpec for Indexer with appropriate submodules. | ||
| """ | ||
| rms_norm = normalization == "RMSNorm" | ||
| return ModuleSpec( | ||
| module=Indexer, | ||
| submodules=IndexerSubmodules( | ||
| linear_wq_b=backend.linear(), | ||
| linear_wk=backend.linear(), | ||
| k_norm=backend.layer_norm(rms_norm=rms_norm, for_qk=True), | ||
| linear_weights_proj=backend.linear(), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def get_sparse_attention_module_spec_for_backend( | ||
| backend: BackendSpecProvider, sparse_attention_type: str, normalization: Optional[str] = None | ||
| ) -> ModuleSpec: | ||
| """Helper function to get module spec for Sparse Attention. | ||
|
|
||
| Args: | ||
| backend: Backend specification provider (TE or Local). | ||
| sparse_attention_type: Type of sparse attention. | ||
| normalization: Normalization type ("RMSNorm" or None for LayerNorm). | ||
|
|
||
| Returns: | ||
| ModuleSpec for the sparse attention implementation with appropriate submodules. | ||
| """ | ||
| if sparse_attention_type == "dsa": | ||
| # Because TransformerEngine does not support sparse attention yet, we use local | ||
| # implementation whether the backend is TransformerEngine or not. | ||
| return ModuleSpec( | ||
| module=SparseAttention, | ||
| submodules=SparseAttentionSubmodules( | ||
| indexer=get_indexer_spec_for_backend(backend, normalization=normalization), | ||
| ), | ||
| ) | ||
| else: | ||
| raise ValueError(f"Invalid sparse attention type: {sparse_attention_type}") |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.