Skip to content

refactor(policy): migrate common config leaves to BaseModel - #3197

Open
NolenLiang wants to merge 9 commits into
mainfrom
nliang/typeddict-to-basemodel-policy-common
Open

NolenLiang wants to merge 9 commits into
mainfrom
nliang/typeddict-to-basemodel-policy-common

Conversation

@NolenLiang

Copy link
Copy Markdown
Contributor

Summary

This is the first PR in the policy config migration series.

  • Migrate common policy config leaves from TypedDict to Pydantic BaseModel with extra="allow":
    • sequence packing
    • dynamic batching
    • tokenizer
    • reward model
    • draft model
    • router replay
    • PyTorch optimizer and scheduler
  • Update Policy, Value, DTensor, Automodel, Megatron, TQ, and reward-model environment call sites to
    use attribute access.
  • Update example configs, reference configs, and test fixtures.
  • Support both direct and sequential PyTorch scheduler configurations.

Compatibility

This PR intentionally does not migrate top-level PolicyConfig / ValueConfig or backend-specific DTensor, Automodel, and Megatron configs. Those will be handled in follow-up PRs.

Validation

  • tests/unit/test_config_v2.py and config validation: 509 passed, 6 skipped
  • Targeted MCore tests: 30 passed
  • Targeted Automodel tests: 44 passed
  • Common policy leaf tests: 12 passed
  • Teacher, DPO, and RM regression tests: 14 passed
  • Ruff format and lint checks passed
  • Python compilation and git diff --check passed

@NolenLiang
NolenLiang requested review from a team as code owners July 14, 2026 15:23
@copy-pr-bot

copy-pr-bot Bot commented Jul 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.

@NolenLiang NolenLiang added the CI:L1 Run doctests, unit tests, and functional tests label Jul 14, 2026
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 30d17e1

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 4c1c844

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 1a95e22

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test c24e3b9

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 57e9aca

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 86e04de

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test d1c6dee

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 25aa652

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 404216b

Comment thread nemo_rl/models/policy/__init__.py Resolved
@NolenLiang
NolenLiang force-pushed the nliang/typeddict-to-basemodel-policy-common branch from 404216b to 2f91f5b Compare August 4, 2026 14:22
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 2f91f5b

@NolenLiang
NolenLiang force-pushed the nliang/typeddict-to-basemodel-policy-common branch from 2f91f5b to f705f83 Compare August 5, 2026 03:17
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test f705f83

@NolenLiang
NolenLiang force-pushed the nliang/typeddict-to-basemodel-policy-common branch from f705f83 to 9779ad5 Compare August 5, 2026 16:30
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 9779ad5

@NolenLiang
NolenLiang force-pushed the nliang/typeddict-to-basemodel-policy-common branch from 9779ad5 to 4428b7c Compare August 18, 2026 07:00
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 4428b7c

@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 90718fc

…asemodel-policy-common

# Conflicts:
#	nemo_rl/algorithms/grpo.py
#	nemo_rl/models/policy/__init__.py
@NolenLiang

Copy link
Copy Markdown
Contributor Author

/ok to test 67f0bce

lonexreb added a commit to lonexreb/RL that referenced this pull request Sep 10, 2026
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]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Sep 16, 2026
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]>
yuki-97 pushed a commit to lonexreb/RL that referenced this pull request Sep 17, 2026
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]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Sep 27, 2026
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]>
lonexreb added a commit to lonexreb/RL that referenced this pull request Sep 27, 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]>
yuki-97 pushed a commit to lonexreb/RL that referenced this pull request Sep 30, 2026
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]>
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 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 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 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 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 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 Nov 7, 2026
Merge origin/main (49 commits) to clear the conflicts with NVIDIA-NeMo#5009 and the
"Check if PR branch is up to date" gate. Code main moved into
rollout_checkpointing/ and main's new tests get the same attribute access
as the rest of this PR.

Review fixes:
- load_replay_buffer is a plain bool defaulting to True; readers test
  `not load_replay_buffer`, and the reference configs dump `true`.
- save_period defaults to 10; note that higher_is_better is only read
  when metric_name is set.
- PretrainedCheckpointConfig stays a TypedDict until PolicyConfig migrates
  (NVIDIA-NeMo#3197), so setup hands it over unchanged and
  PolicyConfig.pretrained_checkpoint keeps its TypedDict annotation.
- Indent the CheckpointingConfig docstring under Attributes: and document
  save_period, checkpoint_must_save_by and pretrained_checkpoint.
- Tests build CheckpointingConfig with keyword arguments.
- Drop the defaults-only CheckpointManager test (NVIDIA-NeMo#5009 testing rules).

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

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants