Skip to main content

PyTRIO

Connect to WiFi. Train large language models.

PyPI version Python 3.10+ License

A clean Python SDK for model training, inference, and post-training experiments.

Website · Docs

✨ What is PyTRIO?

PyTRIO lets you focus on the parts of post-training that matter—your data and algorithms—while the engine handles distributed execution, scheduling, fault tolerance, and GPU infrastructure.

Write your training loop on a CPU machine, choose a base model with one string, and keep full control of your loss function, optimizer, rollout strategy, and experiment logic.

  • 🧪 Built for post-training: Run SFT, RL, preference optimization, and custom objectives
  • Async research: Keep working locally while training runs remotely
  • 🚀 Managed scale: Train across GPUs without managing CUDA or clusters
  • 🔁 Fast iteration: Sample fresh weights, checkpoint, and resume anytime
  • 🔌 Application ready: Serve trained weights through OpenAI-compatible APIs

🚀 Train, then sample

Install the SDK and sign in with an API key from the Trio console:

pip install pytrio
trio login

The same training client can update LoRA weights and turn the latest policy into a sampler immediately:

import pytrio as trio

# Connect to the PyTRIO training engine.
service = trio.ServiceClient()
trainer = service.create_lora_training_client(
    base_model="Qwen/Qwen3.5-4B",
    rank=32,
)
tokenizer = trainer.get_tokenizer()

# Prepare one supervised training example.
tokens = tokenizer.encode(
    "Question: what is Trio?\nAnswer: a model training platform."
)
batch = [
    trio.Datum(
        model_input=trio.ModelInput.from_ints(tokens[:-1]),
        loss_fn_inputs={
            "target_tokens": tokens[1:],
            "weights": [1.0] * (len(tokens) - 1),
        },
    )
]

# Every step of the training loop stays in your hands.
for step in range(10):
    trainer.forward_backward(batch, "cross_entropy").result()
    trainer.optim_step(trio.AdamParams(learning_rate=1e-4)).result()

# Save the latest policy and sample from it immediately.
sampler = trainer.save_weights_and_get_sampling_client()
prompt_tokens = tokenizer.encode("Question: what is Trio?\nAnswer:")
result = sampler.sample(
    prompt=trio.ModelInput.from_ints(prompt_tokens),
    sampling_params=trio.SamplingParams(max_tokens=32, temperature=0.0),
    num_samples=1,
).result()

print(result.sequences[0].text)

🎲 Rollouts in, policy updates out

PyTRIO keeps rollout generation and policy updates in one workflow. Sample multiple trajectories from the latest policy, score them with your reward function, then train directly from their tokens and logprobs:

question = "What is 6 * 8?"
prompt_tokens = tokenizer.encode(
    f"Question: {question}\nReturn only the final numeric answer.\nAnswer:"
)

# Generate a group of rollouts from the latest policy.
rollouts = sampler.sample(
    prompt=trio.ModelInput.from_ints(prompt_tokens),
    sampling_params=trio.SamplingParams(max_tokens=8, temperature=0.7),
    num_samples=4,
).result()

training_data = []
for sequence in rollouts.sequences:
    reward = 2.0 if sequence.text.strip() == "48" else -1.0
    completion_tokens = list(sequence.tokens)
    tokens = prompt_tokens + completion_tokens
    old_logprobs = (
        [0.0] * len(prompt_tokens)
        + [0.0 if value is None else float(value) for value in sequence.logprobs]
    )
    advantages = [0.0] * len(prompt_tokens) + [reward] * len(completion_tokens)

    training_data.append(
        trio.Datum(
            model_input=trio.ModelInput.from_ints(tokens[:-1]),
            loss_fn_inputs={
                "target_tokens": tokens[1:],
                "logprobs": old_logprobs[1:],
                "advantages": advantages[1:],
            },
        )
    )

# Update the policy from rewarded rollouts.
trainer.forward_backward(
    training_data,
    loss_fn="importance_sampling",
).result()
trainer.optim_step(
    trio.AdamParams(learning_rate=1e-5),
).result()

Refresh the sampler from the latest weights on every iteration to build an on-policy loop. The same primitives support SFT, PPO-style objectives, custom losses, checkpointing, and evaluation without hiding the algorithm behind a black box.

🧭 API primitives

Goal Start here
Connect to the training engine trio.ServiceClient
Create and update a LoRA policy trio.TrainingClient
Generate rollouts or compute logprobs trio.SamplingClient
Define token, text, or image input trio.ModelInput
Control rollout generation trio.SamplingParams
Save, resume, and download checkpoints trio.RestClient

🔌 OpenAI-compatible inference

Move a trained policy into an application with a model identifier and the standard OpenAI client:

from openai import OpenAI

client = OpenAI(
    base_url="https://pytrio.com/api/openai/v1",
    api_key="TRIO_API_KEY",
)
response = client.chat.completions.create(
    model="trio://your-model/your-version",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Ready to start training?

Read the official docs →

Training Is On.

Download files

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

Source Distribution

pytrio-0.2.8.tar.gz (129.9 kB view details)

Uploaded Source

Built Distribution

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

pytrio-0.2.8-py3-none-any.whl (193.9 kB view details)

Uploaded Python 3

File details

Details for the file pytrio-0.2.8.tar.gz.

File metadata

  • Download URL: pytrio-0.2.8.tar.gz
  • Upload date:
  • Size: 129.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytrio-0.2.8.tar.gz
Algorithm Hash digest
SHA256 ad01a587f02d0afd91438cae9097efdc27e9e5b5df634e959c58e5dc415cf56f
MD5 16d83aa20a838108af80900a4d7fb67d
BLAKE2b-256 9b706a919fbb931ba5f13fe54b23970b7ad7913c4177dd9c768ccd658dfe9593

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrio-0.2.8.tar.gz:

Publisher: release.yml on SwanHubX/Trio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytrio-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: pytrio-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 193.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pytrio-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 129764d1b5f9cf095be273e9e7a53f384bd77d27c0feafb1551b1401d43ee834
MD5 8008ded34f705cf179b6e744abf887c7
BLAKE2b-256 334b2541679555ce131b55a339d98ef4ea9c00f4080339daca07d077d7a53722

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytrio-0.2.8-py3-none-any.whl:

Publisher: release.yml on SwanHubX/Trio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.9

2 files

This release

0.2.8 This release

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.13

2 files

0.1.12

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