Skip to content

refactor(environments): migrate env leaf configs from TypedDict to BaseModel - #5234

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

yuki-97 merged 2 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-env-leaves

Conversation

@lonexreb

@lonexreb lonexreb commented Nov 14, 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 (after #3916, #5239, #4278, #4909). Five environment configs were still TypedDicts, and the math environment kept its defaults in .get(key, default) calls at the read sites.

Class File
MathEnvConfig nemo_rl/environments/math_environment.py
VLMEnvConfig nemo_rl/environments/vlm_environment.py
CodeEnvConfig nemo_rl/environments/code_environment.py
CodeJaccardEnvConfig nemo_rl/environments/code_jaccard_environment.py
RAGEnvConfig nemo_rl/environments/tools/retriever.py
  • All five are now BaseModel(extra="allow"). MasterConfig.env is still dict[str, Any], so the config reaches each environment actor as a plain dict through create_env. Each actor's __init__ calls model_validate on it, as nemo_gym.py already does for ExternalServiceReadinessConfig. Eval's MasterConfig already builds a MathEnvConfig, which model_validate accepts as it is.
  • Math defaults live on the fields: num_workers: int = 8, verifier_type: str = "math" and math_verify_impl: str = "hf_math_verify". This removes three .get(key, default) reads and the isinstance assert on verifier_type. An explicit null for math_verify_impl now fails at environment start.
  • stop_strings is removed from MathEnvConfig, VLMEnvConfig and CodeJaccardEnvConfig, and from docs/guides/environments.md. No environment read it; each step() builds its own stop strings. extra="allow" keeps YAMLs that still set the key loading.
  • Base and reference configs show the defaults. The base configs that carry env.math (grpo_math_1B.yaml, ppo_math_1B.yaml, distillation_math.yaml, evals/eval.yaml) and their reference configs gain verifier_type and, where missing, math_verify_impl.
  • Tests. The fixtures in test_code_environment.py and test_retriever.py build the config with keyword arguments. The create_env("math", {...}) tests keep dicts, because that is the path production configs take.

Not in this PR:

  • RewardModelEnvironmentConfig nests policy-lane TypedDicts (DynamicBatchingConfig, VllmConfig), so it waits for refactor(policy): migrate common config leaves to BaseModel #3197.
  • SlidingPuzzleConfig: its two readers disagree on the default size (4 in SlidingPuzzleGameLogic.generate, 3 in examples/run_grpo_sliding_puzzle.py). Picking one is a behaviour change, so it gets its own PR.
  • NemoGymConfig, because many open PRs touch nemo_gym.py.

Issues

None.

Convergence / perf / functionality proof

N/A: no change to rewards, verification or dependencies. The new field defaults equal the removed .get fallbacks.

Run locally on CPU: test_config_v2, test_config_validation, test_outdated_config_checks and the math and code-jaccard environment unit tests pass. test_code_environment.py and test_retriever.py need vLLM and a GPU, so they did not run locally.

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

@copy-pr-bot

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

@yuki-97 next PR in the config v2 series (environment leaf configs). Could you add a CI:* label and /ok to test a7925e216c7d90fdd68590f392f8726001f6add5 when you have a moment? Thanks!

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 17, 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.

Great to see the five environment leaf configs migrated to BaseModel. With the math env's call-site .get defaults moved onto the fields, and each env validating its config where it consumes it, an explicit null for math_verify_impl now fails at env start; on main it silently scored every sample 0.

Scope: the environment leaf-config migration and its config, docs and test updates, at a7925e2

Checked:

  • Consumer sweep — no dict-style access to the five configs remains anywhere in the repo. Eval passes its nested MathEnvConfig straight through, and model_validate returns that same instance (run_eval.py:72, math_environment.py:382)
  • Defaults — the new field defaults equal the removed .get fallbacks, so configs that omit the keys behave as before (math_environment.py:48-49)
  • Validation placement — validating in each actor's __init__ matches how other sub-configs under a dict parent are validated where they are consumed
  • Exemplar parity — the eval exemplar and reference config gain exactly the keys model_dump() now emits, so test_config_v2 stays consistent (evals/eval.yaml:59-63)

Remaining comments are on:

  • the unused stop_strings env-config field

nit

  • showing the MathEnvConfig class defaults in the base math configs
  • giving MathEnvConfig.num_workers a default of 8

Generated by Claude Code (#4999 version)

@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 16:19
…seModel

MathEnvConfig, VLMEnvConfig, CodeEnvConfig, CodeJaccardEnvConfig and
RAGEnvConfig become BaseModel(extra="allow"). MasterConfig.env stays a
plain dict, so each environment actor validates its config on entry,
as nemo_gym.py does for ExternalServiceReadinessConfig.

The math env's call-site defaults (verifier_type "math",
math_verify_impl "hf_math_verify") move onto the fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Shubhankar Tripathy <[email protected]>
…Config defaults

Address review on NVIDIA-NeMo#5234:
- Remove the stop_strings field from MathEnvConfig, VLMEnvConfig and
  CodeJaccardEnvConfig; no env reads it. Drop it from the eval configs
  and the environments guide.
- Give MathEnvConfig.num_workers a default of 8.
- Show verifier_type and math_verify_impl in the base math configs and
  their reference configs.

Signed-off-by: Shubhankar Tripathy <[email protected]>
@lonexreb
lonexreb force-pushed the refactor/config-v2-env-leaves branch from a7925e2 to 90d77a0 Compare November 21, 2026 01:06
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Nov 21, 2026
@lonexreb

Copy link
Copy Markdown
Contributor Author

@yuki-97 thanks for the review. Rebased on main (now 0 behind) and addressed all three comments in 90d77a0; test_config_v2, test_config_validation, test_outdated_config_checks and the env unit tests pass locally. Could you run /ok to test 90d77a0870fd837e2cf49c34d17c9390312ee71a 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 90d77a0, checked against the open threads from the previous review, plus a scan of the changed files for new issues.

Checked:

  • stop_strings removal: no environment ever read it (each step() builds next_stop_strings itself), the remaining stop_strings keys in configs are all generation-level, and extra="allow" keeps older YAMLs loading (math_environment.py:44-48)
  • Base configs and reference mirrors: the four no-defaults bases carrying env.math show all three keys with values matching their references, so test_reference_configs_up_to_date and test_config_v2 stay consistent
  • Every actor validates its config where it is consumed and reads it by attribute; model_validate on eval's already-validated MathEnvConfig returns the same instance (math_environment.py:379-385)

LGTM — no remaining findings from this re-review.

Generated by Claude Code

@yuki-97 yuki-97 added the CI:L1 Run doctests, unit tests, and functional tests label Nov 21, 2026
@yuki-97

yuki-97 commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

/ok to test 90d77a0

@yuki-97
yuki-97 enabled auto-merge (squash) November 21, 2026 06:41
@yuki-97
yuki-97 merged commit 18cbf20 into NVIDIA-NeMo:main Nov 22, 2026
97 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 Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants