Skip to content

refactor(workers)!: unify worker class selection through config - #4176

Merged
yuki-97 merged 12 commits into
NVIDIA-NeMo:mainfrom
yuchenwang3:fix/4032-worker-class-config
Dec 3, 2026
Merged

yuki-97 merged 12 commits into
NVIDIA-NeMo:mainfrom
yuchenwang3:fix/4032-worker-class-config

Conversation

@yuchenwang3

@yuchenwang3 yuchenwang3 commented Sep 17, 2026 •

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

What and why

On main, a config-provided worker_extension_cls_fqn is rejected whenever quant_cfg is set, even if it names the correct quantized worker, while the Policy(worker_extension_cls_fqn=...) constructor argument can replace that worker without the same check. This PR makes worker_extension_cls_fqn the common selection path for policy and vLLM workers.

The shared resolver (resolve_worker_cls in nemo_rl/utils/config.py, called by resolve_policy_worker_cls and resolve_generation_worker_cls) fills an omitted FQN with the backend's quantized worker and warns, accepts an exact match, and rejects a mismatch with the expected FQN before allocating workers. Existing quant-only recipes keep automatic worker selection. Policy and VllmGeneration then check that the resolved worker is registered in ACTOR_ENVIRONMENT_REGISTRY, also before allocating workers.

The Policy constructor argument now emits a deprecation warning and feeds the config path. The two in-repo callers set the config field instead: the research template selects its extension in YAML, and setup_sft_v2() sets policy.worker_extension_cls_fqn to nemo_rl.data.energon.sft_worker.SFTMegatronPolicyWorker before building TQPolicy and rejects a different configured value. Frozen teachers clear the copied student extension alongside quantization settings.

Typing the resolvers' config as PolicyConfig / VllmConfig fixes three Pyrefly errors, so their entries are removed from pyrefly-baseline.json.

Usage and compatibility

Leave worker_extension_cls_fqn unset to keep automatic selection, or set it to the FQN printed by the warning. An explicit quant worker must match the policy backend or vLLM sync/async mode. The Automodel backend uses automodel_cfg.

Compatibility change: custom subclasses passed through Policy(worker_extension_cls_fqn=...) with quant_cfg are now rejected, just like config-provided mismatches. Non-quantized custom extensions remain supported. The deprecated argument still works when it satisfies the config validation rules; conflicting constructor/config values remain errors.

Issues

Closes #4032.

Convergence / perf / functionality proof

N/A for convergence and perf: only setup-time worker selection and validation change; recipes that use the default workers, or quantized recipes that omit the field, get the same worker classes as before.

Functionality: CPU unit tests run locally at ac546241, which includes main at da067f1331683b136022ab39172673fc05702dfe.

Test file Result
tests/unit/utils/test_config.py 89 passed
tests/unit/utils/test_outdated_config_checks.py 99 passed, 1 skipped
tests/unit/distributed/test_actor_environments.py 64 passed
tests/unit/models/policy/test_policy_validation.py 30 passed, 21 errors
tests/unit/models/policy/test_teacher_worker_group.py 89 passed, 1 skipped
tests/unit/models/generation/test_vllm_generation.py 189 passed, 3 skipped, 15 failed, 2 errors
tests/unit/algorithms/test_sft_v2.py 51 passed
tests/unit/telemetry/test_sft_v2.py 9 passed
tests/unit/data/test_energon_sft_v2.py Not run: the module skips without megatron.energon (mcore extra)
Focused selection below 133 passed

No GPU was available, so no GPU test ran. The 15 failures and 2 errors in test_vllm_generation.py are GPU tests that could not get GPU placement groups or found no NVIDIA driver. The 21 errors in test_policy_validation.py happen in a fixture that loads the gated meta-llama/Llama-3.2-1B config, which this machine cannot download. The skips need a CUDA device or three GPUs, or are skipped in the test itself. The same tests fail or skip in the same way at the previous head, 32cabe1, on this machine.

  • Driver cases mock Ray workers, model loading, and GPU execution.
  • The resolver tests are in tests/unit/utils/test_config.py, with the other tests for nemo_rl/utils/config.py. The vLLM selection cases are in tests/unit/models/generation/test_vllm_generation.py, next to the existing worker-extension tests. Earlier revisions of this PR had them in tests/unit/models/test_worker_config.py and tests/unit/models/generation/test_vllm_worker_selection.py; both files are removed.
  • Tests used Python 3.13.14 on Linux without a GPU. Multi-GPU distributed tests and GPU model execution were not run. These tests validate worker selection; main's Automodel quantized worker is still a placeholder. NVIDIA-runner CI requires maintainer authorization for this SHA.

Reproduce the focused selection in a configured test environment:

cd tests
uv run --group test pytest -q --hf-gated \
  -o addopts='-p no:vllm_tests -p no:sglang_tests -p no:trtllm_tests -p no:triton_tests' \
  unit/utils/test_config.py \
  unit/models/policy/test_policy_validation.py \
  unit/models/policy/test_teacher_worker_group.py \
  unit/models/generation/test_vllm_generation.py \
  -k 'worker_extension or quant_worker or quantization or unquantized_worker or isolates_student_inference_settings or fp32_lm_head'

Pre-checks

  • Read the contributor guidelines.
  • Added regression tests and updated existing expectations.
  • Full unit and GPU functional suites run locally (focused CPU results above).
  • Updated quantization docs and the research template documentation.

Needs upstream changes

None.

PR commands and CI
  • CI label, exactly one:
    • CI:Lfast: the default for most PRs. Runs a fast test subset.
    • CI:L1: dependency or container changes (pyproject.toml, uv.lock, Dockerfile) or broad core changes. Builds a new image and runs unit and functional tests.
    • CI:docs: docs-only changes. Runs doc tests only.
  • /ok to test <full-commit-sha>: start CI for that commit. Post again after each push.
  • /review: automated review comments. Add mode=strict for a stricter review, reset=true for a fresh full review.
  • /resolve-conflict: Autobot merges main into this PR and resolves the conflicts. PRs from forks must allow edits by maintainers.
  • Locally: /review-pr-team <pr-number> for a team review before you ask for human review.
  • Contributor guidelines

Assisted-by: OpenAI Codex
Assisted-by: Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Sep 17, 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 Sep 17, 2026
@yuchenwang3
yuchenwang3 marked this pull request as ready for review September 17, 2026 19:14
@yuchenwang3
yuchenwang3 requested review from a team and terrykong as code owners September 17, 2026 19:14
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 19, 2026
@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from ff7adc1 to fe6d468 Compare September 21, 2026 23:43
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

Rebased onto main (fd7112c3) at fe6d468e6f372be4665e352f63f2cdfbe62c543c. The conflict resolution preserves the upstream FP32 LM-head validation and the new teacher_index argument.

The focused CPU selection passes 84 tests, including the FP32 LM-head cases. Changed-file formatting, lint, TOML, and recipe checks pass. Targeted Pyrefly reports zero errors under the repository configuration. The full-repository Pyrefly hook could not start because the local Automodel submodule is not populated; GPU/distributed validation still requires the full environment and maintainer-authorized CI.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Sep 22, 2026
@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from fe6d468 to ea794c2 Compare September 22, 2026 18:13
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

Rebased onto main (592149ef) at ea794c201418c35d848d5a245d14adeed6e4d4d2 and resolved the conflict while retaining the upstream DTensor V1 guard and V2 default. Updated the worker-selection expectations and added three cases showing that implicit/config/constructor quantized workers cannot bypass the V1 rejection before allocation.

The focused CPU selection passes 88 tests (39 deselected), including the FP32 LM-head cases. Changed-file formatting, lint, TOML, and recipe checks pass; targeted Pyrefly reports zero shown errors under the repository configuration. Full-repository Pyrefly remains blocked locally by the unpopulated Automodel submodule. GPU/distributed validation was not run and still requires maintainer-authorized CI for this SHA. The PR description now contains the current results and reproduction command.

@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from ea794c2 to 82b433e Compare September 24, 2026 14:54
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 24, 2026
@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from 82b433e to a297e5d Compare October 2, 2026 19:39
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

@yuki-97 Rebased onto main at a297e5d6f18184ba4b39102714869341e2b49ed3. This keeps the new _v2-key rejection intact and adds coverage for both values with implicit, config, and constructor quantized-worker selection before allocation.

The focused CPU selections pass 79 + 21 tests; changed-file lint/format and targeted type checks also pass. GPU/distributed validation has not run. Could you review the worker-selection path for #4032 and help authorize CI for this SHA?

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 2, 2026
@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from a297e5d to 24c2760 Compare October 8, 2026 23:19
@yuchenwang3

Copy link
Copy Markdown
Contributor Author

@yuki-97 Rebased on main and fixed the conflicts. The template and worker tests now use the Automodel names. All 144 focused CPU tests pass; GPU tests still need CI. Could you review the worker-selection change and authorize CI for 24c27600e?

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Oct 9, 2026
Resolve ModelOpt requirements through worker_extension_cls_fqn, deprecate the Policy constructor override, and migrate the template and teacher configuration.

BREAKING CHANGE: custom quantized worker subclasses passed through the Policy constructor must now match the backend ModelOpt worker, as required for config overrides.

Signed-off-by: Yuchen Wang <[email protected]>
@yuchenwang3
yuchenwang3 force-pushed the fix/4032-worker-class-config branch from 24c2760 to 8ee8c68 Compare October 19, 2026 21:47

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

hi @yuchenwang3 , sorry for late reply. thanks for helping refactor this, much more clean than before!

