Repository navigation
refactor(utils): migrate logger configs to BaseModel - #4278
Conversation
|
/ok to test 0db7ffb |
|
/ok to test 0db7ffb |
yuki-97
left a comment
There was a problem hiding this comment.
hi @lonexreb , thanks for helping on the migration!
Scope: the logger-config migration in nemo_rl/utils/logger.py, its call sites, and the test fixtures and reference configs it touches.
Checked:
- Dict-style access: repo-wide sweep for
["..."]/.get(...)/**on the logger config and its sub-configs; every production consumer innemo_rl/,examples/,research/andtools/now reads it by attribute. - Backend init kwargs:
model_dump(exclude_none=True)passed towandb.init/swanlab.initstill forwards extra keys such astags. - Test fixtures: every test that builds, replaces or splats
logger, including files outside the diff. - Defaults: BaseModel fields against the
logger:blocks of the exemplar YAMLs. test_config_v2: reference-config keys against what the migrated classes dump.
Remaining comments are on test fixtures that still pass dicts, defaults and required keys on the logger configs, and moving the enabled-without-block checks into a validator.
0db7ffb to
a12f30a
Compare
|
/ok to test 6bf4d67 |
|
/ok to test 3bd7900 |
6bf4d67 to
3bd7900
Compare
…, missed test files Applies all review findings on NVIDIA-NeMo#4278: - v2 defaults move onto the fields: *_enabled = False, monitor_gpus = True, num_val_samples_to_print = 0, gpu_monitoring intervals = 10, log_nemo_gym_full_result_tables = False (bool, not Optional — None and False meant the same to every reader; the bool() shim in should_log_nemo_gym_full_result_tables is dropped). WandbConfig and SwanlabConfig project/name become required strs; wandb becomes Optional like the other backend blocks. - The enabled-without-block checks move from Logger.__init__ into a model_validator(mode="after") on LoggerConfig (per the RewardPenaltyConfig pattern), so misconfiguration fails at config load — before setup paths like should_log_nemo_gym_full_result_tables touch logger.wandb. - tests/unit/utils/test_logger.py (missed entirely before): Logger dict configs wrapped in LoggerConfig.model_validate (nested blocks must coerce); Wandb/Swanlab/Mlflow logger configs wrapped in <X>Config.model_construct (bypasses the now-required project/name for minimal fixtures; verified extras like tags still reach wandb.init via model_dump(exclude_none=True)). TensorboardLogger sites stay as-is — it never reads its cfg. - test_setup.py: the three remaining plain-dict logger assignments wrapped (model_copy(update=...) for the spread-copies); nested wandb dicts inside model_construct fixtures coerced to WandbConfig across five test files (model_construct does not coerce nested dicts). - Reference configs: null -> false/0 for the keys that gained real defaults; deep-verified all six reference logger blocks still match LoggerConfig.model_dump() exactly. Signed-off-by: Shubhankar Tripathy <[email protected]>
|
Thanks for another thorough pass @yuki-97 (and the lint commit — built on top of it). All findings addressed:
CI triggered on |
|
/ok to test 0691c64 |
|
Update: I got the unit suites running locally (hand-built venv around the repo's Python pin) and ran everything this PR touches —
One unrelated failure in the touched files ( |
Third PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 ClusterConfig, Schema: WandbConfig, SwanlabConfig, TensorboardConfig, MLflowConfig, GPUMonitoringConfig, and LoggerConfig move from TypedDict to BaseModel(extra="allow"); NotRequired fields become Optional[...] = None. GpuMetricSnapshot stays TypedDict (internal data container, not YAML-loaded config). Behavior-preserving details: - WandbLogger/SwanlabLogger passed dict(cfg) / **cfg straight into wandb.init / swanlab.init; they now pass model_dump(exclude_none=True) so unset Optional fields do not reach the backends as explicit Nones, while extra= passthrough keys survive. - Logger.__init__ raises a named ValueError when a backend is enabled but its sub-config block is absent (previously a KeyError). - MLflowLogger keeps its cfg-or-env fallbacks, now via attributes. Call sites (~22 across algorithms, sync_rollout_actor, trajectory_collector, SC setup, all example run scripts, flow_grpo) move to attribute access. Reference configs: always-emitted Optional keys are added with their default values at both the logger level and inside the nested wandb/tensorboard/mlflow blocks (deep-verified: each reference logger block now matches LoggerConfig.model_dump exactly). Test fixtures wrap logger dict literals in LoggerConfig.model_construct and move subscripts to attribute access. Signed-off-by: Shubhankar Tripathy <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
…, missed test files Applies all review findings on NVIDIA-NeMo#4278: - v2 defaults move onto the fields: *_enabled = False, monitor_gpus = True, num_val_samples_to_print = 0, gpu_monitoring intervals = 10, log_nemo_gym_full_result_tables = False (bool, not Optional — None and False meant the same to every reader; the bool() shim in should_log_nemo_gym_full_result_tables is dropped). WandbConfig and SwanlabConfig project/name become required strs; wandb becomes Optional like the other backend blocks. - The enabled-without-block checks move from Logger.__init__ into a model_validator(mode="after") on LoggerConfig (per the RewardPenaltyConfig pattern), so misconfiguration fails at config load — before setup paths like should_log_nemo_gym_full_result_tables touch logger.wandb. - tests/unit/utils/test_logger.py (missed entirely before): Logger dict configs wrapped in LoggerConfig.model_validate (nested blocks must coerce); Wandb/Swanlab/Mlflow logger configs wrapped in <X>Config.model_construct (bypasses the now-required project/name for minimal fixtures; verified extras like tags still reach wandb.init via model_dump(exclude_none=True)). TensorboardLogger sites stay as-is — it never reads its cfg. - test_setup.py: the three remaining plain-dict logger assignments wrapped (model_copy(update=...) for the spread-copies); nested wandb dicts inside model_construct fixtures coerced to WandbConfig across five test files (model_construct does not coerce nested dicts). - Reference configs: null -> false/0 for the keys that gained real defaults; deep-verified all six reference logger blocks still match LoggerConfig.model_dump() exactly. Signed-off-by: Shubhankar Tripathy <[email protected]>
…ture required fields Ran the full tests/unit/utils/test_logger.py (98 tests), tests/unit/test_config_v2.py and tests/unit/test_config_validation.py (1104 passed) plus the touched single-controller fixture files locally; fixes everything that surfaced: - LoggerConfig.gpu_monitoring gets Field(default_factory= GPUMonitoringConfig): both its fields now carry exemplar defaults, so an omitted block is well-defined (matches the NonColocatedTeachersConfig default_factory precedent). - Minimal Wandb/Swanlab fixtures seed the now-required project/name (empty model_construct() left them unset, and WandbLogger's init log line reads cfg.project). - Logger fixtures: model_validate takes the dict positionally, not splatted; sub-config equality asserts compare attributes instead of dicts; missing wandb/swanlab name keys and gpu_monitoring blocks seeded. - test_init_swanlab_only had three @patch decorators but two mock params, so temp_dir silently bound to the WandbLogger mock — pre-existing bug that validation now exposes; parameter added. The one remaining failure in the touched files (test_logs_raw_and_canonical_rollout_throughput) reproduces on pristine main — pre-existing timing flake, unrelated. Signed-off-by: Shubhankar Tripathy <[email protected]>
0691c64 to
7b97134
Compare
…logger Signed-off-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
…ator Signed-off-by: Yuki Huang <[email protected]>
…nfig Signed-off-by: Yuki Huang <[email protected]>
…as Optional Signed-off-by: Yuki Huang <[email protected]>
|
/ok to test 247d17d |
|
Root-caused the sphinx-build failure on this run: the |
Restores 5fa1ac2: the W&B train-data table needs log_full_train_data, which crashed at controller startup because LoggerConfig (a BaseModel since #4278) was read like a dict. Read .log_dir; regression test included. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Zhiyu Li <[email protected]>
What does this PR do ?
Third PR in the utils-layer config v1 → v2 series (#3916
ClusterConfig, #4152 checkpointing configs; pattern from #2518). Migrates the six logger config classes innemo_rl/utils/logger.py—WandbConfig,SwanlabConfig,TensorboardConfig,MLflowConfig,GPUMonitoringConfig,LoggerConfig— fromTypedDicttoBaseModel(extra="allow").GpuMetricSnapshotstaysTypedDict(internal data container, not YAML-loaded).Behavior-preserving details worth review attention:
WandbLogger/SwanlabLoggerpreviously splatted the raw dict intowandb.init/swanlab.init; they now passmodel_dump(exclude_none=True)so unsetOptionalfields don't reach the backends as explicitNones, whileextra="allow"passthrough keys (e.g.tags) still flow through — verified in a standalone check.Logger.__init__raises a namedValueErrorwhen a backend is enabled but its sub-config block is absent (previously an opaqueKeyError).load_replay_buffer-style tri-states don't exist here; all defaults mirror current effective behavior.Call sites: ~22 moved to attribute access across algorithms,
sync_rollout_actor,trajectory_collector, SC setup, everyexamples/run_*.py, andresearch/flow_grpo.Both failure classes from the #3916 review are handled up front:
Optionalkeys added with default values at the logger level and inside the nested wandb/tensorboard/mlflow blocks; deep-verified that each referencelogger:block now matchesLoggerConfig.model_dump()exactly (nested levels included).loggerdict literals wrapped inmodel_construct, subscripts converted, one.update()call replaced — no plain dict left to mask a missed call site.Issues
Part of the TypedDict → BaseModel migration tracked by
tests/unit/test_config_v2.py(see #1675 / #2102).Usage
No user-facing YAML change; unknown keys under
logger:continue to load. Enabling a backend without its config block now fails at Logger construction with a clear message.Before your PR is "Ready for review"
exclude_nonewandb-kwargs path, extras passthrough, round-trip)ruff format+checkclean (repo pin 0.9.9);py_compileon all touched files; zero3rdparty/changes (gitlinks verified)