Deepseek v4 Support#1195
Merged
Merged
Conversation
Collaborator
Author
|
869b205 /ok to review. |
Collaborator
Author
|
Muon optimizer with Zero 1 adaptation will be push after releasing next version FlagOS. |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds DeepSeek V4 training support into FlagScale/Megatron integration by introducing a dedicated DeepSeek V4 training entrypoint and model wiring (hybrid attention + hyper-connections + optional engram), along with a new functional test case and updated CLI/config plumbing.
Changes:
- Introduce DeepSeek V4 model builder/model/block/layer implementations and a new
train_deepseek_v4.pyentrypoint. - Extend argument parsing/config translation for DeepSeek V4 hybrid attention and related settings.
- Add/adjust functional test configs + gold values for a new DeepSeek V4 test case and update CUDA platform test selection.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils/config/platforms/cuda.yaml | Adds a DeepSeek test case to CUDA platform functional test selection. |
| tests/functional_tests/train/deepseek/gold_values/tp1_pp2_ep2_v4.json | New gold values baseline for the DeepSeek V4 functional training case. |
| tests/functional_tests/train/deepseek/conf/train/tp1_pp2_ep2_v4.yaml | New DeepSeek V4 training configuration used by functional tests. |
| tests/functional_tests/train/deepseek/conf/train/data.yaml | Updates DeepSeek functional test data/tokenizer paths. |
| tests/functional_tests/train/deepseek/conf/tp1_pp2_ep2_v4.yaml | New top-level Hydra experiment config pointing to the DeepSeek V4 entrypoint. |
| flagscale/train/megatron/training/arguments.py | Adds DeepSeek V4 hybrid attention arg parsing + config mapping changes. |
| flagscale/train/megatron/training/arguments_fs.py | Adds DeepSeek V4-related arg validation and a new optimizer flag; removes local engram arg registration. |
| flagscale/train/megatron/train_deepseek_v4.py | New DeepSeek V4 training script/entrypoint. |
| flagscale/models/megatron/engram/short_conv.py | Removes local Engram implementation code (moved upstream). |
| flagscale/models/megatron/engram/ngram_hash.py | Removes local Engram hashing/tokenizer implementation (moved upstream). |
| flagscale/models/megatron/engram/multi_head_embedding.py | Removes local Engram embedding implementation (moved upstream). |
| flagscale/models/megatron/engram/engram.py | Removes local Engram module (moved upstream). |
| flagscale/models/megatron/engram/engram_transformer_layer.py | Switches to using upstream megatron.core.transformer.engram.EngramModule. |
| flagscale/models/megatron/engram/engram_model.py | Switches hash mapping import to upstream megatron.core.transformer.engram. |
| flagscale/models/megatron/engram/engram_config.py | Removes local EngramConfig dataclass (moved upstream). |
| flagscale/models/megatron/deepseek_v4/deepseek_transformer_layer.py | New DeepSeek-specific transformer layer wrapper with engram hooks. |
| flagscale/models/megatron/deepseek_v4/deepseek_transformer_block.py | New DeepSeek-specific transformer block with hyper-connection + (planned) MHC recompute wiring. |
| flagscale/models/megatron/deepseek_v4/deepseek_model.py | New DeepSeek GPTModel subclass with lazy/async engram hash computation. |
| flagscale/models/megatron/deepseek_v4/deepseek_builder.py | New DeepSeek model builder/spec wiring for hybrid attention + optional engram. |
| examples/deepseek_v3/conf/train/next.yaml | Adds an example training config (DeepSeek v3 example directory). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| train: | ||
| aquila: ["tp2_pp2", "tp4_pp2"] | ||
| deepseek: ["tp2_pp2_ep2", "tp2_pp2_ep2_engram"] | ||
| deepseek: ["tp2_pp2_ep2", "tp2_pp2_ep2_engram", "tp1_pp2_ep3_v4"] |
Comment on lines
+15
to
+16
| }, | ||
| "fake": true |
Comment on lines
1
to
3
| data: | ||
| data_path: /home/gitlab-runner/data/pile_wikipedia_demo/pile_wikipedia_demo | ||
| data_path: /workspace/data/enron_emails_demo_text_document_qwen | ||
| split: 1 |
| tokenizer: | ||
| tokenizer_type: QwenTokenizerFS | ||
| tokenizer_path: /home/gitlab-runner/tokenizers/qwentokenizer | ||
| tokenizer_path: /workspace/tokenizers/qwentokenizer |
| shell_cmds: null | ||
| envs: | ||
| HYDRA_FULL_ERROR: 1 | ||
| CUDA_VISIBLE_DEVICES: "4,5,6,7" |
Comment on lines
+84
to
+88
| _broadcast(batch['tokens']) | ||
| _broadcast(batch['attention_mask']) | ||
| _broadcast(batch['position_ids']) | ||
| ######### FlagScale Begin ######## | ||
| if mpu.get_dualpipev_pipeline_model_parallel_world_size() is not None: |
Comment on lines
+14
to
+18
| if TYPE_CHECKING: | ||
| from megatron.core.tensor_parallel.random import CheckpointManager | ||
| else: | ||
| CheckpointManager = None | ||
|
|
Comment on lines
+296
to
+300
| next_layer = self.layers[l_no + 1] | ||
| if getattr(next_layer, "is_engram_layer", False): | ||
| next_layer.pre_compute_embedding(engram_hash_input_ids) | ||
| #### FlagScale End #### | ||
| hidden_states, context = layer( |
Comment on lines
+209
to
+218
| # Precompute the engram_hash_iput_ids, it will be used to create a TransformerChunkSchedulePlan. | ||
| engram_hash_input_ids = LazyHashInputIds( | ||
| hash_mapping=self.engram_hash, | ||
| input_ids=input_ids, | ||
| hash_stream=self._hash_stream, | ||
| ) | ||
| if extra_block_kwargs is None: | ||
| extra_block_kwargs = { | ||
| "engram_hash_input_ids": engram_hash_input_ids, | ||
| } |
| """Build decoder block spec and attach STM/HC placeholders to each local layer.""" | ||
|
|
||
| """GPT block spec.""" | ||
| layer_norm_impl = TENorm |
aoyulong
previously approved these changes
May 24, 2026
…ed by the num_residual_streams.
zhaoyinglia
approved these changes
May 24, 2026
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.
PR Category
[Train] Most of codes are copied from Megatron-LM Dev branch. The dev branch is different with main branch or release version.
Megatron LM PR:
DeepSeek-V4:
NVIDIA/Megatron-LM#4458
NVIDIA/Megatron-LM#4481
NVIDIA/Megatron-LM#4518
mHC:
NVIDIA/Megatron-LM#2943
PR Types
[New features]
PR Description
Add DeepSeek V4 model into FlagScale and Megatron-FL
Supported:
Unsupported:
NOTE: This is only a draft pr, please reivew to give more suggestions.
such as:
Next plan: