Skip to content

refactor(distributed): migrate ClusterConfig from TypedDict to BaseModel - #3916

Merged
yuki-97 merged 5 commits into
NVIDIA-NeMo:mainfrom
lonexreb:refactor/config-v2-cluster
Oct 1, 2026
Merged

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

Conversation

@lonexreb

Copy link
Copy Markdown
Contributor

What does this PR do ?

Migrates ClusterConfig (nemo_rl/distributed/virtual_cluster.py) from TypedDict to pydantic BaseModel(extra="allow"), following the pattern established in #2518. This is the first PR in a utils-layer migration series (ClusterConfig → CheckpointingConfig/PretrainedCheckpointConfig → LoggerConfig), complementing the in-flight policy-config series (#3197, @NolenLiang) and the generation-config migration (#3289, @shuyixiong) — happy to coordinate scope if either of those plans to absorb these classes.

Changes:

  • NotRequired fields (master_port_range_low/high, segment_size) become Optional[...] = None. No new non-None defaults, so tests/unit/test_config_v2.py and tests/unit/reference_configs/ are unaffected.
  • All call sites (~77 across grpo, grpo_sync, ppo, sft, dpo, rm, distillation, xtoken, single-controller setup, utils, eval) move from key access to attribute access; .get("segment_size") → .segment_size (identical None semantics).
  • Test fixtures built via MasterConfig.model_construct(...) bypass validation and would leave cluster as a plain dict, so their cluster values are wrapped in ClusterConfig.model_validate({...}). Empty {} placeholders that no exercised path touches are left as plain dicts.

Issues

Part of the TypedDict → BaseModel config migration (v2) tracked by tests/unit/test_config_v2.py; related discussion in #1675 / #2102.

Usage

No user-facing YAML change. Unknown/legacy keys under cluster: continue to load (extra="allow"); missing gpus_per_node/num_nodes now fail at config validation time with a clear pydantic error instead of a KeyError mid-setup.

Before your PR is "Ready for review"

  • Standalone pydantic semantics check of the migrated class (required fields enforced, extra keys preserved, optional defaults, model_dump round-trip)
  • ruff format + ruff check clean (ruff 0.9.9, repo pin); py_compile on all touched files
  • CI unit tests (dev machine cannot run the suite — Python pin; will trigger CI)

@lonexreb
lonexreb requested review from a team as code owners August 30, 2026 23:46
@copy-pr-bot

copy-pr-bot Bot commented Aug 30, 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 e3980a1

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Sep 2, 2026
@lonexreb
lonexreb force-pushed the refactor/config-v2-cluster branch from e3980a1 to 982f295 Compare September 10, 2026 04:37
@lonexreb
lonexreb requested review from a team as code owners September 10, 2026 04:37
@lonexreb

Copy link
Copy Markdown
Contributor Author

/ok to test 982f295

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-maintainers Waiting on maintainers to respond label Sep 10, 2026
@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 11, 2026
@yuki-97

yuki-97 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

/ok to test 982f295

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

@lonexreb thanks for helping on the migration!

changes LGTM but there seem to have some places missing to change, these could be caught by CI. also there's a lint fail need to fix.

Comment thread 3rdparty/Automodel-workspace/Automodel Resolved
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-customer Waiting on the original author to respond label Sep 12, 2026
@lonexreb
lonexreb force-pushed the refactor/config-v2-cluster branch from 982f295 to a2aa92d Compare September 16, 2026 03:54
@lonexreb

Copy link
Copy Markdown
Contributor Author

/ok to test a2aa92d

@lonexreb

Copy link
Copy Markdown
Contributor Author

Thanks for the review @yuki-97! Fixed both issues:

  • 3rdparty submodule changes reverted — those pointer bumps were accidental (a git add -u on a workspace with locally-updated submodules); the PR now carries zero 3rdparty/ changes, gitlinks match main exactly.
  • "Lint" failure root-caused — it wasn't a style issue: the stale Megatron-Bridge pointer resolved emerging-optimizers to v0.2.0 while the lockfile expects v0.3.0, so uv failed dependency resolution before pre-commit even ran. Reverting the submodule pointers fixes lint, uv lock check, and the submodule fast-forward check in one go.

Also rebased onto today's main and re-swept for new dict-style cluster_config accesses (the earlier rebase had already picked up mpo.py / sft_v2.py; nothing new this time). If CI surfaces any call site I still missed, happy to fix promptly.

@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Sep 16, 2026
@yuki-97 yuki-97 added CI:L1 Run doctests, unit tests, and functional tests and removed CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) labels Sep 17, 2026
@yuki-97

yuki-97 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

/ok to test a2aa92d

@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 , I've triggered CI again and also let claude found some places that need change.
lmk if you need my help to also fix something if CI fails, so that we might get it merged more quickly.

Comment thread nemo_rl/distributed/virtual_cluster.py Resolved
Comment thread nemo_rl/distributed/virtual_cluster.py Resolved
Comment thread tests/unit/algorithms/test_grpo.py Resolved
Comment thread nemo_rl/algorithms/mpo.py Resolved
@yuki-97
yuki-97 force-pushed the refactor/config-v2-cluster branch from 06073d8 to a88005e Compare September 17, 2026 09:02
@yuki-97

yuki-97 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

/ok to test a88005e

lonexreb and others added 5 commits September 30, 2026 08:27
Part of the config v1 -> v2 migration (pattern established in NVIDIA-NeMo#2518;
runs alongside NVIDIA-NeMo#3197 for policy configs and NVIDIA-NeMo#3289 for generation
configs). First PR in a utils-layer series: ClusterConfig now,
CheckpointingConfig and LoggerConfig to follow.

- ClusterConfig(TypedDict) -> ClusterConfig(BaseModel, extra="allow");
  NotRequired fields become Optional[...] = None. No new non-None
  defaults, so tests/unit/test_config_v2.py and the reference configs
  are unaffected.
- All call sites move from key access (cluster_config["gpus_per_node"],
  cluster_config.get("segment_size")) to attribute access across grpo,
  grpo_sync, ppo, sft, dpo, rm, distillation, xtoken, single-controller
  setup, utils, and eval.
- Test fixtures built via MasterConfig.model_construct bypass pydantic
  validation and would keep cluster as a plain dict, so their cluster
  values are wrapped in ClusterConfig.model_validate(...). Fixtures that
  never touch cluster (empty {} placeholders) are left as-is.
- Verified: py_compile on all touched files; standalone pydantic check
  of the migrated class (required fields enforced, extra keys allowed,
  optional defaults, model_dump round-trip); ruff format + check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
Signed-off-by: Yuki Huang <[email protected]>
… reference configs

Applies all six findings from the NVIDIA-NeMo#3916 review:

- single_controller_utils/setup.py: convert the last
  getattr(master_config, "cluster", {}).get("segment_size") to
  attribute access (would have raised AttributeError on every SC run).
- reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so add
  master_port_range_low/high: null to dpo/rm/sft.yaml and all three
  optional keys to eval.yaml. Verified all seven reference cluster
  blocks now cover exactly the keys ClusterConfig emits.
- research/template_project/single_update.py (4 reads) and
  research/flow_grpo/run_flow_grpo.py (4 reads, found by a residual
  sweep): subscripts on a validated ClusterConfig -> attributes.
- test_grpo/test_ppo/test_mpo/test_grpo_checkpoint_engine: item
  assignments and subscript asserts on the now-real ClusterConfig ->
  attribute access.
- test_setup/test_ppo_setup: plain dicts assigned over the validated
  cluster field -> ClusterConfig.model_validate({...}) so missed call
  sites can no longer hide behind a dict that still answers .get.
- test_mpo _cluster_config helper returns ClusterConfig(...) instead
  of an annotated dict.

Signed-off-by: Shubhankar Tripathy <[email protected]>
@yuki-97
yuki-97 force-pushed the refactor/config-v2-cluster branch from 0610acc to 5dc4b4a Compare September 30, 2026 15:32
auto-merge was automatically disabled September 30, 2026 15:32

Head branch was pushed to by a user without write access

@yuki-97

yuki-97 commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

/ok to test 5dc4b4a

