Skip to content

fix: make nccl_reshard_refit_info wire-safe for the generation-worker. - #3618

Merged
terrykong merged 3 commits into
mainfrom
youngeunk/nccl-reshard-wire-safe
Aug 14, 2026
Merged

terrykong merged 3 commits into
mainfrom
youngeunk/nccl-reshard-wire-safe

Conversation

@youngeunkwon0405

Copy link
Copy Markdown
Contributor

I am separating PR #3532 into two. Wire-safe part and the MTP gating part.

What does this PR do ?

Make the nccl_reshard_refit_info object wire-safe before sending it to the generation worker during initialization.
nccl_reshard_refit_info contains torch tensors, created by Megatron. The problem is that Megatron replaces the
torch.storage._load_from_bytes function that is required for unpickling to a Megatron-specific function.
So, during unpickling from the generation worker, it will call import megatron which will cause an import error.
This PR fixes that issue.

Add a one line overview of what this PR aims to accomplish.

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

@youngeunkwon0405
youngeunkwon0405 requested review from a team as code owners August 13, 2026 00:13
@copy-pr-bot

copy-pr-bot Bot commented Aug 13, 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.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 13, 2026
@youngeunkwon0405 youngeunkwon0405 self-assigned this Aug 13, 2026
@youngeunkwon0405 youngeunkwon0405 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Aug 13, 2026
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test e0c8961

@youngeunkwon0405 youngeunkwon0405 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Team review: 4 agents (RL expert, test reviewer, bug finder, devil's advocate) + lead; findings independently re-verified before posting.

The fix is correct and necessary — verified empirically. The devil's advocate reproduced the failure end-to-end on CPU: with torch.storage._load_from_bytes patched the way the pinned megatron-core does (megatron/core/init.py @ d12f6c8c, torch.storage._load_from_bytes = safe_load_from_bytes), the raw refit-info pickle references megatron.core.safe_globals.safe_load_from_bytes and cannot unpickle without megatron, while the wire-safe form unpickles and restores exactly. The converter was further verified for MoE+EP+PP round-trip fidelity, idempotency in both directions, and non-mutation of the caller's dict. All 50 unit tests in the touched file pass on a CPU-only environment.

4 inline comments, none above low severity: a fail-loud suggestion in the wire helpers, a narrow teardown race + a hang risk around the new shutdown() wiring (which otherwise closes a real gap), and two test-strengthening suggestions. Linter (ruff check + format): clean.

Generated by Claude Code

Comment thread nemo_rl/algorithms/single_controller.py Resolved
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test 234e68b

youngeunkwon0405 and others added 2 commits August 13, 2026 10:23
… RPC

nccl_reshard_refit_info holds MeshInfo rank tensors created under
Megatron. megatron.core replaces torch.storage._load_from_bytes with
its own loader at import time, so pickled tensors require
`import megatron` at unpickle time — which fails inside vLLM
subprocesses. Convert meshes and Shard/Replicate placements to plain
dicts/lists (make_nccl_reshard_refit_info_wire_safe) before the Ray
hop; the vLLM worker rebuilds them via restore_refit_info_placements.

Also shut the weight synchronizer down at the end of the
single-controller run loop (guarded so teardown errors cannot mask a
training failure) and drop the synchronizer's generation handle on
shutdown to break the reference cycle.

Adds pure-CPU round-trip tests: no tensors on the wire, input not
mutated, restore reproduces placements/meshes exactly.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
Mimic megatron-core's torch.storage._load_from_bytes patch with a dummy
module and assert the raw refit info pickle references it while the
wire-safe form does not — the exact invariant the conversion exists to
guarantee, which a plain pickle round-trip in an unpatched test process
cannot detect.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Youngeun Kwon <[email protected]>
@youngeunkwon0405
youngeunkwon0405 force-pushed the youngeunk/nccl-reshard-wire-safe branch from 234e68b to a103e75 Compare August 13, 2026 17:26
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test a103e75

@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.

Team review: 5 agents + 3 independent adversarial passes.

The fix is correct and complete. Re-verified independently: megatron-core does patch the storage unpickler at import (megatron/core/__init__.py:58), so the premise is real; the only tensor-bearing values are MeshInfo.mesh under per_layer_params (misc_meta is shape/dtype scalars), so the shallow copy misses nothing; the encodings match restore_refit_info_placements exactly and int64 round-trips through tolist(). Reusing the encoding vLLM's msgspec already emits, so the decoder needed zero changes, is a good call.

2 inline comments, both low severity — test-coverage gaps only. Nothing blocking.

Eight other candidates were dropped after adversarial challenge, including two that looked strong at first: a claimed double-shutdown() (refuted — VllmGeneration.weight_synchronizer is None on this path, so the two call sites are mutually exclusive) and a claimed stale-msgspec-docstring contradiction (refuted — the sync and async engines take different transports, so the existing msgspec docstrings and this PR's pickle premise are both true).

One low-severity follow-up, not worth reopening a resolved thread: CheckpointEngineWeightSynchronizer.shutdown() does an untimed ray.get, and this PR is what first puts it on the single-controller failure path where workers may be wedged; a hang there is not caught by except Exception. A bounded ray.get(..., timeout=...) would be worth a separate issue.

Caveat: no tests or linters were run for this review — the environment is macOS and uv.lock supports linux only. Both test suggestions are unverified.

Generated by Claude Code

Comment thread nemo_rl/algorithms/single_controller.py Resolved
Signed-off-by: Youngeun Kwon <[email protected]>
@youngeunkwon0405

Copy link
Copy Markdown
Contributor Author

/ok to test ddab4e8

@terrykong
terrykong enabled auto-merge (squash) August 13, 2026 23:56
@terrykong
terrykong merged commit 679af42 into main Aug 14, 2026
82 checks passed
@terrykong
terrykong deleted the youngeunk/nccl-reshard-wire-safe branch August 14, 2026 04:19
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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants