nemo_rl.experience.reward_penalties#
Shared reward calculations and logging for verified capture rows.
Capture observations retain each valid row’s final reward until its group is consumed, allowing exact pooled medians, histograms and agent reward logging. Optional full-result JSON is retained only when full-result logging is enabled.
Module Contents#
Classes#
Scored-text and original-prompt checks saved with a rollout attempt. |
|
One supported penalty’s configuration, counter and logging contract. |
|
Active effort parameters that affect saved reward interpretation. |
|
Semantic checkpoint identity; user-config extras are never persisted. |
|
Agent identity and optional full-result table data, without raw reward. |
|
A valid finalized sample’s reward, retained until group consumption. |
Functions#
Detect nonempty reasoning copied into immediately adjacent content. |
|
Detect missing supported final content, except a final function call. |
|
Return whether the configured low-effort adjustment is active. |
|
Classify the original rollout input using the standard last-user rule. |
|
Return shaped reward and length term, preserving negative reward semantics. |
|
Check full generated sequences, including their terminal tokens. |
|
Validate the optional log context stored with an unfinished attempt. |
|
Evaluate available checks before sealing, without changing the raw reward. |
|
Shape, then penalize. Token IDs and spans must already be verified by Gym. |
|
Pool per-group finalizer counts and per-row rewards over valid rows. |
|
Build the existing agent full-result table rows using final rewards. |
Data#
API#
- nemo_rl.experience.reward_penalties.has_duplicated_reasoning(
- output_items: list[dict[str, Any]],
Detect nonempty reasoning copied into immediately adjacent content.
- nemo_rl.experience.reward_penalties.has_empty_final_answer(
- output_items: list[dict[str, Any]],
Detect missing supported final content, except a final function call.
- nemo_rl.experience.reward_penalties.effort_shaping_enabled(
- config: nemo_rl.experience.rollouts.EffortLevelsConfig | None,
Return whether the configured low-effort adjustment is active.
- nemo_rl.experience.reward_penalties.is_low_effort(
- row: dict[str, Any],
- config: nemo_rl.experience.rollouts.EffortLevelsConfig,
Classify the original rollout input using the standard last-user rule.
- nemo_rl.experience.reward_penalties.shape_effort_reward(
- reward: float,
- *,
- length: int,
- config: nemo_rl.experience.rollouts.EffortLevelsConfig,
Return shaped reward and length term, preserving negative reward semantics.
- nemo_rl.experience.reward_penalties.has_unwanted_tokens(
- generations: collections.abc.Iterable[collections.abc.Container[int]],
- unwanted_ids: collections.abc.Sequence[int],
Check full generated sequences, including their terminal tokens.
- class nemo_rl.experience.reward_penalties.RewardChecks[source]#
Scored-text and original-prompt checks saved with a rollout attempt.
- duplicated_reasoning: bool#
None
- empty_final_answer: bool#
None
- low_effort: bool#
None
- class nemo_rl.experience.reward_penalties.CapturePenalty[source]#
One supported penalty’s configuration, counter and logging contract.
- name: str#
None
- flag: str#
None
- metric: str#
None
- enabled: collections.abc.Callable[[nemo_rl.algorithms.grpo.RewardPenaltyConfig], bool]#
None
- text_match: collections.abc.Callable[[nemo_rl.experience.reward_penalties.RewardChecks], bool] | None#
None
- nemo_rl.experience.reward_penalties.CAPTURE_PENALTIES#
()
- class nemo_rl.experience.reward_penalties.EffortRewardSettings[source]#
Active effort parameters that affect saved reward interpretation.
- low_weight: float#
None
- low_penalty: float#
None
- low_ub: int#
None
- low_string: str#
None
- class nemo_rl.experience.reward_penalties.CaptureRewardSettings[source]#
Semantic checkpoint identity; user-config extras are never persisted.
- enabled_penalties: tuple[str, ...]#
None
- unwanted_tokens: tuple[int, ...]#
None
- effort: nemo_rl.experience.reward_penalties.EffortRewardSettings | None#
None
- classmethod from_configs(
- penalties: nemo_rl.algorithms.grpo.RewardPenaltyConfig,
- effort: nemo_rl.experience.rollouts.EffortLevelsConfig | None,
- classmethod from_state(
- value: object,
Validate a version-1 record written by
to_state.Sidecars always write version 1; the live config never passes through this path (see
from_configs). Existing model defaults fill absent config fields. A future change to reward semantics must explicitly version/migrate this projection.
- class nemo_rl.experience.reward_penalties.RewardLogContext[source]#
Agent identity and optional full-result table data, without raw reward.
- agent_name: str#
None
- full_result_json: str | None#
None
- class nemo_rl.experience.reward_penalties.FinalizedReward[source]#
A valid finalized sample’s reward, retained until group consumption.
- sample_id: str#
None
- rollout_id: str#
None
- reward: float#
None
- log_context: nemo_rl.experience.reward_penalties.RewardLogContext | None#
None
- classmethod from_state(
- value: object,
Validate checkpoint observations before using them for metrics.
- nemo_rl.experience.reward_penalties.parse_reward_log_context(
- value: object,
Validate the optional log context stored with an unfinished attempt.
- nemo_rl.experience.reward_penalties.compute_reward_checks(
- result: dict[str, Any],
- row: dict[str, Any],
- effort_config: nemo_rl.experience.rollouts.EffortLevelsConfig | None,
Evaluate available checks before sealing, without changing the raw reward.
- nemo_rl.experience.reward_penalties.finalize_capture_reward(
- reward: float,
- *,
- checks: nemo_rl.experience.reward_penalties.RewardChecks | None,
- penalty_config: nemo_rl.algorithms.grpo.RewardPenaltyConfig | None,
- effort_config: nemo_rl.experience.rollouts.EffortLevelsConfig | None,
- token_ids: list[int],
- link_spans: list[tuple[str, int, int]],
Shape, then penalize. Token IDs and spans must already be verified by Gym.
- nemo_rl.experience.reward_penalties.CAPTURE_PENALTY_METRICS#
None
- nemo_rl.experience.reward_penalties.aggregate_capture_reward_metrics(
- metrics: dict[str, list[float]],
- observations: collections.abc.Sequence[nemo_rl.experience.reward_penalties.FinalizedReward],
Pool per-group finalizer counts and per-row rewards over valid rows.
metricsholds the per-group finalizer metrics of the consumed groups;observationsholds one retained reward per valid row of those groups. Rates are computed over valid rows, never averaged across groups.
- nemo_rl.experience.reward_penalties.capture_reward_result_tables(
- observations: collections.abc.Sequence[nemo_rl.experience.reward_penalties.FinalizedReward],
Build the existing agent full-result table rows using final rewards.