@yuki-97
yuki-97 enabled auto-merge (squash) September 30, 2026 15:33
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 1, 2026
Third PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 ClusterConfig,
NVIDIA-NeMo#4152 checkpointing configs; pattern from NVIDIA-NeMo#2518).

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]>
@yuki-97
yuki-97 merged commit eeb8830 into NVIDIA-NeMo:main Oct 1, 2026
151 of 154 checks passed
@svcnvidia-nemo-ci svcnvidia-nemo-ci removed the waiting-on-customer Waiting on the original author to respond label Oct 1, 2026
yuki-97 pushed a commit to lonexreb/RL that referenced this pull request Oct 2, 2026
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]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 5, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 5, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 10, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 10, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 18, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 18, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 24, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 24, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 28, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 28, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 31, 2026
…Config to BaseModel

Second PR in the utils-layer config v1 -> v2 series (NVIDIA-NeMo#3916 migrated
ClusterConfig; pattern from NVIDIA-NeMo#2518, alongside NVIDIA-NeMo#3197/NVIDIA-NeMo#3289).

Schema:
- Both classes become BaseModel(extra="allow"); NotRequired fields
  become Optional[...] = None.
- Hidden call-site defaults are centralized on the class exactly as
  they behave today: save_optimizer=True, save_data_plane=False,
  save_consolidated=False, model_cache_dir="", model_repo_id="",
  is_peft=False, is_async=False.
- model_save_format stays Optional[str] = None on purpose: the DTensor
  v1 worker rejects any non-None value, and the automodel layers apply
  their own "safetensors" fallback (CheckpointManager keeps that
  resolution, now explicit instead of a .get default).
- load_replay_buffer stays tri-state (Optional[bool] = None): the
  async-GRPO restore path only opts out on an explicit False.

Call sites (~85 across all algorithms, SC utils, lm_policy) move from
key access / .get() to attribute access. Two deliberate dict
boundaries are preserved with model_dump():
- policy_config["pretrained_checkpoint"] hand-off (PolicyConfig is
  still TypedDict-shaped; Megatron setup consumes dict keys), and
- checkpointing_cfg forwarded to save_checkpoint workers (the
  automodel checkpoint layer consumes .items()/.get()).

Tests: fixtures built via model_construct bypass validation, so
checkpointing dict literals are wrapped in
CheckpointingConfig.model_construct(**{...}) (missing required fields
now raise AttributeError where they raised KeyError before);
CheckpointManager unit tests validate their full config dicts via
model_validate.

No exemplar YAML or reference-config changes; class defaults mirror
the documented/exemplar values, so tests/unit/test_config_v2.py is
unaffected.

Verified: py_compile on all touched files; standalone pydantic
semantics checks (exemplar blocks round-trip, sft.yaml block keeps
model_save_format=None, nested pretrained_checkpoint coerces and dumps
back, extra keys preserved, model_construct default-fill); ruff format
+ check clean.

Signed-off-by: Shubhankar Tripathy <[email protected]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Oct 31, 2026
…e configs and residual call sites

Rebase over main's removal of the automodel-only fields from
CheckpointingConfig (moved under policy.dtensor_cfg) — the schema now
carries only the algorithm-level fields, and the new
_AUTOMODEL_ONLY_CHECKPOINT_FIELDS rejection guard is kept, adapted to
read config.model_extra since legacy keys now arrive via
extra="allow" rather than the field set. The model_dump() worker
boundary in lm_policy/lm_value is dropped along with the
checkpointing_cfg parameter main removed.

Also applies the two failure classes from the NVIDIA-NeMo#3916 review
pre-emptively:

- Reference configs: Optional fields are always emitted by
  model_dump() where NotRequired keys were omitted, so the always-
  emitted checkpointing keys are added with their default values to
  all six reference blocks; verified each block now covers exactly
  the keys the model emits.
- Residual dict-style sites: converted subscripts/get on the validated
  checkpointing field in the example run scripts, single_controller,
  SC setup, flow_grpo, and test files; wrapped dict-over-field
  assignments (test_ppo, test_sft_v2) in
  CheckpointingConfig.model_construct so missed call sites cannot hide
  behind a dict that still answers .get.

Signed-off-by: Shubhankar Tripathy <[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