-
Notifications
You must be signed in to change notification settings - Fork 4.4k
[fix] Cleanup usage of pg_collection in gtp #6234
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
fanshiqing
merged 5 commits into
NVIDIA:main
from
fanshiqing:shiqingf/gtp_refine_usage_of_pg_collection
Aug 5, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4e87571
Refine usage of pg_collection in gtp
fanshiqing 2c47a2e
Pass gtp_remat process groups through pg_collection
fanshiqing a6fffab
fix lint format
fanshiqing 7d26dc7
Fix gtp_remat resolution for partial pg_collections
fanshiqing 382835b
Pass process groups to remaining GTP-backed layers (#6262)
yashaswikarnati 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 |
|---|---|---|
|
|
@@ -492,7 +492,10 @@ def _allreduce_non_tensor_model_parallel_grads( | |
|
|
||
|
|
||
| def _allreduce_replicated_grads_over_gtp_remat_group( | ||
| model: List[torch.nn.Module], calculate_per_token_loss: bool = False | ||
| model: List[torch.nn.Module], | ||
| gtp_remat_group: Optional[torch.distributed.ProcessGroup], | ||
| egtp_remat_group: Optional[torch.distributed.ProcessGroup], | ||
| calculate_per_token_loss: bool = False, | ||
| ): | ||
| """Complete the gtp_remat / egtp_remat axis reduction for replicated parameters. | ||
|
|
||
|
|
@@ -510,12 +513,6 @@ def _allreduce_replicated_grads_over_gtp_remat_group( | |
|
|
||
| No-op when GTP_remat is inactive (group size <= 1). | ||
| """ | ||
| pg_collection = ProcessGroupCollection.use_mpu_process_groups( | ||
| required_pgs=["gtp_remat", "expt_gtp_remat"] | ||
| ) | ||
| gtp_remat_group = pg_collection.gtp_remat | ||
| egtp_remat_group = pg_collection.expt_gtp_remat | ||
|
|
||
| dense_active = gtp_remat_group is not None and gtp_remat_group.size() > 1 | ||
| expert_active = egtp_remat_group is not None and egtp_remat_group.size() > 1 | ||
| if not dense_active and not expert_active: | ||
|
|
@@ -604,12 +601,29 @@ def finalize_model_grads( | |
| # Full DP x CP x gtp_remat group: num_tokens (the per-token-loss divisor below) counts the | ||
| # gtp_remat peers' distinct tokens. Falls back to replicate dp_cp when gtp is inactive. | ||
| dp_cp_group = getattr(pg_collection, 'dp_cp_gtp_remat', None) or pg_collection.dp_cp | ||
| gtp_remat_group = getattr(pg_collection, 'gtp_remat', None) | ||
| egtp_remat_group = getattr(pg_collection, 'expt_gtp_remat', None) | ||
| else: | ||
| tp_group = parallel_state.get_tensor_model_parallel_group() | ||
| pp_group = parallel_state.get_pipeline_model_parallel_group() | ||
| embd_group = parallel_state.get_embedding_group(check_initialized=False) | ||
| pos_emb_group = parallel_state.get_position_embedding_group(check_initialized=False) | ||
| dp_cp_group = parallel_state.get_data_parallel_group(with_context_parallel=True) | ||
| gtp_remat_group = parallel_state.get_gtp_weight_remat_group(check_initialized=False) | ||
|
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. @yashaswikarnati when are we getting rid of all of this fallback code?
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. Not only for GTP, but everywhere. It's an eyesore :P |
||
| egtp_remat_group = parallel_state.get_expert_gtp_weight_remat_group(check_initialized=False) | ||
|
|
||
| # A missing group would silently skip the gtp_remat-axis reduction below and train on | ||
| # wrong gradients, so fail loudly whenever the config says the axis is active. | ||
| for axis, group, axis_size in ( | ||
| ('gtp_remat', gtp_remat_group, config.gtp_weight_remat_size), | ||
| ('expt_gtp_remat', egtp_remat_group, config.expert_gtp_weight_remat_size), | ||
| ): | ||
| if axis_size > 1: | ||
| found = 'None' if group is None else f'a size-{group.size()} group' | ||
| assert group is not None and group.size() == axis_size, ( | ||
| f"{axis} is enabled (size={axis_size}) but pg_collection provides {found}. " | ||
| f"Pass a pg_collection carrying `{axis}` to finalize_model_grads." | ||
| ) | ||
|
|
||
| # Fence the current stream against all GTP backward grad work before the DP gradient sync. | ||
| if config.gtp_weight_remat_size > 1 or config.expert_gtp_weight_remat_size > 1: | ||
|
|
@@ -646,7 +660,10 @@ def finalize_model_grads( | |
| ) | ||
| _allreduce_non_tensor_model_parallel_grads(model, config, tp_group) | ||
| _allreduce_replicated_grads_over_gtp_remat_group( | ||
| model, calculate_per_token_loss=config.calculate_per_token_loss | ||
| model, | ||
| gtp_remat_group, | ||
| egtp_remat_group, | ||
| calculate_per_token_loss=config.calculate_per_token_loss, | ||
| ) | ||
| if config.timers is not None: | ||
| config.timers('non-tensor-parallel-grads-all-reduce').stop() | ||
|
|
||
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
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
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.