Guide for checkpointing — saving, loading, and resuming training with CheckpointRecord. Use when the user asks about saving weights, resuming training, checkpoint management, or the checkpoint lifecycle.
日本語の概要は準備中です。原文の説明を表示しています。
Set up and run reinforcement learning with verifiable rewards (RLVR/GRPO) for math, code, or custom environments using the Tinker API. Use when the user wants to do RL training, GRPO, reward-based optimization, or train with verifiable rewards.
インストールする前に、エージェントに与えられる指示の中身を確認できます。
Help the user set up and run RL training with verifiable rewards using the Tinker API.
Ask the user (if not already specified):
meta-llama/Llama-3.1-8B-Instruct, Qwen/Qwen3-8B)Read these files for patterns:
tinker_cookbook/recipes/rl_basic.py — Minimal RL example (GSM8K)tinker_cookbook/recipes/math_rl/train.py — Full math RL with multiple environments and loss functionstinker_cookbook/recipes/code_rl/train.py — Code generation RL with sandbox executiontinker_cookbook/recipes/rubric/train.py — Rubric-graded RL with LLM scoringtinker_cookbook/rl/train.py — Core RL training looptinker_cookbook/rl/types.py — Env, EnvGroupBuilder, RLDatasetBuilderdocs/rl/rl-basic.mdx — Getting starteddocs/rl/rl-envs.mdx — Custom environmentsdocs/rl/rl-hyperparams.mdx — Hyperparameter guidanceRL requires an environment that produces rewards. Key patterns:
Built-in environments:
Gsm8kDatasetBuilder — Grade-school math (from recipes/math_rl/math_env.py)ArithmeticDatasetBuilder — Simple arithmeticDeepMathDatasetBuilder, PolarisDatasetBuilder — Advanced mathDeepCoderDatasetBuilder — Code generation with sandboxRubricDatasetBuilder — Rubric-graded tasksCustom environments:
Implement the Env protocol from tinker_cookbook/rl/types.py. Key points:
Env objects are single-use (no reset method)EnvGroupBuilder each batchfloat rewardgroup_size: Number of rollouts per prompt (typically 4-16). Advantages are centered within each group.groups_per_batch (or batch_size): Number of problems per batchmax_tokens: Maximum generation lengthlearning_rate: Typically 1e-5 to 4e-5 for RLkl_penalty_coef: KL penalty against reference model (0.0 = no penalty)temperature: Sampling temperature (default 1.0)rollout_error_tolerance: Tolerance for rollout errors (False = crash on any error, True = retry failed trajectories with default budget, RetryOnFailure(max_retries=5) = custom retry budget). Error counts logged as rollout_errors/* metrics.importance_sampling — Default, on-policyppo — Proximal Policy Optimization (clipped)cispo — Conservative Importance Sampling PPOdro — Distributionally Robust Optimizationloss_fn and loss_fn_config parametersFor overlapping sampling and training:
async_config=AsyncConfig(
max_steps_off_policy=cli_config.max_steps_off_policy,
groups_per_batch=cli_config.groups_per_batch,
)
Follow the pattern from rl_basic.py / math_rl/train.py:
import asyncio
import chz
from tinker_cookbook import cli_utils, model_info
from tinker_cookbook.rl import train
def build_config_blueprint() -> chz.Blueprint[train.Config]:
model_name = "meta-llama/Llama-3.1-8B-Instruct"
renderer_name = model_info.get_recommended_renderer_name(model_name)
# Configure your dataset builder with environment
builder = ... # e.g., Gsm8kDatasetBuilder(...)
return chz.Blueprint(train.Config).apply({
"model_name": model_name,
"renderer_name": renderer_name,
"log_path": "/tmp/tinker-examples/my_rl_run",
"dataset_builder": builder,
"learning_rate": 4e-5,
"max_tokens": 256,
"eval_every": 20,
})
def main(config: train.Config):
cli_utils.check_log_dir(config.log_path, behavior_if_exists="ask")
asyncio.run(train.main(config))
For the full CLI pattern with @chz.chz config class, see recipes/math_rl/train.py.
python -m tinker_cookbook.recipes.<recipe_name>
Override: python -m tinker_cookbook.recipes.<recipe_name> env=gsm8k group_size=16 learning_rate=4e-5
If you created a new recipe, add a smoke test so CI catches regressions:
# tests/recipes/test_recipe_<name>.py
import pytest
from tests.helpers import run_recipe
@pytest.mark.integration
def test_<recipe_name>():
run_recipe(
"tinker_cookbook.recipes.<recipe_name>.train",
["behavior_if_log_dir_exists=delete", "groups_per_batch=4", "group_size=2"],
)
run_recipe() automatically passes max_steps=2 so the recipe runs 2 training steps and exits. For environment logic (reward grading, env setup), add unit tests as *_test.py next to the source:
tinker_cookbook/recipes/math_rl/math_env_test.pyAfter training, export weights using the tinker_cookbook.weights API:
from tinker_cookbook import weights
adapter_dir = weights.download(tinker_path="tinker://run-id/sampler_weights/final", output_dir="./adapter")
weights.build_hf_model(base_model="meta-llama/Llama-3.1-8B-Instruct", adapter_path=adapter_dir, output_path="./model")
weights.publish_to_hf_hub(model_path="./model", repo_id="user/my-finetuned-model")
Env objects are single-use — always create fresh envs via buildergroup_size matters for variance reductionmax_tokens too small truncates reasoning; too large wastes computegroups_per_batch for debugging, scale up for real runsnum_substeps > 1 for very large batches to split optimizer stepsまだレビューはありません。使ってみた感想をお寄せください。
概要と使いどころ
Guide for checkpointing — saving, loading, and resuming training with CheckpointRecord. Use when the user asks about saving weights, resuming training, checkpoint management, or the checkpoint lifecycle.
日本語の概要は準備中です。原文の説明を表示しています。
Guide for testing conventions and CI pipelines — unit tests, integration smoke tests, pytest markers, and GitHub Actions workflows. Use when the user asks about testing, CI, running tests, or adding tests for a recipe.
日本語の概要は準備中です。原文の説明を表示しています。
Guide for using completers — TokenCompleter and MessageCompleter for text generation during RL rollouts and evaluation. Use when the user asks about generating text, completing messages, or using completers in RL environments.
日本語の概要は準備中です。原文の説明を表示しています。
Guide for contributing to the tinker-cookbook repo — development setup, code style, type checking, PR process, and design conventions. Use when the user asks about how to contribute, set up the dev environment, code style, or project conventions.
日本語の概要は準備中です。原文の説明を表示しています。
Guide for dataset construction — SupervisedDatasetBuilder, RLDatasetBuilder, ChatDatasetBuilder, and custom dataset creation from JSONL, HuggingFace, or conversation data. Use when the user asks about datasets, data loading, data preparation, or custom data formats.
日本語の概要は準備中です。原文の説明を表示しています。
Set up and run knowledge distillation (on-policy, off-policy, or multi-teacher) from a teacher model to a student model using the Tinker API. Use when the user wants to distill knowledge, compress models, or train a student from a teacher.
日本語の概要は準備中です。原文の説明を表示しています。