PyTRIO Skill
PyTRIO Skill enables AI coding agents such as Claude Code, Codex, and OpenCode to accurately write, debug, and explain remote LLM post-training and inference code with PyTRIO. It focuses on two areas:
- Using PyTRIO correctly: helps agents understand PyTRIO's remote training and inference paradigm—including sync/async training loops, multimodal
ModelInput, custom loss functions (forward_backward_custom), checkpoint saving and resuming, OpenAI-compatible APIs, and SwanLab experiment tracking—avoiding mistakes from applying local PyTorch or Hugging Face patterns directly to PyTRIO - Best-practice recipes for post-training algorithms: bundles proven implementations and guides across supervised fine-tuning and decision models (SFT, multi-turn conversation distillation, Decision Model / PyTRIO-Jev), reinforcement learning and on-policy distillation (GRPO, Vision GRPO, OPD, OPSD, DAPO, GSPO, DPO), and multi-turn Agentic RL (Search-R1, ReTool, ALFWorld)
The agent routes each task to the relevant local reference (references/) and runnable example (examples/) first, then consults the official PyTRIO Markdown documentation when needed.
TIP
Before generating or debugging code with the skill, make sure your pytrio SDK is up to date (multimodal inference, multimodal SFT, and Vision GRPO require pytrio >= 0.2.7). If your project pins a specific version via pyproject.toml, requirements, or a lockfile, keep the pinned version and follow its API signatures.
Installation
Install via Agent
If you use a coding agent such as Claude Code or Codex, send the prompt below and it will complete the installation automatically:
Fetch the installation guide and follow it: https://raw.githubusercontent.com/SwanHubX/pytrio-skill/main/README.mdManual Installation
Global installation is recommended:
npx skills add SwanHubX/pytrio-skill -g -y
npx skillsinstalls Agent Skills for AI agent CLIs. Passing-ginstalls the skill globally under~/.agents/skills, allowing multiple agent CLIs for the same user to share it. See the skills documentation for details.
To update PyTRIO Skill when a new version is released, run:
npx skills update pytrio-skill -g -yLog in to PyTRIO
Before running generated code, make sure pytrio is installed and your API key is configured:
pip install --upgrade pytrio
trio login # paste your API key from https://pytrio.com/dashboardIn non-interactive environments such as CI, pass your API key via an environment variable:
export PYTRIO_API_KEY=<your key>. See Environment Configuration for all supported variables.
Capabilities
Using PyTRIO Correctly
| Capability | What the Agent Covers |
|---|---|
| Remote training paradigm & core APIs | Follows PyTRIO's remote training and sync / async loop patterns instead of misapplying local PyTorch or Hugging Face code |
| Custom loss functions | Implements custom training objectives and gradient logic with forward_backward_custom |
| Multimodal input & inference | Builds text-image ModelInput accurately for multimodal sampling, inference, and training |
| Serving, checkpoints & configuration | Consults the official docs index for inference, checkpoint saving and resuming, OpenAI-compatible APIs, environment variables, and SwanLab tracking |
Algorithm Best Practices
| Category | Algorithms & Recipes |
|---|---|
| Supervised Fine-Tuning (SFT) | Minimal SFT, persona fine-tuning (e.g., Chat-Huanhuan), multi-turn conversation distillation (sync / async), and multimodal SFT |
| Decision Models | Decision Model (PyTRIO-Jev) fixed-candidate classification, sparse supervision, and temperature calibration |
| Preference & Policy Optimization | DPO preference alignment, GRPO, Vision GRPO, DAPO, and GSPO |
| On-Policy Distillation | OPD on-policy distillation (sync / async) and OPSD self-distillation |
| Multi-turn Agentic RL | End-to-end multi-turn RL workflows including Search-R1 (search QA), ReTool (tool use), and ALFWorld (embodied interaction) |
Example Prompts
Once installed, you can describe your task directly in Claude Code, Codex, or another coding agent. Here are ready-to-adapt prompts for both newcomers and advanced post-training workflows:
Getting Started & Fast Onboarding
1. Run your first LoRA fine-tune and compare before/after outputs
I have a local conversation dataset at data/train.jsonl. Use PyTRIO to run LoRA SFT on Qwen/Qwen3.5-4B, log the loss curve to SwanLab, save checkpoints when finished, and write a sampling script comparing responses before and after fine-tuning.2. Migrate an existing local script to PyTRIO remote training
Migrate the Hugging Face SFT script in this directory to PyTRIO remote LoRA training with resume support (saving both state and sampler weights), and update the inference code to use the OpenAI-compatible API.Advanced Algorithms & Research Prototyping
3. Scaffold an async GRPO training pipeline with a custom verifier
Following PyTRIO best practices, build an async GRPO training script for Qwen/Qwen3.5-4B using my custom verifier in verifier.py: sample 8 prompts × 8 trajectories per step, skip zero-variance groups, and log reward and response length to SwanLab.4. Build a multi-turn tool-use Agentic RL loop (ReTool style)
I want to run a multi-turn code-execution Agentic RL experiment where the model calls a local Python sandbox and reads stdout across up to 6 turns. Build the PyTRIO training pipeline so tool observation tokens have zero training weight and advantage, and track per-turn pass rates.5. Prototype a custom objective with forward_backward_custom
I want to test a modified preference-optimization objective on PyTRIO. Implement a length-normalized DPO loss with a KL penalty using forward_backward_custom, and include a small-batch smoke test to verify the forward pass and gradients.Use with SwanLab Skill
PyTRIO training scripts recommend logging metrics such as loss, reward, and reverse KL with SwanLab. If you also want your agent to query experiment curves, compare runs, or write full experiment-tracking code, install SwanLab Skill alongside PyTRIO Skill:
npx skills add SwanHubX/SwanLab-Skill -g -y