Skip to content

Initialize default process group when loading torch_dist checkpoints - #6787

Draft
pujitha24 wants to merge 1 commit into
NVIDIA:mainfrom
pujitha24:auto/issue-1818
Draft

Initialize default process group when loading torch_dist checkpoints#6787
pujitha24 wants to merge 1 commit into
NVIDIA:mainfrom
pujitha24:auto/issue-1818

Conversation

@pujitha24

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

What does this PR do?

Initializes a single-process default torch.distributed process group in the checkpoint conversion loader so tools/checkpoint/convert.py can load torch_dist checkpoints without a ValueError: Default process group has not been initialized crash.

CI on this repo requires a maintainer to add ok-to-test — happy to address anything it surfaces.

Note: I could not execute the new unit test end-to-end in my local sandbox (macOS, no GPU/Docker), because importing megatron.core/megatron.training transitively requires triton, which has no macOS wheel. I validated the underlying mechanism directly (installing a CPU-only torch build and reproducing the exact torch.distributed.get_world_size() ValueError before the fix, then confirming init_process_group(backend='gloo', rank=0, world_size=1) resolves it), and confirmed via git log that this exact fix pattern is already merged and working for the checkpoint saver path (tools/checkpoint/saver_base.py, added in commit a3a7a0c "fix checkpointing conversion", #4058) — the loader path never received the equivalent fix. CI is the first environment that can actually execute the new pytest file.

Issue tracking

Linked issue:
Report: #1818

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

Code review

Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.

Step 1: Mark PR as "Ready for Review"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

Step 2: Final Review

For PRs that change megatron/core, once all expert reviewers have approved, the Final Review label is applied automatically and final reviewers are assigned.

For PRs outside megatron/core, this step is skipped.

Step 3: Approved

Once all required reviewers have approved, the Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

Fixes #1818

Motivation:
tools/checkpoint/convert.py fails with "ValueError: Default process
group has not been initialized" when loading torch_dist checkpoints
saved with --use-dist-ckpt. dist_checkpointing.load calls
torch.distributed.get_world_size() (via determine_global_metadata),
but MegatronCheckpointLoaderBase.initialize_megatron_env never calls
torch.distributed.init_process_group, so no default process group
exists.

The equivalent checkpoint saver path (saver_base.py) already guards
against this with a single-process gloo process group, added for the
save direction in a prior fix, but the loader path never received the
same fix.

Approach:
Mirror saver_base.py's existing pattern in
MegatronCheckpointLoaderBase.initialize_megatron_env: if no default
process group exists, initialize a minimal single-process gloo
backend (rank=0, world_size=1) before the mpu fake-parallelism setup.
convert.py always runs the loader as a single process (via
multiprocessing, never torchrun), so this cannot conflict with a real
multi-rank launch.

Validation:
Added tests/unit_tests/tools/checkpoint/test_loader_base.py, which
calls initialize_megatron_env directly and asserts a default process
group is available afterward (skipped under this repo's multi-rank
CI harness, matching the existing guard in
test_gpt_hybrid_conversion_parallelism.py, since that harness already
provides its own multi-rank default group).

I could not execute this new pytest file end-to-end in my local
sandbox (macOS, no GPU/Docker): importing megatron.core/megatron.training
transitively requires triton, which has no macOS wheel. I did directly
validate the underlying mechanism: installed a CPU-only torch build
and reproduced the exact "torch.distributed.get_world_size()"
ValueError prior to any init_process_group call, then confirmed
torch.distributed.init_process_group(backend='gloo', rank=0,
world_size=1) resolves it -- the same call this change adds. I also
confirmed via git history that this identical pattern is already
merged and working for the saver side. CI is the first environment
that can run the new test end-to-end.

Report: NVIDIA#1818
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5 (via Claude Code)
@copy-pr-bot

copy-pr-bot Bot commented Aug 23, 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 23, 2026 22:45
@github-actions

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] convert.py fails with ValueError: Default process group has not been initialized

1 participant