Skip to content

fix(megatron): make the NCCL collective timeout configurable - #4481

Merged
terrykong merged 3 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/megatron-dist-timeout
Oct 17, 2026
Merged

terrykong merged 3 commits into
NVIDIA-NeMo:mainfrom
linj-glitch:linj/megatron-dist-timeout

Conversation

@linj-glitch

@linj-glitch linj-glitch commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds megatron_cfg.distributed_timeout_minutes so slow checkpoint I/O can use a longer collective timeout. A reported 128-rank GRPO run spent 10m19s writing one shard; waiting ranks hit Timeout(ms)=600000, leaving the checkpoint without .metadata. Both default and model-parallel groups timed out.

The setting reaches the default NCCL group, Bridge's training TP/PP/DP/CP/EP groups, and the policy/value replica groups used for data-plane broadcasts. Positive fractional minutes are supported; zero and negative values fail with a worker-neutral error. Omitted or null preserves the current 10-minute NCCL/Bridge defaults.

Set the value in every Megatron worker config. PPO needs both:

policy:
  megatron_cfg:
    distributed_timeout_minutes: 30
value:
  megatron_cfg:
    distributed_timeout_minutes: 30

Exemplars and matching reference configs now document the null default. Tests cover default-group and Bridge forwarding, explicit None, fractional values, invalid values, both replica workers, and cached-group reuse. Shared test helpers are module-level functions.

Verified against Bridge ec835530 and LM b4d72b79: Bridge skips an existing default group and explicitly forwards the timeout to training groups; torch 2.13.0 new_group(timeout=None) uses the backend default, so replica groups need explicit forwarding too. The temporary groups created during first-run HF→Megatron import still use LM's 30-minute signature default.

Validation

  • 15 repository config/reference tests passed in a CPU run using --noconftest to bypass Ray session fixtures.
  • Pinned pre-commit lint/format hooks and configured pyrefly gate passed. The recipe-minimization checker passed separately with installed dependencies after its isolated script resolver failed DNS.
  • 19 supplemental CPU source-contract cases passed using extracted real function bodies and torch spies; the before-SHA regression control failed on the corrected error/config/replica behavior. These are not native Megatron integration tests.
  • 22 targeted mcore tests collect. Native execution remains pending: this environment cannot directly import Megatron/Bridge/TransformerEngine. No current multi-rank GPU run was performed.

The native Megatron unit lane must run the selected tests before merge validation is complete. The separate AutoModel/DTensor timeout follow-up is already tracked in #3624; this PR changes Megatron workers only. Related: #2229 and #2390.

@copy-pr-bot

copy-pr-bot Bot commented Oct 5, 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.

@linj-glitch
linj-glitch marked this pull request as draft October 5, 2026 06:10
@linj-glitch
linj-glitch force-pushed the linj/megatron-dist-timeout branch from f78a682 to 4b7fff4 Compare October 8, 2026 00:15
@linj-glitch
linj-glitch marked this pull request as ready for review October 13, 2026 05:02
The Megatron policy and value workers create the default process group with
`torch.distributed.init_process_group("nccl")`, and Megatron Bridge builds the
model-parallel groups with `DistributedInitConfig.distributed_timeout_minutes`
left at its default. Both are 10 minutes, and there is no config knob for either.

Dist-checkpoint save finalize and load run collectives across every rank, so a
single rank that is slow on I/O takes the whole job down. Example: a 128-rank
GRPO job with async checkpointing on a slow shared filesystem; one rank needed
10m19s to write its shard, the save-finalize collective hit the 10-minute NCCL
watchdog, and the checkpoint directory was left without its `.metadata` file.
Resuming from the previous checkpoint then timed out the same way in the load
collective and the job hung.

Add `policy.megatron_cfg.distributed_timeout_minutes` (NotRequired; omitted or
None keeps today's defaults). When set, it is passed to `init_process_group`
in `setup_distributed` (used by both the Megatron policy and value workers) and
to Bridge's `DistributedInitConfig`, which Bridge uses for the model-parallel
groups it creates. Bridge skips its own `init_process_group` because the group
already exists, so the default group's timeout has to be set by NeMo RL.
Non-positive values are rejected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Lin Jia <[email protected]>
@linj-glitch

Copy link
Copy Markdown
Contributor Author

/ok to test ab1d065

@terrykong
terrykong requested a review from macandro96 October 15, 2026 05:33

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this! The PR description is clear: it shows the real 128-rank failure, walks the upstream call chain line by line, and the tests cover both groups. The chain holds against the pins: setup_distributed sets the default group, and _create_megatron_config → Bridge initialize_megatron → initialize_model_parallel covers every TP/PP/DP/CP/EP group, gloo included. Fractional minutes are safe too: Megatron only uses the value in timedelta(minutes=...).

No correctness bugs. The inline comments are all small.

Before merge: CI hasn't run on this head yet. The 10 mcore tests need the Megatron unit lane (L0_Unit_Tests_Megatron_*) to be green.

PR description nit (no code change): "the signature default of 30 at L637 never applies" isn't true on the first-run HF→Megatron import. community_import.py#L247 calls Bridge's model_provider.initialize_model_parallel(seed=0), which passes no timeout, so those short-lived groups get 30 min. It only matters for values above 30, but the sentence is worth fixing.

Follow-up (not this PR): the DTensor/Automodel path calls init_process_group(backend=backend) with no timeout, so it can hit the same 10-min watchdog on a slow checkpoint save. Worth a separate issue.

Visual explainer: https://terrykong.github.io/gh-pages-poc/terryk/pr-4481-nccl-timeout.html

Generated by Claude Code

Comment thread nemo_rl/models/megatron/setup.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
Comment thread nemo_rl/models/megatron/setup.py Resolved
Apply the configured collective timeout to policy and value replica groups.
Read the required Megatron config directly and use a worker-neutral error.
Document null defaults across exemplars and references, including both PPO
worker configs. Decouple distributed-config test helpers and cover explicit
None, fractional minutes, missing config, and replica group caching.

Signed-off-by: Lin Jia <[email protected]>
@terrykong
terrykong enabled auto-merge (squash) October 17, 2026 07:42
@terrykong terrykong added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Oct 17, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test b5baf26

@terrykong
terrykong merged commit 8338530 into NVIDIA-NeMo:main Oct 17, 2026
92 checks passed
alexandery-nvidia added a commit that referenced this pull request Oct 17, 2026
…failures-and-redispatch

main gained #4481, #4771, #4458, #4770, #4640, #4765, #4525 and #4670 since the
previous merge. #4640 (rubric-mean and fixed-baseline GenRM scoring) rewrote the
metric assertions in tests/unit/experience/test_rollouts.py that this branch also
edits for nemo_gym_infra_redispatches: the resolution keeps main's per-key
assertions and adds the redispatch count beside them, and the expected
rollout_metrics dict carries both sides' new keys. test_rollouts.py,
test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 17, 2026
…andery/gym-health-check-during-collection

Carries the stack root's merge of main (8338530: #4481, #4771, #4458, #4770,
#4640, #4765, #4525 and #4670) forward so this head stays current with main.
No conflicts; test_rollouts.py, test_rollout_manager.py and test_nemo_gym.py
pass locally on the merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
alexandery-nvidia added a commit that referenced this pull request Oct 17, 2026
…xandery/gym-rollout-metrics-hook

Carries the stack's merge of main (8338530: #4481, #4771, #4458, #4770, #4640,
#4765, #4525 and #4670) forward. #4640 (rubric-mean and fixed-baseline GenRM
scoring) reports the shared GenRM fields once per group through
_nemo_gym_group_metrics and skips them in both per-agent loops, which this
branch had replaced with per_agent_result_metrics: the resolution keeps the
helper on both paths and adds the same _SHARED_GENRM_METRICS skip inside it,
so the manager no longer imports the constant. test_rollouts.py,
test_rollout_manager.py and test_nemo_gym.py pass locally on the merged tree.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: alexandery <[email protected]>
linmuchuiyang added a commit to linmuchuiyang/RL that referenced this pull request Oct 23, 2026
Add policy.automodel_cfg.distributed_timeout_minutes (and value.automodel_cfg for PPO), the
Automodel-path counterpart of megatron_cfg.distributed_timeout_minutes (NVIDIA-NeMo#4481). setup_distributed
passes timeout=datetime.timedelta(minutes=...) to torch.distributed.init_process_group, so the
default group and the FSDP2 / expert-parallel groups derived from it use the configured collective
timeout instead of torch's 10-minute NCCL default. Unset keeps the default; non-positive values are
rejected with the same message pattern as NVIDIA-NeMo#4481.

On the Automodel/DTensor path the first training step JIT-compiles kernels (HybridEP / DeepEP,
TileLang) and loads large MoE checkpoints; on cold nodes that keeps ranks apart for more than
10 minutes, and until now the only remedy was patching setup.py.

Signed-off-by: linmuchuiyang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants