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:
objectMetadata 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
Noneif the eval split was empty.monitor_summary (dict[str, float] | None) – Aggregate monitor metrics observed during training, or
Noneif no monitor was attached. Keys are the per-step metric names (monitor/mean_scoreetc.) and values are their final observed value.
- Parameters:
- rhscope.recipes.grpo.set_global_seed(seed)[source]¶
Seed the Python, NumPy, and PyTorch RNGs.
Transformers’
set_seedwould 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.nameinBaseEnv.registered_envs(). New envs are added by subclassingBaseEnvwith a non-defaultnameattribute; 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.
- 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:
RecipeRunResultwith 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: