スキル一覧に戻る
ReinforceNow

off-policy-distillation

by ReinforceNow

The RL training platform. Use ReinforceNow to train reliable AI agents from raw data to production.

65🍴 3📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: off-policy-distillation description: Generate training data from teacher models for off-policy distillation. Use when converting prompts to SFT datasets using larger models, generating teacher completions with tools, or preparing data for knowledge distillation. Triggers on "distillation", "teacher model", "generate completions", "OpenRouter", "off-policy", "knowledge transfer". allowed-tools: Read, Edit, Write, Bash, Grep, Glob

Off-Policy Distillation

Generate training data by running a teacher model (e.g., GPT-4o) with tools, then train a student model via SFT.

IMPORTANT: This is SFT training - NO rewards.py needed. The student learns by imitating teacher responses.

Setup

# 1. Create venv with Python 3.11+ using uv
uv venv --python 3.11

# 2. Activate the venv
source .venv/bin/activate

# 3. Install dependencies
uv pip install httpx tqdm crawl4ai nest_asyncio

# 4. Setup crawl4ai browser (required once)
crawl4ai-setup

# 5. Set OpenRouter API key
echo "OPENROUTER_API_KEY=sk-or-v1-your-key-here" > .env

Quick Start

# 1. Generate teacher completions with tool use
python generate_distillation_data.py prompts.jsonl \
  --model openai/gpt-4o-mini \
  --tools tools.py \
  --output train.jsonl

# 2. Train (SFT - no rewards needed)
rnow run

How It Works

  1. Prepare prompts - A list of tasks/questions
  2. Run agentic rollouts - Teacher model uses tools (e.g., browse) to solve tasks
  3. Save conversations - Full multi-turn conversations with tool calls saved to train.jsonl
  4. Train with SFT - Student learns to imitate the teacher's responses AND tool use

Script: generate_distillation_data.py

Runs concurrent agentic rollouts with adaptive rate limiting.

Usage

# Basic - agentic with tools
python generate_distillation_data.py prompts.jsonl --tools tools.py

# No tools - simple completions
python generate_distillation_data.py prompts.jsonl --tools none

# Custom model and concurrency
python generate_distillation_data.py prompts.jsonl \
  --model openai/gpt-4o \
  --concurrency 10 \
  --max-turns 15

Options

OptionDefaultDescription
inputrequiredInput prompts file (txt or jsonl)
-o, --outputtrain.jsonlOutput file
-t, --toolstools.pyTools file (use 'none' to disable)
-m, --modelopenai/gpt-4o-miniTeacher model (OpenRouter format)
-s, --systemNoneSystem prompt
-n, --numNoneMax prompts to process
-c, --concurrency20Initial concurrent requests (adapts on rate limits)
--max-tokens2048Max tokens per response
--max-turns10Max turns per rollout
--temperature0.7Sampling temperature

Input Format

prompts.txt (simple):

Find the active ingredient in NCT01234567
What was the FDA approval date for Keytruda?

prompts.jsonl (with metadata):

{"prompt": "Find the active ingredient in NCT01234567", "metadata": {"expected_answer": "pembrolizumab"}}
{"prompt": "What was the FDA approval date for Keytruda?", "metadata": {"expected_answer": "2014-09-04"}}

Output Format

Full conversations with tool calls:

{
  "messages": [
    {"role": "user", "content": "Find the active ingredient in NCT01234567"},
    {"role": "assistant", "content": "", "tool_calls": [{"id": "call_1", "type": "function", "function": {"name": "browse", "arguments": "{\"url\": \"https://clinicaltrials.gov/study/NCT01234567\"}"}}]},
    {"role": "tool", "tool_call_id": "call_1", "content": "# Study NCT01234567\n\nIntervention: Pembrolizumab 200mg..."},
    {"role": "assistant", "content": "The active ingredient is pembrolizumab."}
  ],
  "metadata": {"teacher": "openai/gpt-4o-mini", "turns": 2},
  "tools": ["browse"]
}

tools.py - Browse Tool

The included tools.py uses Crawl4AI for web browsing:

@tool
def browse(url: str) -> str:
    """Browse a URL and return its content as markdown."""
    # Uses Crawl4AI to fetch and convert page to markdown

You can add more tools as needed:

@tool
def search(query: str) -> str:
    """Search the web for information."""
    # Your search implementation

config.yml for SFT

project_name: "Distilled Agent"
dataset_type: sft  # No rewards needed

data:
  train_file: train.jsonl
  batch_size: 4

model:
  path: Qwen/Qwen3-8B
  qlora_rank: 32

trainer:
  num_epochs: 3
  learning_rate: 0.00005

Note: No rewards.py is needed - SFT learns from teacher examples directly.


ModelBest ForCost
openai/gpt-4o-miniFast, cheap, good for browsingLow
openai/gpt-4oBetter reasoningMedium
anthropic/claude-sonnet-4Complex tasksMedium
openai/o3Deep reasoningHigh

See openrouter.ai/models for full list.


Tips

1. Use Metadata for Later RL

Include expected answers in metadata for potential RL fine-tuning later:

{"prompt": "What is 2+2?", "metadata": {"expected_answer": "4"}}

2. Filter Bad Samples

After generation, filter out low-quality samples:

import json
entries = [json.loads(l) for l in open("train.jsonl")]
# Keep only successful rollouts (assistant gave final answer)
filtered = [e for e in entries if not e["messages"][-1].get("tool_calls")]

3. Resume Interrupted Generation

The script auto-resumes. Just re-run with the same output file.

4. Handle Rate Limits

The script automatically reduces concurrency on rate limits. Start high (20) and let it adapt.


Troubleshooting

Crawl4AI Setup Issues

# Make sure playwright browsers are installed
playwright install chromium

Rate Limiting

The script handles this automatically. If you see many rate limits, reduce initial concurrency:

python generate_distillation_data.py prompts.jsonl -c 5

Tool Execution Errors

Check that tools.py dependencies are installed:

uv pip install crawl4ai nest_asyncio
crawl4ai-setup

  • rnow-config - Configure SFT training
  • rnow-train-jsonl - train.jsonl format details
  • rnow-tools - Writing custom tools

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です