rhscope.recipes.grpo

GRPO recipe runner - model-agnostic.

This module wires a validated RecipeConfig to TRL’s GRPOTrainer. Nothing here names a specific model, dataset, or architecture; everything is driven by the recipe. Only this module imports trl and peft - they are optional dependencies (pip install "rhscope[trl]").

Use via the CLI:

rhscope run-recipe recipes/grpo_default.yaml

Or programmatically:

from rhscope.recipes import load_recipe
from rhscope.recipes.grpo import run_grpo_recipe

config = load_recipe("recipes/grpo_default.yaml")
run_grpo_recipe(config)
class rhscope.recipes.grpo.RecipeRunResult(output_dir, global_step, final_hack_rate, monitor_summary=None)[source]

Bases: object

Metadata returned after a recipe finishes.

Variables:
  • output_dir (pathlib.Path) – Directory where checkpoints and logs were written.

  • global_step (int) – Final trainer.state.global_step.

  • final_hack_rate (float | None) – Hacking rate on the eval split after training, or None if the eval split was empty.

  • monitor_summary (dict[str, float] | None) – Aggregate monitor metrics observed during training, or None if no monitor was attached. Keys are the per-step metric names (monitor/mean_score etc.) and values are their final observed value.

Parameters:
output_dir: Path
global_step: int
final_hack_rate: float | None
monitor_summary: dict[str, float] | None = None
rhscope.recipes.grpo.set_global_seed(seed)[source]

Seed the Python, NumPy, and PyTorch RNGs.

Transformers’ set_seed would seed the same RNGs; we duplicate it here so callers can seed without importing Transformers until they need it.

Parameters:

seed (int)

Return type:

None

rhscope.recipes.grpo.build_env(config)[source]

Instantiate the environment specified by config.

Looks up config.name in BaseEnv.registered_envs(). New envs are added by subclassing BaseEnv with a non-default name attribute; they register automatically at import time.

v0.1 ships one env (code_shortcut). The MBPP loader hook here is specific to that env; user-defined envs with other data sources should construct their own tasks directly.

Parameters:

config (EnvConfig)

Return type:

BaseEnv

rhscope.recipes.grpo.run_grpo_recipe(config, *, env=None)[source]

Execute a full GRPO run from a validated recipe.

Parameters:
  • config (RecipeConfig) – Validated recipe.

  • env (BaseEnv | None) – Optional pre-built environment (useful for tests and for sharing a dataset across multiple recipe runs). If omitted, the env is constructed from config.env.

Returns:

RecipeRunResult with the output directory, final step, and the hacking rate measured on the env’s eval split (if non-empty).

Raises:

RuntimeError – If TRL or PEFT are not installed, or if the environment is empty.

Return type:

RecipeRunResult