Skip to content

feat(workers): Add config-driven worker extension FQNs - #3809

Merged
yuki-97 merged 3 commits into
NVIDIA-NeMo:mainfrom
pstjohn:u-5-worker-extension-fqn
Sep 9, 2026
Merged

yuki-97 merged 3 commits into
NVIDIA-NeMo:mainfrom
pstjohn:u-5-worker-extension-fqn

Conversation

@pstjohn

@pstjohn pstjohn commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

This change is to make it easier to plug in custom workers and policies.

Policy.__init__ already accepts a worker_extension_cls_fqn, but standard policy configs cannot set it. The vLLM generation path has no equivalent extension hook. A caller that needs custom policy and vLLM workers therefore has to wrap or replace Policy and monkeypatch the vLLM worker resolver.

This PR adds one optional worker_extension_cls_fqn field to PolicyConfig and VllmConfig.

Policy reads the field directly from its config, so normal construction paths honor it without algorithm-specific forwarding. The existing constructor argument remains supported.

If config and the constructor provide different FQNs, construction fails rather than choosing one silently. VllmGeneration applies its configured FQN after the existing worker resolver for both synchronous and asynchronous engines.

On both paths, worker_extension_cls_fqn is mutually exclusive with quant_cfg, because both settings replace the backend’s resolved worker. Invalid combinations fail before worker or placement-group allocation. The canonical GRPO exemplar and its reference config include the two optional entries, as required for the existing TypedDict config schema.

@pstjohn
pstjohn requested review from a team as code owners August 25, 2026 00:44
@copy-pr-bot

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

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

Reviewed by a team of 5 agents (RL expert, bug finder, test agent, design reviewer, devil's advocate). Nice, tightly-scoped change — and failing loudly on conflicting config-vs-constructor values instead of silently picking one is the right call.

Verification run locally:

  • Linters clean: ruff, ruff-format, taplo, whitespace, and pyrefly check (0 errors).
  • All 4 new tests pass on 8xH100. They were mutation-tested and kill 4 real mutants (dropping the vLLM override; moving the quant check after PG init; the async/sync kwargs split) — these are not tautologies. cluster._init_placement_groups.assert_not_called() in particular has teeth: moving the check after the PG call makes the test fail.
  • The YAML nesting was checked hard by three agents independently and is correct — VllmGeneration.self.cfg is the policy.generation dict, so the key is read where it's set. Not a silent no-op.

3 inline comments, all suggestions, none blocking.

Two lower-confidence items I'm noting here rather than inline, both arguably tracking issues rather than work for this PR:

  • TeacherWorkerGroup deep-copies the student policy config and hardcodes MegatronPolicyWorker, so policy.worker_extension_cls_fqn is silently dropped for distillation teachers — the same hole it already warns-and-clears for quant_cfg. Debatable whether that's even wrong (a frozen teacher on the stock worker seems fine).
  • Nothing in the suite pins an exemplar YAML key to the dict level its consumer reads. Harmless here since the value is null and both consumers use .get(), but see below.

Unrelated repo-level find, worth its own issue: _collect_mismatched_keys in tests/unit/test_config_v2.py:101 is one-directional. Deleting a key from an exemplar while leaving the reference config intact still passes all 14 tests, so exemplar-side drift is invisible in both directions.

Generated by Claude Code

Comment thread nemo_rl/models/policy/lm_policy.py Resolved
Comment thread examples/configs/grpo_math_1B.yaml Resolved
@pstjohn

pstjohn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test ab2f594

@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 6, 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.

Scope: the two new worker_extension_cls_fqn fields and their wiring in lm_policy.py / vllm_generation.py, plus the exemplar + reference YAMLs and the two new test modules.

Checked:

  • Config placement — the generation-level key is read at the same level quant_cfg and refit_transport live at, and the reference config mirrors the exemplar, so test_reference_configs_up_to_date stays green.
  • Guard ordering — the quant exclusion correctly precedes cluster._init_placement_groups; traced where each other invalid-FQN case actually surfaces, and how much is allocated by then.
  • Backend reach — which of the five generation backends can see the key after defaults: inheritance, and which of them read it.
  • Test mutation — dropped each new production line in turn and confirmed a new test fails; the default no-extension path is unchanged from main.
  • Exemplar convention — compared against how other NotRequired PolicyConfig keys are spread across the five base configs.

Remaining comments are three fail-early / validation suggestions, one fix to a backend list in a YAML comment, and a pointer to #4032 for the longer-term consolidation (no action needed here).

Before merge: could you rebase and run CI? The branch is 69 commits behind main, and nemo_rl/models/generation/__init__.py has moved there since it branched — that is the file the vllm/config.py comment asks you to add a guard to, so it is worth rebasing before picking that one up. I have added CI:Lfast; all unit shards were skipped on ab2f594, so the four new tests have not run in CI yet.

Comment thread examples/configs/grpo_math_1B.yaml Resolved
Comment thread nemo_rl/models/policy/lm_policy.py Resolved
Comment thread nemo_rl/models/policy/__init__.py Resolved
Add one optional worker_extension_cls_fqn field to PolicyConfig and
VllmConfig.

Signed-off-by: Peter St. John <[email protected]>
Address review feedback on the config-driven worker extension FQNs.

The quant_cfg mutual exclusion applied to both the config field and the
pre-existing Policy constructor argument, which narrowed the constructor's
contract. Previously the override ran after resolve_policy_worker_cls and
printed the resolved class name, so extending the quant-resolved worker via
the constructor was supported. Restrict the exclusion to the config-supplied
FQN, where the config author cannot know which worker quant_cfg resolves to.

Cover the two branches that had no test: config and constructor set to the
same value (the equality clause was dead code with respect to the suite), and
the constructor argument combined with quant_cfg. Both were mutation-verified
to fail without the corresponding source change.

Note in the exemplar that the generation-level key is vLLM-only, since
sglang/trtllm/dynamo inherit this config and ignore it, and disambiguate it
from vLLM's own worker_extension_cls engine argument.

Signed-off-by: Peter St. John <[email protected]>
@pstjohn
pstjohn force-pushed the u-5-worker-extension-fqn branch from ab2f594 to f934c26 Compare September 9, 2026 16:02
@yuki-97

yuki-97 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

/ok to test f934c26

@yuki-97
yuki-97 enabled auto-merge (squash) September 9, 2026 17:52
@yuki-97
yuki-97 merged commit 3c17147 into NVIDIA-NeMo:main Sep 9, 2026
84 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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants