Skip to main content

GRPO-in-Sandbox Package

Agentic Reinforcement Learning Library. It's from llm_in_sandbox()

Core API

from grpo_in_sandbox import (
    train,
    RLHFTrainingConfig,
    create_runtime,
    Agent,
    AgentArgs,
    RewardModel,
    ProductManager,
    BaseRuntime,
    LocalRuntime,
    DockerRuntime,
    KaggleRuntime,
    Trajectory,
    TrajectoryStep,
    AgentConfig,
    load_config,
)

Module Structure

Module Description
train.py GRPO training interface
runtime.py Unified runtime abstraction
config.py Configuration management
agent.py Agent implementation
trajectory.py Trajectory recording
observation.py Action results
action.py Action representation
tools.py Tool definitions
docker_runtime.py Docker backend

Training Example

from grpo_in_sandbox import train, RLHFTrainingConfig

config = RLHFTrainingConfig(
    model_name_or_path="Qwen/Qwen2.5-0.5B-Instruct",
    num_train_epochs=3,
)
results = train(config)

Training Backends

train() drives TRL's GRPOTrainer with a selectable model-loading backend:

backend Install Notes
"auto" (default) Uses Unsloth if installed, otherwise pure TRL
"trl" pip install "grpo-in-sandbox[training]" Pure TRL + Transformers + PEFT, no Unsloth needed
"unsloth" pip install "grpo-in-sandbox[unsloth]" Unsloth-optimized loading + vLLM fast inference
from grpo_in_sandbox import train, RLHFTrainingConfig

config = RLHFTrainingConfig(
    model_name_or_path="Qwen/Qwen2.5-0.5B-Instruct",
    backend="trl",    # pure TRL — no Unsloth required
    use_vllm=False,   # optional; auto-disabled when vllm is not installed
)
results = train(config)

AI Judge Self-Play Mode

Train models WITHOUT sandbox execution using AI-as-Judge for reward signals.

from grpo_in_sandbox import (
    SelfPlayGRPO,
    RLHFTrainingConfig,
    AITrainerMode,
    AIJudge,
    ProductManager,
)

# Method 1: Using SelfPlayGRPO orchestrator
config = RLHFTrainingConfig(
    mode=AITrainerMode.AI_JUDGE,
    model_name_or_path="Qwen/Qwen2.5-0.5B-Instruct",
    judge_llm_name="openai/gpt-4o-mini",
    judge_criteria=["correctness", "clarity", "helpfulness"],
    max_steps=50,
)
sp = SelfPlayGRPO(config)
sp.run()

# Method 2: Using train() with ai_judge parameter
judge = AIJudge(llm_name="openai/gpt-4o-mini")
results = train(config, ai_judge=judge)

For full API tutorial, see docs/AI_JUDGE_GRPO_TUTORIAL.md

Runtime Example

from grpo_in_sandbox import create_runtime

runtime = create_runtime(backend="docker")
output, exit_code = runtime.run("echo hello")
stdout, stderr, exit_code = runtime.demux_run("echo hello")
runtime.close()

Agent Example

from grpo_in_sandbox import Agent, AgentArgs, create_runtime

runtime = create_runtime(backend="docker")

args = AgentArgs(
    system_prompt="You are a helpful assistant.",
    instance_prompt="{problem_statement}",
    llm_name="openai/gpt-4",
)

agent = Agent(args)
trajectory = agent.run(
    runtime=runtime,
    problem_statement="Solve 2+2",
)

需要安装的依赖项

pip install grpo-in-sandbox               # 核心(沙箱 / Agent / CLI)
pip install "grpo-in-sandbox[training]"   # + GRPO 训练(纯 TRL 后端:transformers/trl/peft/accelerate/torch)
pip install "grpo-in-sandbox[unsloth]"    # + Unsloth 优化后端(含 training 依赖)
pip install "grpo-in-sandbox[quant]"      # + bitsandbytes(load_in_4bit=True 时需要)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grpo_in_sandbox-0.2.1.tar.gz (97.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grpo_in_sandbox-0.2.1-py3-none-any.whl (120.9 kB view details)

Uploaded Python 3

File details

Details for the file grpo_in_sandbox-0.2.1.tar.gz.

File metadata

  • Download URL: grpo_in_sandbox-0.2.1.tar.gz
  • Upload date:
  • Size: 97.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for grpo_in_sandbox-0.2.1.tar.gz
Algorithm Hash digest
SHA256 93f7a95690f44e4c816b128bf4f2880dd9dbbd01e886fea814ac39a555fca259
MD5 ac0ac34c63a38553eaa4e73dc707b7fc
BLAKE2b-256 f9a1f13adbdc0e8a3e8238e15587219c2ad498127b341d8e10844151e0053b64

See more details on using hashes here.

File details

Details for the file grpo_in_sandbox-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for grpo_in_sandbox-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e421a67ff8cb2be7ea7a59fc6d0427e548b75117d74738e82ccfb49c9e6123
MD5 236619413dd7ce14e62d05ec9eea616c
BLAKE2b-256 972d6a3ce8a41d396811335f0463147ed56a6042a586571cc430c6884713571c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

This release

0.2.1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page