-
Notifications
You must be signed in to change notification settings - Fork 5
Add Naive Training Moe Example Code on Single GPU or Multi GPUs #10
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
Closed
Closed
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
|
|
||
|
|
||
|
|
||
| ## Clone the DualPipe & Setup Environment | ||
|
|
||
| ```bash | ||
| git clone https://github.com/deepseek-ai/DualPipe.git | ||
| cd dualpipe | ||
| conda create -n dualpipe python=3.10 -y | ||
| conda activate dualpipe | ||
| pip install -r requirements.txt | ||
| pip install -e . | ||
| ``` | ||
|
|
||
| ## Naive Implementation for Single-GPU and Multi-GPU Training of MoE Models | ||
| ```bash | ||
| MASTER_ADDR=localhost MASTER_PORT=12355 WORLD_SIZE=4 python examples/moe_train_basic.py | ||
| ``` | ||
|
|
||
| ### Parameters | ||
| - WORLD_SIZE=4: Uses 4 GPUs for pipeline parallelism | ||
| - MASTER_ADDR: Master node address | ||
| - MASTER_PORT: Communication port | ||
| - `test_moe_basic()`: Tests basic functionality of the MoE 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| __version__ = "1.0.0" | ||
|
|
||
| from dualpipe.dualpipe import DualPipe | ||
| from dualpipe.dualpipev import DualPipeV | ||
| from dualpipe.comm import ( | ||
| set_p2p_tensor_shapes, | ||
| set_p2p_tensor_dtype, | ||
| ) | ||
| from dualpipe.utils import WeightGradStore | ||
|
|
||
| __all__ = [ | ||
| DualPipe, | ||
| DualPipeV, | ||
| WeightGradStore, | ||
| set_p2p_tensor_shapes, | ||
| set_p2p_tensor_dtype, | ||
| ] | ||
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,38 @@ | ||
| from typing import List, Tuple | ||
|
|
||
| import torch | ||
| import torch.distributed as dist | ||
|
|
||
|
|
||
| TENSOR_SHAPES: List[Tuple[int]] = None | ||
| TENSOR_DTYPE: torch.dtype = None | ||
|
|
||
|
|
||
| def set_p2p_tensor_shapes(shapes: List[Tuple[int]]): | ||
| global TENSOR_SHAPES | ||
| TENSOR_SHAPES = shapes | ||
|
|
||
|
|
||
| def set_p2p_tensor_dtype(dtype: torch.dtype): | ||
| global TENSOR_DTYPE | ||
| TENSOR_DTYPE = dtype | ||
|
|
||
|
|
||
| def build_from_tensor_shapes(): | ||
| return [torch.empty(s, dtype=TENSOR_DTYPE, device="cuda", requires_grad=True) for s in TENSOR_SHAPES] | ||
|
|
||
|
|
||
| def append_irecv(ops: List[dist.P2POp], src: int, group: dist.ProcessGroup) -> List[torch.Tensor]: | ||
| tensors = build_from_tensor_shapes() | ||
| src = dist.distributed_c10d.get_global_rank(group, src) | ||
| for tensor in tensors: | ||
| if tensor is not None: | ||
| ops.append(dist.P2POp(dist.irecv, tensor, src)) | ||
| return tensors | ||
|
|
||
|
|
||
| def append_isend(ops: List[dist.P2POp], tensors: List[torch.Tensor], dst: int, group: dist.ProcessGroup) -> None: | ||
| dst = dist.distributed_c10d.get_global_rank(group, dst) | ||
| for tensor in tensors: | ||
| if tensor is not None: | ||
| ops.append(dist.P2POp(dist.isend, tensor, dst)) |
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.
There are dualpipe codes, no need to be included.
In the README.md, explain how to clone the dualpipe codes, setup PYTHONPATH.