Skip to content

refactor(evals): migrate EvalConfig from TypedDict to BaseModel - #4909

Merged
yuki-97 merged 5 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-eval
Nov 22, 2026
Merged

yuki-97 merged 5 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-eval

Conversation

@lonexreb

@lonexreb lonexreb commented Oct 25, 2026 •

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

What and why

Part of the config v2 series (#3916 ClusterConfig, #4278 LoggerConfig, #5239 CheckpointingConfig). EvalConfig was still a TypedDict, and its checks ran as asserts in setup(), after the cluster was already up.

  • EvalConfig is a BaseModel(extra="allow") (nemo_rl/evals/eval.py). The five fields carry the defaults from examples/configs/evals/eval.yaml: metric="pass@k", num_tests_per_prompt=1, seed=42, k_value=1, save_path=None.
  • Validation at config load. metric is Literal["pass@k", "cons@k"] and k_value is PositiveInt. A model_validator(mode="after") checks num_tests_per_prompt >= k_value. A bad eval: block now fails at MasterConfig(**config) with a pydantic.ValidationError instead of an AssertionError in setup(). The temperature > 0 and top_k != 1 check spans eval and generation, so it stays in setup().
  • Call sites. Every eval_config["k"], eval_config.get("save_path") and master_config.eval["k"] in eval.py uses attribute access. No other module reads EvalConfig (checked nemo_rl/, examples/, research/, docs/).
  • Tests. The _run_env_eval_impl fixture in tests/unit/evals/test_eval.py builds a real EvalConfig instead of a dict, and test_eval_config_rejects_fewer_tests_than_k covers the validator.

No YAML or reference-config changes: every EvalConfig key is already in examples/configs/evals/*.yaml and tests/unit/reference_configs/eval.yaml, so model_dump() adds no keys. Valid configs behave as before.

Not in this PR: _PassThroughEnvConfig stays a TypedDict; the env configs it nests are migrated in #5234.

Issues

None.

Convergence / perf / functionality proof

N/A: no change to eval scoring, generation or dependencies; only where the config is declared and validated moves.

Run locally on CPU: tests/unit/evals/test_eval.py, tests/unit/test_config_v2.py and tests/unit/test_config_validation.py (471 passed, 0 failed). ruff 0.9.9 (including --select I and format) is clean. No GPU eval run was done.

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

🤖 Generated with Claude Code

Fourth PR in the utils-layer config v1->v2 series (NVIDIA-NeMo#3916, NVIDIA-NeMo#4278, NVIDIA-NeMo#4152).

EvalConfig is now a pydantic BaseModel with extra="allow". The five fields
carry the exemplar defaults from examples/configs/evals/eval.yaml, and the
metric / k_value / num_tests_per_prompt checks that setup() used to assert
at runtime now run in a model_validator so a bad eval block fails at config
load. The cross-config temperature/top_k check stays in setup().

All eval_config["k"] / .get("k") / master_config.eval["k"] call sites in
nemo_rl/evals/eval.py use attribute access. The _run_env_eval_impl test
fixture builds a real EvalConfig instead of a dict so missed call sites
cannot hide behind a dict's .get. New tests cover the defaults, the three
validator rejections, and extra-key passthrough.

_PassThroughEnvConfig stays a TypedDict until MathEnvConfig/VLMEnvConfig
are migrated with the environment configs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Signed-off-by: Shubhankar Tripathy <[email protected]>
@copy-pr-bot

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

@lonexreb

Copy link
Copy Markdown
Contributor Author

/ok to test 40ba2b3

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

@RayenTian could you also help review this?

@yuki-97
yuki-97 requested a review from RayenTian October 27, 2026 01:12
@yuki-97 yuki-97 added the CI:L1 Run doctests, unit tests, and functional tests label Oct 27, 2026
@yuki-97

yuki-97 commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

/ok to test 40ba2b3

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

Reviewed the EvalConfig TypedDict→BaseModel migration (4th in the config v1→v2 series). Verified end-to-end: the three former setup() asserts map exactly to the new model_validator (no flipped/off-by-one conditions), the validator actually fires at load via examples/run_eval.py → MasterConfig(**config) (no model_construct bypass), every call site in eval.py was converted to attribute access, no other module references EvalConfig, and the 5 class defaults match eval.yaml exactly. Moving validation to config-load time is a nice improvement. tests/unit/evals/test_eval.py passes 17/17 locally. One minor, non-blocking test suggestion inline.

Generated by Claude Code

Comment thread tests/unit/evals/test_eval.py Resolved
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Oct 28, 2026
lonexreb and others added 2 commits November 11, 2026 22:36
Signed-off-by: Shubhankar Tripathy <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Shubhankar Tripathy <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@lonexreb

Copy link
Copy Markdown
Contributor Author

@yuki-97 merged main again (was 16 behind, no conflicts; eval/config tests pass locally). Could you /ok to test ec5537ecd0ae9eb8f3d6401d009c65c112f1fc23 when you get a chance? Thanks!

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

Thanks for migrating EvalConfig to a BaseModel. Moving the three eval checks into its validator means a bad eval block now fails at config load, in MasterConfig(**config) (run_eval.py:105), instead of after the cluster is up.

Scope: the EvalConfig TypedDict-to-BaseModel migration in nemo_rl/evals/eval.py and its tests, at ec5537e

Checked:

  • Validator vs removed asserts: the three moved conditions are identical to the removed setup() asserts, and the cross-section temperature/top_k check rightly stays in setup() (eval.py:126-129)
  • Consumers: a repo-wide sweep finds no dict-style access to EvalConfig left; only eval.py and its test use it
  • Defaults: all 5 class defaults match examples/configs/evals/eval.yaml, mmau.yaml and the reference config, so test_config_v2 sees no new keys (eval.yaml:2-7)
  • Coverage: the validator runs on every shipped eval config, through run_eval.py and test_config_validation.py (test_config_validation.py:199-201)

Remaining comments are on:

  • Dropping the two EvalConfig tests that only assert class defaults and pydantic's extra="allow" handling

nit

  • Unused metric / k_value locals and a comment about where the checks moved, in setup()
  • Declaring metric and k_value on the fields with Literal and PositiveInt instead of checking them by hand

Generated by Claude Code (#4999 version)

Comment thread nemo_rl/evals/eval.py Resolved
Comment thread tests/unit/evals/test_eval.py Resolved
Comment thread tests/unit/evals/test_eval.py Resolved
Comment thread nemo_rl/evals/eval.py Resolved
@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 Nov 18, 2026
lonexreb and others added 2 commits November 20, 2026 21:31
… fields

Use Literal and PositiveInt so pydantic rejects bad values; the validator
keeps only the cross-field num_tests_per_prompt >= k_value check. Drop the
now-unused setup() locals and the tests that only pinned defaults and
pydantic's extra="allow" handling.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Shubhankar Tripathy <[email protected]>
@lonexreb

Copy link
Copy Markdown
Contributor Author

@yuki-97 merged main (was 78 behind, now 0, no conflicts) and addressed the three review comments in b71c138. test_eval.py, test_config_v2 and test_config_validation pass locally. Could you run /ok to test b71c138c429e8c762143a2f5cfbf8040e401fad0 when you have a moment?

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

Thanks for resolving the previous round's comments.

Scope: fix commit b71c138, checked against the open threads from the previous review, plus a scan of the changed files for new issues.

Checked:

  • Literal / PositiveInt on the fields reject the same inputs the removed hand-written checks did, and every shipped eval config and test-suite override (eval.num_tests_per_prompt=16) still validates (eval.py:46-61)
  • setup() keeps only the temperature/top_k cross-check, and no dict-style EvalConfig access remains anywhere in the repo
  • The remaining test_eval_config_rejects_fewer_tests_than_k exercises the project's own after-validator, so it stays within the testing rule (test_eval.py:294-299)

LGTM — no remaining findings from this re-review.

Generated by Claude Code

@yuki-97

yuki-97 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

/ok to test b71c138

@yuki-97
yuki-97 enabled auto-merge (squash) November 21, 2026 06:40
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Nov 21, 2026
@lonexreb

Copy link
Copy Markdown
Contributor Author

@yuki-97 L1_Functional_Tests_Megatron_3 failed on b71c138 before any test code ran: ray.init in distillation_megatron.sh raised The current node timed out during startup after Failed to get node info: RPC error: Deadline Exceeded (job log). That looks like a runner problem, not this change, and I don't have rights to re-run. Could you re-run the failed job once the run finishes?

@yuki-97
yuki-97 merged commit da067f1 into NVIDIA-NeMo:main Nov 22, 2026
165 of 169 checks passed
yfw added a commit that referenced this pull request Nov 24, 2026
…kind-advantages

Brings in 8 commits, including the BaseModel environment configs (#5234),
the BaseModel EvalConfig (#4909), the pipelined prefix writer (#5176) and the
self-review status check (#5348). No conflicts. The two GRPO configs pick up
main's new math verifier_type key next to this PR's masked_reward_policy
comments.

Main's ledger schema is still 8, so failure_kind stays in schema 9. The Gym
pin is the same on both sides (9e2e5d0ad0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Yi-Fu Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests community-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants