Why one slow checkpoint rank kills a Megatron job, and the timeout setting that fixes it

Explainer for NVIDIA-NeMo/RL #4481 (related: #2229). All permalinks pin the PR head ab1d065.

Before
Every NCCL group in a Megatron worker waited at most 10 minutes for a slow rank. There was no way to raise it.
This PR
Adds megatron_cfg.distributed_timeout_minutes and applies it to the default group and to every Megatron model-parallel group.
Status
Fixed by this PR for the checkpoint save and load path. Leaving the setting out keeps today's behavior.
Background. GPUs talk through NCCL process groups. In a collective, every rank in the group must arrive before anyone can leave. A watchdog kills the process if a collective takes longer than the group's timeout. For NCCL, torch's default is 10 minutes. Saving a distributed checkpoint ends with a collective, so all ranks wait there for the slowest writer. Dotted words have a short explanation: hover or tap them.

NeMo RL creates the default group itself in setup_distributed, with no timeout, so it gets 10 minutes. Megatron Bridge then sees that group already exists and skips its own setup, which was the only place its timeout setting reached the default group. It still builds the tensor/pipeline/data-parallel groups, and passes them distributed_timeout_minutes, which NeMo RL never set, so they also got 10 minutes.

What times out

A small version of the reported failure (it really happened on 128 ranks): 4 ranks save a checkpoint. Rank 2 sits on a slow shared filesystem and needs 13 minutes to write its piece.

One checkpoint save, 4 ranks โ€” where each rank spends its time 0 4 10 13 30 minutes rank 0 rank 1 rank 2 writing its shard (slow disk) rank 3 waiting in the final all-gather โœ“ 13 min: all arrived writing slow writer blocked in a collective before: 10 min โ†’ watchdog kills the job after, set to 30 โ†’ save completes

Before the PR, ranks 0, 1 and 3 hit the 10-minute watchdog while rank 2 is still writing. The job dies, the checkpoint folder never gets its .metadata file, and resuming from the previous checkpoint times out the same way during load. With distributed_timeout_minutes: 30 the same save finishes at minute 13.

How the PR raises the limit

Where the fix lands: RL only, one function changed and one helper added, both in setup.py, plus the documented key in MegatronConfig. No Megatron Bridge change: Bridge already forwards the field to every model-parallel group.

@@ setup.py L511-L521 ยท new helper _distributed_timeout_minutes
+def _distributed_timeout_minutes(config) -> Optional[float]:
+    """Return ``megatron_cfg.distributed_timeout_minutes``, or None when unset."""
+    timeout_minutes = (config.get("megatron_cfg") or {}).get(
+        "distributed_timeout_minutes"
+    )
+    if timeout_minutes is not None and timeout_minutes <= 0:
+        raise ValueError(
+            "policy.megatron_cfg.distributed_timeout_minutes must be positive, "
+            f"got {timeout_minutes}"
+        )
+    return timeout_minutes

@@ setup.py L532-L541 ยท setup_distributed โ€” the default group
     destroy_parallel_state()
-    # Initialize process group
-    torch.distributed.init_process_group("nccl")
+    # Initialize process group. Bridge skips its own init_process_group when one
+    # already exists, so the collective timeout of the default group (used by
+    # dist-checkpoint save finalize / load) has to be set here.
+    timeout_minutes = _distributed_timeout_minutes(config)
+    if timeout_minutes is None:
+        torch.distributed.init_process_group("nccl")
+    else:
+        torch.distributed.init_process_group(
+            "nccl", timeout=datetime.timedelta(minutes=timeout_minutes)
+        )

@@ setup.py L2131-L2136 ยท _create_megatron_config โ€” the model-parallel groups
     dist_cfg = DistributedInitConfig()
+    timeout_minutes = _distributed_timeout_minutes(config)
+    if timeout_minutes is not None:
+        dist_cfg.distributed_timeout_minutes = timeout_minutes

Each piece, in order:

  1. One helper reads and checks the value, so both groups always get the same number.
  2. setup_distributed passes it to the default group. Both the Megatron policy worker and the Megatron value worker go through here.
  3. _create_megatron_config puts it on Bridge's config. Bridge hands it to Megatron-LM, which turns it into timedelta(minutes=...) for every TP/PP/DP/CP/EP group. A fraction like 2.5 is fine: that is the only place the number is used.

Usage, in the policy's megatron_cfg (in PPO, set it in the value's megatron_cfg too):

policy:
  megatron_cfg:
    distributed_timeout_minutes: 30   # leave it out to keep the 10-minute default

๐ŸŸก review comment โ€” policy/__init__.py:509

So what. Jobs that save to a slow shared filesystem can now survive a straggler rank instead of losing the checkpoint and the run. Nothing changes unless you set the key. One small gap remains: the data-plane replica groups are built with no timeout and stay at 10 minutes. They are not used while saving or loading, so they did not cause this failure; the review asks to pass the same timeout there for consistency.

๐ŸŸก review comment โ€” setup.py:535