-
Notifications
You must be signed in to change notification settings - Fork 500
Fix explicit sharding for Deepseek #3595
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
Open
Shuwen-Fang
wants to merge
7
commits into
main
Choose a base branch
from
explicitpp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−29
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -14,17 +14,16 @@ | |
|
|
||
| """ Smoke test """ | ||
| import os | ||
| import unittest | ||
|
|
||
| from absl.testing import absltest | ||
| from absl.testing import absltest, parameterized | ||
| from tests.utils.test_helpers import get_test_config_path, get_test_dataset_path, get_test_base_output_directory | ||
|
|
||
| from maxtext.common.gcloud_stub import is_decoupled | ||
| from maxtext.trainers.pre_train.train import main as train_main | ||
| from maxtext.utils.globals import MAXTEXT_ASSETS_ROOT | ||
|
|
||
|
|
||
| class Train(unittest.TestCase): | ||
| class Train(parameterized.TestCase): | ||
| """Smoke test G3 only""" | ||
|
|
||
| def setUp(self): | ||
|
|
@@ -46,7 +45,7 @@ def test_tiny_config(self): | |
| # pylint: disable=f-string-without-interpolation | ||
| f"base_output_directory={self.base_output_directory}", | ||
| "run_name=runner_test", | ||
| r"dataset_path={self.dataset_path}", | ||
| f"dataset_path={self.dataset_path}", | ||
| "base_emb_dim=8", | ||
| "base_num_query_heads=4", | ||
| "base_num_kv_heads=4", | ||
|
|
@@ -74,7 +73,7 @@ def test_tiny_config_no_scan(self): | |
| # pylint: disable=f-string-without-interpolation | ||
| f"base_output_directory={self.base_output_directory}", | ||
| "run_name=runner_test", | ||
| r"dataset_path={self.dataset_path}", | ||
| f"dataset_path={self.dataset_path}", | ||
| "base_emb_dim=8", | ||
| "base_num_query_heads=4", | ||
| "base_num_kv_heads=4", | ||
|
|
@@ -103,7 +102,7 @@ def test_tiny_config_explicit_shardmode(self): | |
| # pylint: disable=f-string-without-interpolation | ||
| f"base_output_directory={self.base_output_directory}", | ||
| "run_name=runner_test", | ||
| r"dataset_path={self.dataset_path}", | ||
| f"dataset_path={self.dataset_path}", | ||
| "base_emb_dim=8", | ||
| "base_num_query_heads=4", | ||
| "base_num_kv_heads=4", | ||
|
|
@@ -123,6 +122,93 @@ def test_tiny_config_explicit_shardmode(self): | |
| ] | ||
| ) | ||
|
|
||
| def test_tiny_config_explicit_shardmode_deepseek(self): | ||
| test_tmpdir = os.environ.get("TEST_TMPDIR") # pylint: disable=unused-variable | ||
| train_main( | ||
| [ | ||
| None, | ||
| get_test_config_path(), | ||
| # pylint: disable=f-string-without-interpolation | ||
| f"base_output_directory={self.base_output_directory}", | ||
| "run_name=runner_test_deepseek", | ||
| f"dataset_path={self.dataset_path}", | ||
| "model_name=deepseek3-test", | ||
| "base_emb_dim=32", | ||
| "base_num_query_heads=4", | ||
| "base_num_kv_heads=4", | ||
| "base_mlp_dim=64", | ||
| "base_moe_mlp_dim=64", | ||
| "base_num_decoder_layers=2", | ||
| "first_num_dense_layers=1", | ||
| "head_dim=32", | ||
| "v_head_dim=32", | ||
| "qk_nope_head_dim=32", | ||
| "qk_rope_head_dim=16", | ||
| "q_lora_rank=16", | ||
| "kv_lora_rank=16", | ||
| "per_device_batch_size=1", | ||
| "max_target_length=64", | ||
| "dataset_type=synthetic", | ||
| "steps=2", | ||
| "enable_checkpointing=False", | ||
| rf"tokenizer_path={os.path.join(MAXTEXT_ASSETS_ROOT, 'tokenizers', 'tokenizer.llama2')}", | ||
| "sparse_matmul=True", | ||
| "capacity_factor=-1", | ||
| "shard_mode=explicit", | ||
| "enable_goodput_recording=False", | ||
| "enable_checkpoint_cloud_logger=False", | ||
| "monitor_goodput=False", | ||
| "abort_on_nan_loss=False", | ||
| "abort_on_inf_loss=False", | ||
| ] | ||
| ) | ||
|
|
||
| @parameterized.named_parameters( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NuojCheng these tests depend on the hardware type but should work for all topologies with >= 2 devices. wdyt?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think we have v6e-4 for CI tests |
||
| ("fsdp_expert", ["ici_fsdp_parallelism=-1", "ici_expert_parallelism=2", "use_ring_of_experts=True"]), | ||
| ("fsdp_expert_no_roe", ["ici_fsdp_parallelism=-1", "ici_expert_parallelism=2", "use_ring_of_experts=False"]), | ||
| ("fsdp", ["ici_fsdp_parallelism=-1"]), | ||
| ) | ||
| def test_parallelism_configs(self, parallelism_args): | ||
| test_tmpdir = os.environ.get("TEST_TMPDIR") # pylint: disable=unused-variable | ||
|
|
||
| base_args = [ | ||
| None, | ||
| get_test_config_path(), | ||
| f"base_output_directory={self.base_output_directory}", | ||
| "run_name=runner_test_parallelism", | ||
| f"dataset_path={self.dataset_path}", | ||
| "model_name=deepseek3-test", | ||
| "base_emb_dim=32", | ||
| "base_num_query_heads=4", | ||
| "base_num_kv_heads=4", | ||
| "base_mlp_dim=64", | ||
| "base_moe_mlp_dim=64", | ||
| "base_num_decoder_layers=2", | ||
| "first_num_dense_layers=1", | ||
| "head_dim=32", | ||
| "v_head_dim=32", | ||
| "qk_nope_head_dim=32", | ||
| "qk_rope_head_dim=16", | ||
| "q_lora_rank=16", | ||
| "kv_lora_rank=16", | ||
| "per_device_batch_size=1", | ||
| "max_target_length=64", | ||
| "dataset_type=synthetic", | ||
| "steps=2", | ||
| "enable_checkpointing=False", | ||
| rf"tokenizer_path={os.path.join(MAXTEXT_ASSETS_ROOT, 'tokenizers', 'tokenizer.llama2')}", | ||
| "capacity_factor=-1", | ||
| "shard_mode=explicit", | ||
| "enable_goodput_recording=False", | ||
| "monitor_goodput=False", | ||
| "abort_on_nan_loss=False", | ||
| "abort_on_inf_loss=False", | ||
| ] | ||
|
|
||
| full_args = base_args + parallelism_args | ||
|
|
||
| train_main(full_args) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| absltest.main() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI we did similar things but in a different style in
attention_op.py, seemaxtext/src/maxtext/layers/attention_op.py
Lines 1487 to 1498 in 82ece9d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated