Skip to main content

Triotune

PyTRIO-native training recipes and trainer building blocks.

Triotune is a small, text-only training cookbook built on the public PyTRIO client API. The name combines Trio, from PyTRIO, with tune, inspired by Torchtune. It keeps model execution, tokenization, sampling, and optimization in PyTRIO, while providing the client-side data preparation, reward and advantage calculation, token alignment, and training-loop orchestration.

中文文档

Project status: Triotune is an early-stage cookbook. It currently offers built-in text-training workflows and examples; a general API for registering arbitrary custom model modules is not yet part of the project.

🗂️ Contents

👋 Introduction

Triotune provides a trainer-shaped interface for a few PyTRIO-backed training algorithms. The package is intentionally client-side: PyTRIO remains responsible for model weights, LoRA training clients, tokenizers, sampling, forward/backward execution, optimizer steps, and checkpoint storage.

The current trainers are:

  • PPO: one asynchronous trainer for PPO, GRPO, RLOO, GSPO, SAPO, CISPO, DAPO, and related presets.
  • DPO: chosen/rejected preference pairs, optional reference-policy scoring, and a local pairwise loss submitted through PyTRIO.
  • SFT: text-only supervised fine-tuning with prompt/completion masking and an asynchronous training path.
  • OPD: on-policy distillation in which a student samples completions and a fixed teacher supplies token-level scores.

PPO, DPO, and OPD include asynchronous training paths where the underlying PyTRIO client supports them. Shared utilities handle text, token-ID, and chat-message inputs, checkpoint naming, and SwanLab metrics.

📰 News

  • 2026-10-12: Triotune 0.1.0 (pytrio-cookbook) was published to PyPI.

📦 Installation

✅ Requirements

  • Python 3.12 (the package currently declares >=3.12,<3.13)
  • Access to a PyTRIO-compatible training service and the models used by your recipe

Using uv is recommended because uv.lock pins the repository environment:

uv sync
uv run python -c "import trio_cookbook; print(trio_cookbook.__name__)"

Install the optional PyTorch dependency when using DPO:

uv sync --extra dpo

The published package can also be installed directly:

pip install triotune==0.1.1

For a source checkout with pip:

pip install -r requirements.txt
pip install -e .

The distribution name is triotune; the Python import name remains trio_cookbook.

🚀 Quick start

The GSM8K recipe prepares a JSONL dataset and then runs the PPO trainer with its GRPO preset. The preparation command does not create a PyTRIO client, so it is a safe first check for the local environment:

# From the repository root
bash triotune/scripts/train_grpo_gms8k.sh --prepare-only

# Start training with the default YAML configuration
bash triotune/scripts/train_grpo_gms8k.sh

Useful overrides include --steps, --batch-size, --group-size, --max-examples, and --help. The default configuration uses a Qwen model, LoRA, SwanLab logging, and the GSM8K boxed-answer reward. Change the model and training settings in triotune/configs/grpo_gms8k.yaml for your setup.

🔧 Support Matrix

🧠 Algorithms

Algorithm Documentation Paper Configuration
GRPO - 📄 Paper 🔗 GSM8K Example
PPO - 📄 Paper 🔗 GSM8K Example
DPO - 📄 Paper 🔗 HH-RLHF Example
OPD - 🔗 DeepMath-103K Example
SFT - 🔗 Huanhuan Chat Example

📖 Models

PyTRIO currently supports the following models:

  • Qwen/Qwen3.5-4B
  • Qwen/Qwen3.5-9B
  • Qwen/Qwen3.8-27B

🧩 Data contracts

The trainers accept a deliberately small set of input representations:

  • a string;
  • a non-empty list of token IDs; or
  • a non-empty list of {role, content} chat messages.

Algorithm-specific fields are:

  • GRPO: messages and a string answer used by the reward function;
  • DPO: shared messages, plus chosen and rejected responses;
  • SFT: text, messages, prompt/completion, or pre-tokenized input_ids (optionally with labels);
  • OPD: prompt rows; the teacher scores the student's sampled completion.

See the trainer guide and script guide for validation rules and complete JSONL examples.

🐍 Python API

The public imports are grouped by algorithm:

import asyncio

from trio_cookbook.trainer import PPOConfig, PPOTrainer

rows = [
    {
        "messages": [{"role": "user", "content": "What is 2 + 2?"}],
        "answer": "4",
    },
]

trainer = PPOTrainer(
    model="your-pytrio-model-id",
    reward_fn=your_reward_function,
    args=PPOConfig.for_algorithm("grpo", num_generations=4, max_steps=100),
    train_dataset=rows,
)
asyncio.run(trainer.train())

🗃️ Repository layout

triotune/
├── configs/       # YAML configurations for the built-in workflows
├── recipes/       # Trainer-based and standalone PyTRIO examples
├── scripts/       # Shell launchers and dataset preparation guides
└── trainer/       # Trainers plus shared config, dataset, and client contracts

🎯 Current scope

Triotune currently targets text-only, PyTRIO-backed experiments. It does not claim to provide a Web UI, Megatron integration, multimodal training, or a universal plugin/registry system. If you need a custom model module, first adapt it to the public PyTRIO client contract and use the existing recipe or trainer interfaces; first-class custom-module registration is planned work, not a supported promise of version 0.1.1.

Metadata

Release files for triotune 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for triotune 0.1.1
File Size Uploaded Provenance
triotune-0.1.1.tar.gz 104.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for triotune 0.1.1
File Interpreter ABI Platform
triotune-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 232.5 kB

Release files / triotune-0.1.1.tar.gz

Download URL triotune-0.1.1.tar.gz
Size 104.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a343357782bab4524d07aa0f15e3174aa587bf191aabaf8022eae1d0eca2901e
BLAKE2b-256 checksum
How to use checksums
eb84ad78bd9622970ee9582059d86f97c43563aacf6101475c106b0fa1e33261
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / triotune-0.1.1-py3-none-any.whl

Download URL triotune-0.1.1-py3-none-any.whl
Size 127.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
efc547c156c002b05464271f096654539354959c564c8080f903fa0fc8e710b9
BLAKE2b-256 checksum
How to use checksums
af7d421a1c932f899dcc7c6baaea8b85dbb8621caa7c608ff6c61eaca6cf280b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for triotune 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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