Skip to content

refactor(utils): migrate logger configs to BaseModel - #4278

Merged
yuki-97 merged 10 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-logger
Oct 3, 2026
Merged

yuki-97 merged 10 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-logger

Conversation

@lonexreb

Copy link
Copy Markdown
Contributor

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 in nemo_rl/utils/logger.py — WandbConfig, SwanlabConfig, TensorboardConfig, MLflowConfig, GPUMonitoringConfig, LoggerConfig — from TypedDict to BaseModel(extra="allow"). GpuMetricSnapshot stays TypedDict (internal data container, not YAML-loaded).

Behavior-preserving details worth review attention:

  • WandbLogger/SwanlabLogger previously splatted the raw dict into wandb.init/swanlab.init; they now pass model_dump(exclude_none=True) so unset Optional fields don't reach the backends as explicit Nones, while extra="allow" passthrough keys (e.g. tags) still flow through — verified in a standalone check.
  • Logger.__init__ raises a named ValueError when a backend is enabled but its sub-config block is absent (previously an opaque KeyError).
  • 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, every examples/run_*.py, and research/flow_grpo.

Both failure classes from the #3916 review are handled up front:

  • Reference configs: always-emitted Optional keys added with default values at the logger level and inside the nested wandb/tensorboard/mlflow blocks; deep-verified that each reference logger: block now matches LoggerConfig.model_dump() exactly (nested levels included).
  • Test fixtures: logger dict literals wrapped in model_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"

  • Standalone pydantic semantics checks (nested coercion, exclude_none wandb-kwargs path, extras passthrough, round-trip)
  • ruff format + check clean (repo pin 0.9.9); py_compile on all touched files; zero 3rdparty/ changes (gitlinks verified)
  • CI unit tests (will trigger)

@copy-pr-bot

copy-pr-bot Bot commented Sep 27, 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 0db7ffb

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 29, 2026
@yuki-97 yuki-97 added the CI:L1 Run doctests, unit tests, and functional tests label Sep 29, 2026
@yuki-97

yuki-97 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

/ok to test 0db7ffb

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

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 in nemo_rl/, examples/, research/ and tools/ now reads it by attribute.
  • Backend init kwargs: model_dump(exclude_none=True) passed to wandb.init / swanlab.init still forwards extra keys such as tags.
  • 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.

Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
Comment thread nemo_rl/utils/logger.py Resolved
@yuki-97
yuki-97 force-pushed the refactor/config-v2-logger branch from 0db7ffb to a12f30a Compare September 29, 2026 14:49
@yuki-97

yuki-97 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

/ok to test 6bf4d67

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Sep 29, 2026
@lonexreb

lonexreb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3bd7900

@lonexreb
lonexreb force-pushed the refactor/config-v2-logger branch from 6bf4d67 to 3bd7900 Compare October 1, 2026 05:56
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 1, 2026
…, 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]>
@lonexreb

lonexreb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for another thorough pass @yuki-97 (and the lint commit — built on top of it). All findings addressed:

  • Field defaults per v2 convention: *_enabled = False, monitor_gpus = True, num_val_samples_to_print = 0, gpu_monitoring intervals = 10, and log_nemo_gym_full_result_tables: bool = False (the bool() shim in should_log_nemo_gym_full_result_tables is gone). WandbConfig/SwanlabConfig project/name are required strs; wandb is now Optional like the other backend blocks.
  • Load-time validator: the enabled-without-block checks moved out of Logger.__init__ into a model_validator(mode="after") on LoggerConfig, following RewardPenaltyConfig._require_unwanted_token_ids_when_penalized — this also resolves the ordering concern at setup.py:1976, since a bad config now fails at load before that path runs.
  • tests/unit/utils/test_logger.py (the file I missed): Logger dict configs wrapped in model_validate (nested blocks must coerce); backend-logger configs wrapped in model_construct (keeps minimal {} fixtures working despite required project/name; verified extras like tags still reach wandb.init through model_dump(exclude_none=True)). TensorboardLogger sites left alone — it never reads its cfg.
  • test_setup.py three plain-dict sites wrapped (model_copy(update=...) for the spread-copies), and nested wandb dicts inside model_construct fixtures coerced to WandbConfig in five test files — model_construct doesn't coerce nested dicts, so those would have slipped past the attribute reads in should_log_nemo_gym_full_result_tables.
  • Reference configs: null → false/0 for keys that gained real defaults; deep-verified all six reference logger: blocks still match model_dump() exactly.

CI triggered on 3bd790055e347ddb0e3001b0d69ab45e3ceeec5f.

@lonexreb

lonexreb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 0691c64

@lonexreb

lonexreb commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Update: I got the unit suites running locally (hand-built venv around the repo's Python pin) and ran everything this PR touches — tests/unit/utils/test_logger.py (98/98), tests/unit/test_config_v2.py + tests/unit/test_config_validation.py (1104 passed), and the touched single-controller fixture files (142 + 156 passed). Fixes from that run are in the new commit:

  • LoggerConfig.gpu_monitoring now uses Field(default_factory=GPUMonitoringConfig) — both its fields carry exemplar defaults after your review, so an omitted block is well-defined (same pattern as NonColocatedTeachersConfig).
  • Minimal Wandb/Swanlab test fixtures seed the now-required project/name; Logger fixtures pass the dict to model_validate positionally; sub-config equality asserts compare attributes.
  • Bonus pre-existing bug the validation exposed: test_init_swanlab_only had three @patch decorators but two mock params, so temp_dir silently bound to the WandbLogger mock — fixed.

One unrelated failure in the touched files (test_logs_raw_and_canonical_rollout_throughput) reproduces on pristine main — looks like a timing-sensitivity flake (6.67 vs 20.0 tok/s with mocked time.monotonic), happy to file an issue if useful.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 1, 2026
lonexreb and others added 4 commits October 1, 2026 23:30
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]>
@yuki-97
yuki-97 force-pushed the refactor/config-v2-logger branch from 0691c64 to 7b97134 Compare October 2, 2026 06:32
@yuki-97

yuki-97 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

/ok to test 247d17d

@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 @lonexreb , added some more commits to keep consistency for the current style in the repo and enqueued.

@yuki-97
yuki-97 enabled auto-merge (squash) October 2, 2026 07:42
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Oct 2, 2026
@lonexreb

lonexreb commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Root-caused the sphinx-build failure on this run: the Check for unknown broken links step tripped on two external failures in docs this PR doesn't touch — https://mn.cs.tsinghua.edu.cn/avqa (502 Bad Gateway, guides/grpo-audio) and a one-off RemoteDisconnected from the nsight-systems page on docs.nvidia.com (nsys-profiling). Nothing from this PR's diff. The rerun that's queued should pass once those sites behave; for the recurring offender I've opened #4434 adding the Tsinghua URL to linkcheck_ignore (same treatment as the existing github.com/HF entries), so it stops failing unrelated queued PRs.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 3, 2026
@yuki-97
yuki-97 merged commit 19b245a into NVIDIA-NeMo:main Oct 3, 2026
143 of 146 checks passed
ZhiyuLi-Nvidia pushed a commit that referenced this pull request Oct 27, 2026
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]>
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.

3 participants