pytrio.ServiceClient
class ServiceClient:
def __init__(
self,
api_key: str | None = None,
):ServiceClient is the main entry point for PyTRIO APIs. It creates:
TrainingClientinstances for model training.SamplingClientinstances for generation and inference.RestClientinstances for REST operations.
import pytrio as trio
client = trio.ServiceClient()
training_client = client.create_lora_training_client(base_model="Qwen/Qwen3.5-4B")
sampling_client = client.create_sampling_client(base_model="Qwen/Qwen3.5-4B")
rest_client = client.create_rest_client()Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | str | None | None | API key. If omitted, PyTRIO reads the current process configuration, which can come from the local login state, PYTRIO_API_KEY, or pytrio.configure(api_key=...); see Environment Configuration |
During initialization, ServiceClient verifies login, opens the socket connection, and fetches the available model list. Each ServiceClient copies the current process configuration when construction begins; later calls to pytrio.configure(...) do not change an existing client's server URL, timeout, or similar settings.
Methods
get_supported_models
def get_supported_models(self) -> list[str]Return the models currently available to the account.
Returns
list[str] - model names, for example ["Qwen/Qwen3.5-4B"].
Example
models = client.get_supported_models()
print(models) # ["Qwen/Qwen3.5-4B", ...]create_lora_training_client
def create_lora_training_client(
self,
base_model: str,
rank: int = 32,
seed: int | None = None,
train_mlp: bool = True,
train_attn: bool = True,
train_unembed: bool = True,
) -> TrainingClientCreate a TrainingClient for LoRA fine-tuning.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
base_model | str | - | Base model, for example "Qwen/Qwen3.5-4B" |
rank | int | 32 | LoRA rank, from 4 to 64 |
seed | int | None | None | Initialization seed |
train_mlp | bool | True | Whether to train MLP layers |
train_attn | bool | True | Whether to train attention layers |
train_unembed | bool | True | Whether to train the lm_head layer |
Returns
TrainingClient - client with the active training state.
Example
training_client = client.create_lora_training_client(
base_model="Qwen/Qwen3.5-4B",
rank=16,
train_unembed=False,
)create_sampling_client
def create_sampling_client(
self,
base_model: str,
model_path: str | None = None,
) -> SamplingClientCreate a SamplingClient for generation and inference.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
base_model | str | "" | Base model, for example "Qwen/Qwen3.5-4B" |
model_path | str | None | None | LoRA model checkpoint path URL to load during initialization |
Returns
SamplingClient - sampling client.
Examples
sampling_client = client.create_sampling_client(base_model="Qwen/Qwen3.5-4B")sampling_client = client.create_sampling_client(
base_model="Qwen/Qwen3.5-4B",
model_path="/path/to/checkpoint",
)create_rest_client
def create_rest_client(self) -> RestClientCreate a RestClient for REST API operations, such as listing adapters and querying checkpoints.
Returns
RestClient - REST client.
Example
rest_client = client.create_rest_client()
checkpoint_list = rest_client.list_user_checkpoints().result()create_training_client_from_state
def create_training_client_from_state(self, path: str) -> TrainingClientCreate a TrainingClient from a saved adapter or checkpoint without restoring optimizer state.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | str | Adapter or checkpoint path |
Returns
TrainingClient - client with restored model state.
Example
training_client = client.create_training_client_from_state(
path="/path/to/checkpoint"
)create_training_client_from_state_with_optimizer
def create_training_client_from_state_with_optimizer(self, path: str) -> TrainingClientCreate a TrainingClient from a train checkpoint and restore optimizer state for resume training.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | str | Train checkpoint path |
Returns
TrainingClient - client with restored model and optimizer state.
Example
training_client = client.create_training_client_from_state_with_optimizer(
path="/path/to/checkpoint"
)Async Methods
create_lora_training_client_async
async def create_lora_training_client_async(
self,
base_model: str,
rank: int = 32,
seed: int | None = None,
train_mlp: bool = True,
train_attn: bool = True,
train_unembed: bool = True,
) -> TrainingClientAsynchronously create a TrainingClient for LoRA fine-tuning. Parameters and return value are the same as create_lora_training_client.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
base_model | str | - | Base model, for example "Qwen/Qwen3.5-4B" |
rank | int | 32 | LoRA rank, from 4 to 64 |
seed | int | None | None | Initialization seed |
train_mlp | bool | True | Whether to train MLP layers |
train_attn | bool | True | Whether to train attention layers |
train_unembed | bool | True | Whether to train the lm_head layer |
Returns
TrainingClient - client with the active training state.
Example
training_client = await client.create_lora_training_client_async(
base_model="Qwen/Qwen3.5-4B",
rank=16,
train_unembed=False,
)create_sampling_client_async
async def create_sampling_client_async(
self,
base_model: str,
model_path: str | None = None,
) -> SamplingClientAsynchronously create a SamplingClient for generation and inference. Parameters and return value are the same as create_sampling_client.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
base_model | str | "" | Base model, for example "Qwen/Qwen3.5-4B" |
model_path | str | None | None | LoRA model checkpoint path URL to load during initialization |
Returns
SamplingClient - sampling client.
Examples
sampling_client = await client.create_sampling_client_async(base_model="Qwen/Qwen3.5-4B")sampling_client = await client.create_sampling_client_async(
base_model="Qwen/Qwen3.5-4B",
model_path="/path/to/checkpoint",
)create_training_client_from_state_async
async def create_training_client_from_state_async(self, path: str) -> TrainingClientAsynchronously create a TrainingClient from a saved adapter or checkpoint without restoring optimizer state. Parameters and return value are the same as create_training_client_from_state.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | str | Adapter or checkpoint path |
Returns
TrainingClient - client with restored model state.
Example
training_client = await client.create_training_client_from_state_async(
path="/path/to/checkpoint"
)create_training_client_from_state_with_optimizer_async
async def create_training_client_from_state_with_optimizer_async(self, path: str) -> TrainingClientAsynchronously create a TrainingClient from a train checkpoint and restore optimizer state for resume training. Parameters and return value are the same as create_training_client_from_state_with_optimizer.
Parameters
| Parameter | Type | Description |
|---|---|---|
path | str | Train checkpoint path |
Returns
TrainingClient - client with restored model and optimizer state.
Example
training_client = await client.create_training_client_from_state_with_optimizer_async(
path="/path/to/checkpoint"
)