Repository navigation
Open
Labels
community-requestenhancementNew feature or requestt-dataclasswaiting-on-maintainersWaiting on maintainers to respondx-tencent
Description
Currently, nemo-rl uses TypedDict to host the config options:
Lines 115 to 177 in b238e41
| class GRPOConfig(TypedDict): | |
| num_prompts_per_step: int | |
| num_generations_per_prompt: int | |
| max_num_epochs: int | |
| max_num_steps: int | |
| max_rollout_turns: int | |
| normalize_rewards: bool | |
| use_leave_one_out_baseline: bool | |
| val_period: int | |
| val_batch_size: int | |
| val_at_start: bool | |
| max_val_samples: int | |
| seed: int | |
| async_grpo: NotRequired[AsyncGRPOConfig] | |
| overlong_filtering: NotRequired[bool] | |
| # whether to enable dynamic sampling, i.e. | |
| # whether to discard prompts whose rewards have zero standard deviation | |
| use_dynamic_sampling: bool | |
| # When using dynamic sampling, the maximum number of batches to generate | |
| # before throwing an error | |
| dynamic_sampling_max_gen_batches: NotRequired[int] | |
| # When using dynamic sampling, generation prompt batch size will equal | |
| # num_prompts_per_step * batch_multiplier | |
| batch_multiplier: NotRequired[float] | |
| reward_shaping: RewardShapingConfig | |
| reward_scaling: RewardScalingConfig | |
| class GRPOSaveState(TypedDict): | |
| consumed_samples: int | |
| current_step: int | |
| current_epoch: int | |
| total_steps: int | |
| total_valid_tokens: int # Track total number of non-padding tokens during training | |
| val_reward: NotRequired[ | |
| float | |
| ] # Optional field - may not be present during training | |
| def _default_grpo_save_state() -> GRPOSaveState: | |
| return { | |
| "consumed_samples": 0, | |
| "current_step": 0, | |
| "current_epoch": 0, | |
| "total_steps": 0, | |
| "total_valid_tokens": 0, | |
| "val_reward": -99999999.0, | |
| } | |
| class GRPOLoggerConfig(LoggerConfig): | |
| num_val_samples_to_print: int # number of val samples to print to stdout | |
| class MasterConfig(TypedDict): | |
| policy: PolicyConfig | |
| loss_fn: ClippedPGLossConfig | |
| env: dict[str, Any] | |
| data: DataConfig | |
| grpo: GRPOConfig | |
| logger: GRPOLoggerConfig | |
| cluster: ClusterConfig | |
| checkpointing: CheckpointingConfig |
We can consider to use dataclass to host these options like:
@dataclass
class GRPOConfig:
num_prompts_per_step: int
num_generations_per_prompt: int
max_num_epochs: int
max_num_steps: int
# ...It has several benifits, like, more friendly for type checking for pyrefly/mypy, and ease of development, e.g., you can directly access config.logger.log_dir with type hints in IDE/editor, instead of typing config["logger"]["log_dir"]. We may also add some runtime validation logic in the __post_init__ dunder for dataclass.
The dataclass could be converted from omegaconf using to_object method.
Reacted by coderabbitai
Metadata
Metadata
Assignees
Labels
community-requestenhancementNew feature or requestt-dataclasswaiting-on-maintainersWaiting on maintainers to respondx-tencent
Activity
coderabbitai commentedon Dec 21, 2025
📝 CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
Examples
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord or schedule a call!
terrykong commentedon Dec 21, 2025
Hi @xuantengh . I expected this question to come to us eventually :)
So I'm not opposed to dataclasses, in fact there are benefits to using dataclasses (e.g., dot getters). Let me first share some of the initial motivation for typeddicts and maybe we can see if we can come out of this with anything actionable.
Initially, we wanted something very minimal and flexible. An example would be if someone has a yaml that looks different from what we expect because:
we wouldn't want to error out because the structure was different, so long as they had the necessary keys/values. TypedDict's being hints gave us enough to document the config and let a static type hint tool analyze our code, while not getting in the way with "version skew" of configs.
Dataclasses offer lots of goodies and are more friendly to IDEs plus having a way to post init, so I agree those would be nice, but one thing they do not offer out of the box is this key mismatch.
It's definitely possible to design a solution with dataclasses that deals with this key mismatch, but I'd like to understand what thing we can help solve by doing so. Is this nice-to-have for you or blocking you in some way? Would love to hear more about how this can help
xuantengh commentedon Dec 22, 2025
Thanks for your patient explanation about the backward compatiblity consideration for chosing
TypedDict.Yeah, it is just a nice-to-have feature. It does not block anything, and I'm happy with
TypedDictas well. Feel free to close this if this is not planned at least right now.terrykong commentedon Dec 22, 2025
No worries. Thanks for raising. I think we can keep this issue open for now in case there are more opinions on this.