@RayenTian could you help review it?

@RayenTian

Copy link
Copy Markdown
Contributor

/ok to test c9aec4e

@RayenTian RayenTian 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 at c9aec4e. My earlier threads are resolved, and I found no new problems in the commits since.

RayenTian
RayenTian previously approved these changes Nov 25, 2026

@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; the PR is 11 commits behind and the "Check if PR branch is up to date" job allows at most 10.

Thanks for making worker_extension_cls_fqn the single place that picks the policy and vLLM worker class, with quant_cfg now a check on that field, as #4032 proposed.

Thanks also for the nine-comment self-review and for fixing all nine before this pass.

Scope: the worker-selection change, its docs, the research template and tests, checked against the proposal in #4032, at c9aec4e

Checked:

  • Every item of #4032 is implemented as proposed: an unset field is filled with a warning, the matching ModelOpt worker is accepted, anything else raises with the expected FQN (config.py:50-66).
  • The deprecated constructor argument is copied into the config before the one resolver, so both channels get the same quant check and registration check (lm_policy.py:133-140).
  • All 14 shipped configs that resolve to a non-null quant_cfg select the same worker classes as on main.
  • The resolved class, not a key read back from the config, is checked for registration before any worker or placement group is created (lm_policy.py:343-344, vllm_generation.py:381-389).

Remaining comments are on:

  • SFTv2 with quant_cfg set.
  • The research extension-points reference, which still describes the old mechanism.

nit

  • The quantization guide lists Automodel among the backends with a ModelOpt worker.
  • Assertions in the policy tests that cannot fail.
  • The .get fallback in the two worker resolvers.

nemo-rl-review: kind=expert harness=claude-code/2.1.332 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=c9aec4e

Comment thread nemo_rl/models/policy/utils.py Resolved
Comment thread nemo_rl/algorithms/sft_v2.py Resolved
Comment thread docs/guides/quantization-aware-rl.md Resolved
@yuki-97

yuki-97 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/ok to test b000aa5

yuki-97
yuki-97 previously approved these changes Nov 26, 2026
@yuki-97
yuki-97 enabled auto-merge (squash) November 26, 2026 05:11
@yuki-97

yuki-97 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

/ok to test 98c4eff

yuki-97
yuki-97 previously approved these changes Nov 26, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 28, 2026
@terrykong terrykong removed the Documentation Improvements or additions to documentation label Nov 28, 2026
@yuki-97

yuki-97 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

/ok to test 0a7188f

yuki-97
yuki-97 previously approved these changes Dec 1, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) and removed waiting-on-maintainers Waiting on maintainers to respond labels Dec 1, 2026
@yuki-97

yuki-97 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

/ok to test d9cf2a3

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

Self-review via /review-pr-team of merge commit d9cf2a3, which brings #3945 (real-quant vLLM rollout) from main into this PR's worker selection: 6 agents (RL expert, test, bug-finder, design, comment-reviewer, comment-editor) + devil's-advocate pass.

Verdict — no findings above the confidence bar. LGTM, no action needed.

Verified clean

  • real_quant as a second trigger — resolve_generation_worker_cls now also picks the ModelOpt vLLM worker when policy.generation.real_quant is set; a real-quant run needs this because it must leave policy.generation.quant_cfg null, vllm/utils.py:1369, modelopt/utils.py:43-48
  • Rejection added on main — every worker_extension_cls_fqn + quant_cfg/real_quant case that main rejected in VllmGeneration.__init__ still raises before placement groups are created, except the exact ModelOpt worker, which this PR accepts, vllm_generation.py:387, utils/config.py:60-64
  • Docs and config comments — the "Worker Class Selection" paragraph, the grpo_math_1B.yaml generation comment and the VllmConfig.worker_extension_cls_fqn comment match the code for both keys, quantization-aware-rl.md:18-22
  • Earlier fixes — every fix from the resolved threads is still in place after the merge, including the indexed GENERATION_WORKER_OVERRIDES[default_cls] where main had a .get fallback, vllm/utils.py:1368

nemo-rl-review: kind=expert harness=claude-code/2.1.334 model=claude-fable-5-2 effort=medium review-pr-team=v3 reviewed=d9cf2a3

@yuki-97
yuki-97 merged commit 78f1452 into NVIDIA-NeMo:main Dec 3, 2026
112 of 168 checks passed
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) community-request complexity:medium Moderate change. Set by Autobot PR classify (skills/pr-classify) convergence-risk:high Likely to change training results. Set by Autobot PR classify (skills/pr-classify) proof:convergence Needs convergence proof (W&B runs). Set by Autobot PR classify (skills/pr-classify) proof:functionality Needs proof that it works. Set by Autobot PR classify (skills/pr-classify)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worker-class overrides are split across three mechanisms instead of one config field

5 participants