Repository navigation
refactor(environments): migrate env leaf configs from TypedDict to BaseModel - #5234
Conversation
|
@yuki-97 next PR in the config v2 series (environment leaf configs). Could you add a |
yuki-97
left a comment
There was a problem hiding this comment.
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
MathEnvConfigstraight through, andmodel_validatereturns that same instance (run_eval.py:72, math_environment.py:382) - Defaults — the new field defaults equal the removed
.getfallbacks, 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, sotest_config_v2stays consistent (evals/eval.yaml:59-63)
Remaining comments are on:
- the unused
stop_stringsenv-config field
nit
- showing the
MathEnvConfigclass defaults in the base math configs - giving
MathEnvConfig.num_workersa default of 8
Generated by Claude Code (#4999 version)
…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]>
a7925e2 to
90d77a0
Compare
|
@yuki-97 thanks for the review. Rebased on main (now 0 behind) and addressed all three comments in 90d77a0; |
yuki-97
left a comment
There was a problem hiding this comment.
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_stringsremoval: no environment ever read it (eachstep()buildsnext_stop_stringsitself), the remainingstop_stringskeys in configs are all generation-level, andextra="allow"keeps older YAMLs loading (math_environment.py:44-48)- Base configs and reference mirrors: the four no-
defaultsbases carryingenv.mathshow all three keys with values matching their references, sotest_reference_configs_up_to_dateandtest_config_v2stay consistent - Every actor validates its config where it is consumed and reads it by attribute;
model_validateon eval's already-validatedMathEnvConfigreturns the same instance (math_environment.py:379-385)
LGTM — no remaining findings from this re-review.
Generated by Claude Code
|
/ok to test 90d77a0 |
…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]>
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.MathEnvConfignemo_rl/environments/math_environment.pyVLMEnvConfignemo_rl/environments/vlm_environment.pyCodeEnvConfignemo_rl/environments/code_environment.pyCodeJaccardEnvConfignemo_rl/environments/code_jaccard_environment.pyRAGEnvConfignemo_rl/environments/tools/retriever.pyBaseModel(extra="allow").MasterConfig.envis stilldict[str, Any], so the config reaches each environment actor as a plain dict throughcreate_env. Each actor's__init__callsmodel_validateon it, asnemo_gym.pyalready does forExternalServiceReadinessConfig. Eval'sMasterConfigalready builds aMathEnvConfig, whichmodel_validateaccepts as it is.num_workers: int = 8,verifier_type: str = "math"andmath_verify_impl: str = "hf_math_verify". This removes three.get(key, default)reads and theisinstanceassert onverifier_type. An explicitnullformath_verify_implnow fails at environment start.stop_stringsis removed fromMathEnvConfig,VLMEnvConfigandCodeJaccardEnvConfig, and fromdocs/guides/environments.md. No environment read it; eachstep()builds its own stop strings.extra="allow"keeps YAMLs that still set the key loading.env.math(grpo_math_1B.yaml,ppo_math_1B.yaml,distillation_math.yaml,evals/eval.yaml) and their reference configs gainverifier_typeand, where missing,math_verify_impl.test_code_environment.pyandtest_retriever.pybuild the config with keyword arguments. Thecreate_env("math", {...})tests keep dicts, because that is the path production configs take.Not in this PR:
RewardModelEnvironmentConfignests 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 defaultsize(4 inSlidingPuzzleGameLogic.generate, 3 inexamples/run_grpo_sliding_puzzle.py). Picking one is a behaviour change, so it gets its own PR.NemoGymConfig, because many open PRs touchnemo_gym.py.Issues
None.
Convergence / perf / functionality proof
N/A: no change to rewards, verification or dependencies. The new field defaults equal the removed
.getfallbacks.Run locally on CPU:
test_config_v2,test_config_validation,test_outdated_config_checksand the math and code-jaccard environment unit tests pass.test_code_environment.pyandtest_retriever.pyneed vLLM and a GPU, so they did not run locally.Needs upstream changes
None.
PR commands and CI
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. Addmode=strictfor a stricter review,reset=truefor a fresh full review./resolve-conflict: Autobot mergesmaininto this PR and resolves the conflicts. PRs from forks must allow edits by maintainers./review-pr-team <pr-number>for a team review before you ask for human review.🤖 Generated with Claude Code