-
Notifications
You must be signed in to change notification settings - Fork 411
[DSV3] Forward and backward pass for single GPU #1320
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 all commits
Commits
Show all changes
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
# | ||
# Copyright (c) Meta Platforms, Inc. All Rights Reserved. | ||
|
||
from torchtitan.components.loss import build_cross_entropy_loss | ||
from torchtitan.components.lr_scheduler import build_lr_schedulers | ||
from torchtitan.components.optimizer import build_optimizers | ||
from torchtitan.datasets.hf_datasets import build_hf_dataloader | ||
from torchtitan.datasets.tokenizer.tiktoken import build_tiktoken_tokenizer | ||
from torchtitan.protocols.train_spec import register_train_spec, TrainSpec | ||
|
||
from .infra.parallelize import parallelize_deepseekv3 | ||
from .model.args import DeepSeekV3ModelArgs | ||
from .model.model import DeepSeekV3Model | ||
|
||
__all__ = [ | ||
"parallelize_deepseekv3", | ||
"DeepseekV3ModelArgs", | ||
"DeepseekV3Model", | ||
"deepseekv3_configs", | ||
] | ||
|
||
|
||
deepseekv3_configs = { | ||
"debugmodel": DeepSeekV3ModelArgs( | ||
vocab_size=102400, | ||
dim=256, | ||
inter_dim=10944, | ||
moe_inter_dim=1408, | ||
n_layers=3, | ||
n_dense_layers=1, | ||
n_heads=16, | ||
n_routed_experts=8, | ||
n_shared_experts=2, | ||
n_activated_experts=3, | ||
route_scale=1.0, | ||
q_lora_rank=0, | ||
kv_lora_rank=512, | ||
qk_nope_head_dim=128, | ||
qk_rope_head_dim=64, | ||
v_head_dim=128, | ||
mscale=0.70, | ||
), | ||
"16B": DeepSeekV3ModelArgs( | ||
vocab_size=102400, | ||
dim=2048, | ||
inter_dim=10944, | ||
moe_inter_dim=1408, | ||
n_layers=27, | ||
n_dense_layers=1, | ||
n_heads=16, | ||
n_routed_experts=64, | ||
n_shared_experts=2, | ||
n_activated_experts=6, | ||
route_scale=1.0, | ||
q_lora_rank=0, | ||
kv_lora_rank=512, | ||
qk_nope_head_dim=128, | ||
qk_rope_head_dim=64, | ||
v_head_dim=128, | ||
mscale=0.70, | ||
), | ||
"236B": DeepSeekV3ModelArgs( | ||
vocab_size=102400, | ||
dim=5120, | ||
inter_dim=12288, | ||
moe_inter_dim=1536, | ||
n_layers=60, | ||
n_dense_layers=1, | ||
n_heads=128, | ||
n_routed_experts=160, | ||
n_shared_experts=2, | ||
n_activated_experts=6, | ||
n_expert_groups=8, | ||
n_limited_groups=3, | ||
route_scale=16.0, | ||
q_lora_rank=1536, | ||
kv_lora_rank=512, | ||
qk_nope_head_dim=128, | ||
qk_rope_head_dim=64, | ||
v_head_dim=128, | ||
), | ||
"671B": DeepSeekV3ModelArgs( | ||
vocab_size=129280, | ||
dim=7168, | ||
inter_dim=18432, | ||
moe_inter_dim=2048, | ||
n_layers=61, | ||
n_dense_layers=3, | ||
n_heads=128, | ||
n_routed_experts=256, | ||
n_shared_experts=1, | ||
n_activated_experts=8, | ||
n_expert_groups=8, | ||
n_limited_groups=4, | ||
route_scale=2.5, | ||
score_func="sigmoid", | ||
q_lora_rank=1536, | ||
kv_lora_rank=512, | ||
qk_nope_head_dim=128, | ||
qk_rope_head_dim=64, | ||
v_head_dim=128, | ||
dtype="fp8", | ||
), | ||
} | ||
|
||
|
||
register_train_spec( | ||
TrainSpec( | ||
name="deepseek_v3", | ||
cls=DeepSeekV3Model, | ||
config=deepseekv3_configs, | ||
parallelize_fn=parallelize_deepseekv3, | ||
pipelining_fn=None, | ||
build_optimizers_fn=build_optimizers, | ||
build_lr_schedulers_fn=build_lr_schedulers, | ||
build_dataloader_fn=build_hf_dataloader, | ||
build_tokenizer_fn=build_tiktoken_tokenizer, | ||
build_loss_fn=build_cross_entropy_loss, | ||
) | ||
) |
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,23 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
|
||
import torch.nn as nn | ||
|
||
from torch.distributed.device_mesh import DeviceMesh | ||
|
||
from torchtitan.config_manager import JobConfig | ||
from torchtitan.distributed import ParallelDims | ||
|
||
|
||
def parallelize_deepseekv3( | ||
model: nn.Module, | ||
world_mesh: DeviceMesh, | ||
parallel_dims: ParallelDims, | ||
job_config: JobConfig, | ||
): | ||
# TODO: Add support for parallelizing the model, this is a placeholder function for now | ||
return model |
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.
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.