trinity.common.rewards package

Submodules

Module contents

Reward functions for RFT

class trinity.common.rewards.RewardFn(**kwargs)[source]

Bases: ABC

Base Reward Function Class.

abstract __init__(**kwargs) None[source]
class trinity.common.rewards.RMGalleryFn(reward_name, **kwargs)[source]

Bases: RewardFn

Reward Function from RMGallery. https://github.com/modelscope/RM-Gallery

__init__(reward_name, **kwargs)[source]
class trinity.common.rewards.AccuracyReward(answer_parser: Callable[[str], str] | None = None)[source]

Bases: RewardFn

A reward function that rewards correct answers. Ref: https://github.com/huggingface/open-r1/blob/main/src/open_r1/rewards.py

__init__(answer_parser: Callable[[str], str] | None = None)[source]
class trinity.common.rewards.CountDownRewardFn[source]

Bases: RewardFn

A reward function that rewards for countdown task. Ref: Jiayi-Pan/TinyZero verl/utils/reward_score/countdown.py

__init__()[source]
class trinity.common.rewards.FormatReward(pattern: str | None = None)[source]

Bases: RewardFn

A reward function that checks if the reasoning process is enclosed within <think> and </think> tags, while the final answer is enclosed within <answer> and </answer> tags. Ref: https://github.com/huggingface/open-r1/blob/main/src/open_r1/rewards.py

__init__(pattern: str | None = None)[source]
class trinity.common.rewards.MathRewardFn(answer_parser=<function simple_answer_parser>, pattern='.*?<think>.*?</think>\\s*<answer>.*?</answer>\\s*$')[source]

Bases: RewardFn

A reward function that rewards for math task.

DEFAULT_FORMAT_PATTERN = '.*?<think>.*?</think>\\s*<answer>.*?</answer>\\s*$'
DEFAULT_ANSWER_PARSER() str
__init__(answer_parser=<function simple_answer_parser>, pattern='.*?<think>.*?</think>\\s*<answer>.*?</answer>\\s*$') None[source]
class trinity.common.rewards.MathBoxedRewardFn(**kwargs)[source]

Bases: RewardFn

A reward function that rewards for math task.

__init__(**kwargs) None[source]
class trinity.common.rewards.MathDAPORewardFn(enable_overlong_penalty: bool | None = None, penalty_factor: float | None = None, max_response_length: int | None = None, cache_length: int | None = None)[source]

Bases: RewardFn

A reward function that follows the definition in DAPO for math task.

__init__(enable_overlong_penalty: bool | None = None, penalty_factor: float | None = None, max_response_length: int | None = None, cache_length: int | None = None) None[source]
compute_overlong_penalty(response_token)[source]