Skip to main content

PyTRIO

Own the training loop. Build models for your frontier.

PyPI version Python 3.10+ License

The Python SDK for the PyTRIO Training API—control post-training in your code while PyTRIO runs the infrastructure.

Website · Docs

✨ What is pytrio?

pytrio is the Python SDK for the PyTRIO Training API. It lets researchers and engineering teams drive large-model post-training from their own code while PyTRIO supplies training as a service.

With the Training API, your data preparation, loss functions, reward logic, rollout strategy, and experiment orchestration stay in your environment. PyTRIO provides the remote compute and handles distributed execution, scheduling, and infrastructure reliability.

  • 🎛️ Programmable training: Compose explicit training primitives instead of submitting a black-box fine-tuning job
  • 🧪 Post-training focused: Build SFT, reinforcement learning, preference optimization, and custom objectives
  • ☁️ Remote execution: Run the control loop locally without setting up CUDA or managing GPU clusters
  • 🔁 One experiment loop: Train, sample, evaluate, checkpoint, and resume through the same SDK
  • 🔌 Ready for applications: Move trained weights into PyTRIO's OpenAI-compatible inference service

🧭 Where the SDK fits

The broader PyTRIO platform includes flexible Training API access, dedicated training resources, managed training workflows, and inference. This repository focuses on the programmable SDK surface: connecting to the service, controlling training and sampling, and managing experiment state from Python.

Model availability, pricing, and access to dedicated or managed offerings are platform concerns and may change independently of the SDK. See the PyTRIO website for the current product catalog.

🚀 Train, then sample with the Training API

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

pip install pytrio
trio login

Create a LoRA training client, update its weights, and turn the latest policy into a sampler without leaving your Python workflow:

import pytrio as trio

# Connect to the PyTRIO Training API.
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 PyTRIO?\nAnswer: a post-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 PyTRIO?\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

The SDK keeps rollout generation and policy updates in one programmable 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. These primitives support SFT, PPO-style objectives, custom losses, checkpointing, and evaluation while keeping the algorithm visible in your code.

🧩 SDK primitives

Goal Start here
Connect to the Training API 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

Inference is part of the broader PyTRIO platform. After training through the SDK, move a saved 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)

Build your specialized model

Explore the Training API docs →

Training Is On. ⚡

Metadata

Release files for pytrio 0.2.10

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

Source distribution (sdist)

Source distribution for pytrio 0.2.10
File Size Uploaded Provenance Actions
pytrio-0.2.10.tar.gz 143.8 kB With provenance Details for pytrio-0.2.10.tar.gz

Built distribution (wheel)

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

Total release size: 351.2 kB

Release files / pytrio-0.2.10.tar.gz

Download URL pytrio-0.2.10.tar.gz
Size 143.8 kB
Tags Source
SHA-256 checksum
How to use checksums
679bdcd4f4d340e90675bffb000b63df555818d25c22ae26bc3570aefe107c38
BLAKE2b-256 checksum
How to use checksums
f9ab2ac3e23e458bc83477be8cc3c34a1296c278c6d6329904ed8c05650adf35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / pytrio-0.2.10-py3-none-any.whl

Download URL pytrio-0.2.10-py3-none-any.whl
Size 207.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c28dd2db12271039854a3ebd63f0eadb12778c18209df295aa63807fde850609
BLAKE2b-256 checksum
How to use checksums
eff7138df6f19cb65416785356accb31e796d1a32726140aceabdeb1c3c68a34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for pytrio 0.2.10

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytrio-0.2.10.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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.

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