Skip to content

[fix] Cleanup usage of pg_collection in gtp - #6234

Merged
fanshiqing merged 5 commits into
NVIDIA:mainfrom
fanshiqing:shiqingf/gtp_refine_usage_of_pg_collection
Aug 5, 2026
Merged

[fix] Cleanup usage of pg_collection in gtp#6234
fanshiqing merged 5 commits into
NVIDIA:mainfrom
fanshiqing:shiqingf/gtp_refine_usage_of_pg_collection

Conversation

@fanshiqing

@fanshiqing fanshiqing commented Aug 4, 2026

Copy link
Copy Markdown
Member
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Refine usage of pg_collection in gtp, which is a planned following up tiny task of #4967

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Signed-off-by: Shiqing Fan <shiqingf@nvidia.com>
@fanshiqing
fanshiqing requested review from a team as code owners August 4, 2026 03:03
@copy-pr-bot

copy-pr-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 4, 2026 03:04
@fanshiqing fanshiqing self-assigned this Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@fanshiqing fanshiqing changed the title Refine usage of pg_collection in gtp [GTP] Refine usage of pg_collection in gtp Aug 4, 2026
@fanshiqing
fanshiqing marked this pull request as ready for review August 4, 2026 03:13
@fanshiqing

Copy link
Copy Markdown
Member Author

/ok to test 4e87571

Comment thread megatron/core/extensions/transformer_engine.py
Comment thread megatron/core/tensor_parallel/layers.py
Comment thread megatron/core/distributed/finalize_model_grads.py
- Thread pg_collection from TransformerLayer through Attention/MLP into the TE
  and core linear layers.
- Assert in finalize_model_grads when the config enables the axis but the group
  is missing, instead of treating it as "GTP inactive" and training on wrong
  gradients.
- Add test_gtp_custom_pgs.py: two TransformerBlocks, identical degrees
  (TP=1, CP=1, GTP_remat=2 over world=4), identical weights and input, one from
  the MPU groups and one from a custom collection with permuted gtp_remat rank
  membership. Output and gradients must match; verified it fails without the
  plumbing.

Signed-off-by: Shiqing Fan <shiqingf@nvidia.com>
@fanshiqing
fanshiqing requested review from a team as code owners August 4, 2026 04:40
@fanshiqing

Copy link
Copy Markdown
Member Author

/ok to test 2c47a2e

@fanshiqing
fanshiqing force-pushed the shiqingf/gtp_refine_usage_of_pg_collection branch from a3943e3 to 07b0066 Compare August 5, 2026 02:44
@fanshiqing

Copy link
Copy Markdown
Member Author

/ok to test 07b0066

Signed-off-by: ykarnati <ykarnati@nvidia.com>
@fanshiqing
fanshiqing force-pushed the shiqingf/gtp_refine_usage_of_pg_collection branch from 07b0066 to 382835b Compare August 5, 2026 02:49
@fanshiqing

Copy link
Copy Markdown
Member Author

/ok to test 382835b

Comment thread megatron/core/pipeline_parallel/schedules.py
Comment thread megatron/core/pipeline_parallel/schedules.py
@Phlip79

Phlip79 commented Aug 5, 2026

Copy link
Copy Markdown
Member

/claude strict-review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict review passed — no significant issues found. LGTM

Reviewed as a pg_collection plumbing refactor for GTP-backed layers. Verified:

  • Correctness: resolve_gtp_remat_group correctly uses vars() not hasattr (dataclass __getattr__ returns None for unset fields, so hasattr would always be True and defeat the MPU fallback) — covered by the fall-back test. The new fail-loud assertion in finalize_model_grads turns a silent wrong-gradient skip into a hard error when *_remat_size > 1 but the group is missing/mismatched.
  • Backward compat: all new pg_collection args are optional and MPU-fallback preserves pre-pg_collection callers; the default training path stays safe because _build_default_pg_collection now populates the gtp_remat fields; the one internal signature change (_allreduce_replicated_grads_over_gtp_remat_group) has both callers updated.
  • Unused-arg check: every added pg_collection parameter has a real use path (resolve or downstream propagation); the new gtp_remat_rank/egtp_remat_rank seed args are wired and defaulted.
  • Cleanup: removed HAVE_GTP import and MEGATRON_GTP_FORCE_ENABLE env sets are confirmed dead across the tree.
  • Process-group guidance: the direct parallel_state.get_*_group() reads are confined to the existing MPU-fallback branch — a documented compatibility point.

Strong new test coverage: the permuted-pairing custom-group test precisely targets the silent 'module reads global groups instead of the passed collection' failure this refactor prevents.

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yashaswikarnati when are we getting rid of all of this fallback code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not only for GTP, but everywhere. It's an eyesore :P

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/31029975296

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/31034228133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: medium nemotron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants