-
Notifications
You must be signed in to change notification settings - Fork 565
Enables specified cp rank slicing #2387
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |||||||||||||||||
|
|
||||||||||||||||||
| """Context Parallelism.""" | ||||||||||||||||||
| import os | ||||||||||||||||||
| from typing import List, Union, Tuple | ||||||||||||||||||
| from typing import List, Union, Optional, Tuple | ||||||||||||||||||
| import torch | ||||||||||||||||||
| import transformer_engine_torch as tex | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -4016,7 +4016,8 @@ def get_batch_on_this_cp_rank( | |||||||||||||||||
| input_ids_padded: torch.Tensor, | ||||||||||||||||||
| labels_padded: torch.Tensor, | ||||||||||||||||||
| position_ids_padded: torch.Tensor, | ||||||||||||||||||
| cp_group: torch.distributed.ProcessGroup = None, | ||||||||||||||||||
| cp_size: Optional[int] = None, | ||||||||||||||||||
| cp_rank: Optional[int] = None, | ||||||||||||||||||
| qvk_format: str = "thd", | ||||||||||||||||||
| ): | ||||||||||||||||||
| """Slice batch input along sequence dimension into multiple chunks for THD format. | ||||||||||||||||||
|
|
@@ -4026,14 +4027,18 @@ def get_batch_on_this_cp_rank( | |||||||||||||||||
|
|
||||||||||||||||||
| Which are parallelized across GPUs in a context parallel group. | ||||||||||||||||||
| This version works with variable-length sequences using cumulative sequence lengths. | ||||||||||||||||||
|
|
||||||||||||||||||
| If cp_rank is provided, it will slice the batch for the provided rank. | ||||||||||||||||||
|
Contributor
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. could you put this next to cp_group in the input list? Also, I think the better docstring would be
but maybe the better option would be to have a
Contributor
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. I put it next to The functional already takes in a
Contributor
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. If its for context parallel I expect the user to already have their distributed process groups setup right? |
||||||||||||||||||
| """ | ||||||||||||||||||
| if qvk_format not in ["thd", "bshd", "sbhd"]: | ||||||||||||||||||
| raise ValueError(f"Unsupported qvk_format: {qvk_format}!") | ||||||||||||||||||
| if qvk_format == "thd": | ||||||||||||||||||
| # Get context parallel size and rank | ||||||||||||||||||
| cp_size = torch.distributed.get_world_size(group=cp_group) | ||||||||||||||||||
| if cp_size > 1: | ||||||||||||||||||
|
Contributor
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. logic: will fail with TypeError if
Suggested change
|
||||||||||||||||||
| cp_rank = torch.distributed.get_rank(group=cp_group) | ||||||||||||||||||
| if not (0 <= cp_rank < cp_size): | ||||||||||||||||||
| raise ValueError(f"cp_rank must be in [0, {cp_size}), but received {cp_rank}.") | ||||||||||||||||||
| if cp_rank is None: | ||||||||||||||||||
| raise ValueError("cp_rank must be provided when cp_size > 1.") | ||||||||||||||||||
|
Comment on lines
+4038
to
+4041
Contributor
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. logic: validation checks are in wrong order - will fail when Line 4038 checks range before line 4040 checks for
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| # Calculate the chunk sizes for each sequence | ||||||||||||||||||
| total_slices_of_any_sequence = 2 * cp_size | ||||||||||||||||||
|
|
||||||||||||||||||
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.
logic: breaking change - removed backward compatibility with
cp_groupparameterOld signature had
cp_group: torch.distributed.ProcessGroup = Noneand would calltorch.distributed.get_world_size(group=cp_group)andtorch.distributed.get_rank(group=cp_group)as fallback. New code removes this entirely, breaking existing callers. Either restore fallback logic or update PR description to mark as breaking change.