Skip to content

refactor(examples): build MasterConfig with model_validate - #5306

Merged
terrykong merged 1 commit into
rnabel/pyrefly-baselinefrom
rnabel/master-config-validate
Nov 20, 2026
Merged

terrykong merged 1 commit into
rnabel/pyrefly-baselinefrom
rnabel/master-config-validate

Conversation

@RNabel

@RNabel RNabel commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Builds the top-level config in the example entry points with MasterConfig.model_validate(config) instead of MasterConfig(**config), which removes 114 errors from the Pyrefly baseline.

Issues

None. Stacked on #5298.

Usage

config = OmegaConf.to_container(config, resolve=True)
config = MasterConfig.model_validate(config)  # was: MasterConfig(**config)

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

Why

config is the untyped dict returned by OmegaConf.to_container. Unpacking it into the constructor makes Pyrefly report one missing-argument error per required field, plus a bad-unpacking error, at every call. model_validate takes the data as a value, so nothing is reported. examples/run_sft_v2.py and examples/run_vlm_mpo.py already construct their config this way.

Changes

  • 13 entry points under examples/, the same one-line change in each.
  • 5 unit tests that replace MasterConfig on an example module with a fake now give the fake a model_validate.
  • pyrefly-baseline.json pruned: 1,610 entries become 1,496 (101 missing-argument, 13 bad-unpacking). None are added.

Behaviour

For a dict input the two forms are equivalent. This was checked by running each script's real main() up to config construction with its default YAML, building the config both ways, and comparing model_dump(), extra keys and the fields set:

  • 12 of the 13 defaults validate and are identical both ways. The thirteenth, run_grpo_nemo_gym.py, fails validation with the same error both ways, so that predates this PR: its default YAML lacks policy.megatron_cfg.moe_per_layer_logging.
  • Invalid configs raise the same ValidationError both ways.

Two inputs that already fail now fail with a different exception type: a top-level non-string key, and a non-mapping config. Both were TypeError and are now pydantic ValidationError.

Testing

Run in a Linux container with the locked environment, CPU only:

  • pyrefly check at 1.4.0 with the baseline: 0 errors before pruning and after.
  • Ruff lint, import order and format on the touched files: pass.
  • The entry-point, config and PPO suites that cover the changed scripts and fakes: 513 passed, 7 skipped. The default loss/config/setup suites: 1484 passed, 95 skipped, same as the base branch.
  • Not run: GPU tests, and the functional hooks that call run_grpo_single_controller.main() end to end, so that box is left unchecked.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 19, 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.

@RNabel
RNabel requested review from terrykong and yuki-97 November 19, 2026 10:07
@RNabel
RNabel marked this pull request as ready for review November 19, 2026 10:30

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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. I found no actionable issues across the 19 changed files and directly affected config and test contracts.

One child report was unavailable, so I inspected its assigned entrypoints directly. This was a static source review. I did not run tests or lint/type checks, and I could not independently verify CI.

Generated by Codex

Note: formal approval is not available for this request, so this review is posted as a comment only.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

@RNabel
RNabel force-pushed the rnabel/master-config-validate branch from 915c8ab to 350a77f Compare November 19, 2026 19:30
@RNabel
RNabel force-pushed the rnabel/pyrefly-baseline branch from 741a817 to a48fc3a Compare November 19, 2026 19:30
@RNabel RNabel added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Nov 19, 2026
@RNabel

RNabel commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 350a77f

The example entry points constructed their config with
MasterConfig(**config), where config is the untyped dict returned by
OmegaConf.to_container. Pyrefly reports one missing-argument error per
required field at each such call. Use MasterConfig.model_validate(config),
as run_sft_v2.py and run_vlm_mpo.py already do, and prune the 114 baseline
entries this resolves. Five tests that fake MasterConfig on an example
module follow the new call.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Robin Nabel <[email protected]>
@RNabel
RNabel force-pushed the rnabel/master-config-validate branch from 350a77f to 0e4657c Compare November 20, 2026 08:23
@RNabel
RNabel force-pushed the rnabel/pyrefly-baseline branch from 6e805bc to 13d40e8 Compare November 20, 2026 08:23
@RNabel

RNabel commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0e4657c

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

LGTM, thanks for clearing these out of the baseline. For a dict config, MasterConfig.model_validate(config) does the same thing as MasterConfig(**config). Every MasterConfig is a plain pydantic BaseModel: no custom __init__, no before or wrap validators, no aliases, and no validation context. The only validator on a MasterConfig is a mode="after" validator, and it runs the same way for both calls.

The 5 updated test fakes are needed. If run_ppo, run_grpo, run_vlm_grpo, run_grpo_single_controller and run_distillation_nemo_gym go back to MasterConfig(**config), all 5 changed test files fail. The changed tests plus the entry-point and outdated-config suites pass on CPU (119 passed, 1 skipped on purpose). The ordering check in _call_lines already matches MasterConfig.model_validate(...), so it still checks that check_outdated_config runs before the config is built in all 13 scripts. The baseline drops exactly 114 entries and adds none.

Optional, not blocking: research/template_project/single_update.py still uses MasterConfig(**config). Its README tells people to copy that folder to start new projects, so switching it too would stop the old form from spreading. It's fine to leave that for a later PR.

Generated by Claude Code

@terrykong
terrykong merged commit 53bd6f3 into rnabel/pyrefly-baseline Nov 20, 2026
107 checks passed
@terrykong
terrykong deleted the rnabel/master-config-validate branch November 20, 2026 09:27
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.

3 participants