Skip to content

fix(refit): release trainer memory before collective export - #3984

Merged
yuki-97 merged 29 commits into
NVIDIA-NeMo:mainfrom
seonjinn:fix/qwen35-mxfp8-refit-memory-20260903
Oct 13, 2026
Merged

yuki-97 merged 29 commits into
NVIDIA-NeMo:mainfrom
seonjinn:fix/qwen35-mxfp8-refit-memory-20260903

Conversation

@seonjinn

@seonjinn seonjinn commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Release policy training memory before non-colocated refit.

One policy-level option now controls the same lifecycle for vLLM collective, vLLM NCCL Reshard, and Megatron-generation refit. This prevents large exports from competing with completed gradients, optimizer state, and Transformer Engine caches.

Usage

policy:
  offload_policy_before_refit: true
  offload_optimizer_for_refit: true
  megatron_cfg:
    fp8_cfg:
      enabled: true
      force_clear_fp8_caches: true
  generation:
    colocated:
      enabled: false

The option defaults to false. It requires a Megatron policy and non-colocated vLLM or Megatron generation.

Changes

  • Use one policy-level option across collective, NCCL Reshard, and MCore refit.
  • Support GRPO, distillation, and PPO.
  • Keep optimizer offload separately configurable.
  • Reject unsupported colocated, backend, and transport combinations during setup.
  • Add required defaults to complete example configs and focused validation, propagation, and ordering tests.

Validation

  • Ruff, formatting, targeted Pyrefly, compile, and diff checks pass.
  • GitHub lint passes on 207f9c385; the full test matrix is running.

@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Sep 3, 2026
@seonjinn
seonjinn requested a review from jepio September 3, 2026 21:31
@seonjinn
seonjinn marked this pull request as ready for review September 3, 2026 22:01
@seonjinn
seonjinn requested review from a team as code owners September 3, 2026 22:01
@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@seonjinn seonjinn changed the title fix(refit): avoid Qwen3.5 397B MXFP8 export OOM fix(refit): release trainer memory before collective export Sep 3, 2026
@seonjinn seonjinn added the CI:L1 Run doctests, unit tests, and functional tests label Sep 3, 2026
@seonjinn

seonjinn commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ca43e3d

@seonjinn

seonjinn commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 32b0467

…t-memory-20260903

Signed-off-by: seonjinn <[email protected]>

# Conflicts:
#	tests/unit/algorithms/test_distillation.py
@seonjinn

seonjinn commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1b592f7

@seonjinn

seonjinn commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 1e8e23f

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test a572960

hchings added a commit that referenced this pull request Sep 14, 2026
Backport #3984 (release_grads_before_refit) from
optimized's patches 0002 and 0006 (originally by seonjinn <[email protected]>),
then extend it to the trtllm generation backend: factory.py's
_SUPPORTED_BACKENDS and validate_release_grads_before_refit only allowed
vLLM. CollectiveWeightSynchronizer is backend-agnostic on the trainer
side and TrtllmGeneration already implements the generation-side
interface it needs, so trtllm just needed the gate relaxed.

Signed-off-by: Erin Ho <[email protected]>
hchings added a commit that referenced this pull request Sep 15, 2026
Backport #3984 (release_grads_before_refit) from
optimized's patches 0002 and 0006 (originally by seonjinn <[email protected]>),
then extend it to the trtllm generation backend: factory.py's
_SUPPORTED_BACKENDS and validate_release_grads_before_refit only allowed
vLLM. CollectiveWeightSynchronizer is backend-agnostic on the trainer
side and TrtllmGeneration already implements the generation-side
interface it needs, so trtllm just needed the gate relaxed.

Signed-off-by: Erin Ho <[email protected]>
Comment thread nemo_rl/weight_sync/factory.py Resolved
Signed-off-by: seonjinn <[email protected]>

# Conflicts:
#	nemo_rl/weight_sync/collective_weight_synchronizer.py
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test b4e342c

hchings added a commit that referenced this pull request Oct 6, 2026
Backport #3984 (release_grads_before_refit) from
optimized's patches 0002 and 0006 (originally by seonjinn <[email protected]>),
then extend it to the trtllm generation backend: factory.py's
_SUPPORTED_BACKENDS and validate_release_grads_before_refit only allowed
vLLM. CollectiveWeightSynchronizer is backend-agnostic on the trainer
side and TrtllmGeneration already implements the generation-side
interface it needs, so trtllm just needed the gate relaxed.

Signed-off-by: Erin Ho <[email protected]>
@seonjinn

seonjinn commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 73f4446

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

Scope: follow-up on 4a0aa78 and the test commits since 5586e40.

Checked:

  • Default behaviour is unchanged for every shipped recipe. The old nested key was false everywhere it was set, the new policy.offload_policy_before_refit is false in every exemplar, and offload_optimizer_for_refit resolves to true exactly as the old .get(..., True) did.
  • Legacy PPO with non-colocated vLLM now attaches a weight synchronizer when offload is on, and refit_policy_generation routes through it, so the flag is no longer dropped there.
  • Distillation's managed refit path skips the inline prepare_refit_info, which is fine because CollectiveWeightSynchronizer.init_communicator runs it.
  • GRPO, PPO and distillation all validate the topology at setup, before the policy or generation workers are built, so colocated and unsupported-transport combinations fail early.

Remaining comments are on the removed mcore_generation_config key, which has no startup rejection, and on the research template config, which is missing the two new required keys.

nit, not blocking merging — the title says "before collective export", but the PR now also covers nccl_reshard and Megatron-generation refit; something like fix(refit): offload policy before non-colocated refit would match the scope.

Comment thread nemo_rl/models/policy/__init__.py Resolved
@seonjinn

seonjinn commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 717da9b

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

Merge blockers — please rebase on main and resolve conflicts before further review.

Scope: fix commit 717da9b against the open threads from the previous pass, plus a scan of the changed files for new issues.

Checked:

  • The removed mcore_generation_config.offload_policy_before_refit key is now rejected at startup by reject_outdated_mcore_refit_offload_key, which runs before MasterConfig(**config) in every entry point including single_update.py; no shipped YAML nests the key under mcore_generation_config, so the check does not trip on in-tree recipes.
  • research/template_project/configs/grpo_math_1B.yaml now defines both required keys, so MasterConfig no longer fails with "Field required".
  • The rejection tests cover both true and false for the removed key, plus the policy-level key passing.

Remaining comments are on the new template_project config test.

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test c9fdef7

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

LGTM, thanks @seonjinn !

@yuki-97
yuki-97 merged commit f201e5b into NVIDIA-NeMo:main Oct 13, 2026
94 checks passed
avenkateshha added a commit that referenced this pull request Oct 15, 2026
Megatron worker setup reads offload_optimizer_for_refit without a
fallback since #3984 removed its `.get(..., True)` default. The CSD
example teachers never set the key: YAML lists are not merged from the
defaults file, so the student inherits it from distillation_math.yaml
while each teacher entry is written out in full. A CSD example teacher
switched to Megatron therefore fails with a KeyError during worker
setup.

Add offload_policy_before_refit and offload_optimizer_for_refit to each
teacher in csd.yaml and csd_multiteacher.yaml, matching the teacher
entries of the X-Token example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adithya Hanasoge <[email protected]>
avenkateshha added a commit that referenced this pull request Oct 16, 2026
Megatron worker setup reads offload_optimizer_for_refit without a
fallback since #3984 removed its `.get(..., True)` default. The CSD
example teachers never set the key: YAML lists are not merged from the
defaults file, so the student inherits it from distillation_math.yaml
while each teacher entry is written out in full. A CSD example teacher
switched to Megatron therefore fails with a KeyError during worker
setup.

Add offload_policy_before_refit and offload_optimizer_for_refit to each
teacher in csd.yaml and csd_multiteacher.yaml, matching the teacher
entries of the X-Token example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adithya Hanasoge <[email protected]>
avenkateshha added a commit that referenced this pull request Oct 19, 2026
Megatron worker setup reads offload_optimizer_for_refit without a
fallback since #3984 removed its `.get(..., True)` default. The CSD
example teachers never set the key: YAML lists are not merged from the
defaults file, so the student inherits it from distillation_math.yaml
while each teacher entry is written out in full. A CSD example teacher
switched to Megatron therefore fails with a KeyError during worker
setup.

Add offload_policy_before_refit and offload_optimizer_for_refit to each
teacher in csd.yaml and csd_multiteacher.yaml, matching the teacher
entries of the X-Token example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adithya Hanasoge <[email protected]>
yuki-97 pushed a commit that referenced this pull request Oct 21, 2026
avenkateshha added a commit that referenced this pull request Nov 3, 2026
Megatron worker setup reads offload_optimizer_for_refit without a
fallback since #3984 removed its `.get(..., True)` default. The CSD
example teachers never set the key: YAML lists are not merged from the
defaults file, so the student inherits it from distillation_math.yaml
while each teacher entry is written out in full. A CSD example teacher
switched to Megatron therefore fails with a KeyError during worker
setup.

Add offload_policy_before_refit and offload_optimizer_for_refit to each
teacher in csd.yaml and csd_multiteacher.yaml, matching the teacher
entries of the X-Token example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adithya Hanasoge <[email protected]>
avenkateshha added a commit that referenced this pull request Nov 16, 2026
Megatron worker setup reads offload_optimizer_for_refit without a
fallback since #3984 removed its `.get(..., True)` default. The CSD
example teachers never set the key: YAML lists are not merged from the
defaults file, so the student inherits it from distillation_math.yaml
while each teacher entry is written out in full. A CSD example teacher
switched to Megatron therefore fails with a KeyError during worker
setup.

Add offload_policy_before_refit and offload_optimizer_for_refit to each
teacher in csd.yaml and csd_multiteacher.yaml, matching the teacher
entries of the X-Token example.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Adithya Hanasoge <[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) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants