SuperAPI AI 工具集

pytrio

通用与其它

查看项目

更新于 10-16 09:53

技能介绍

用途:PyTRIO 提供远程 LLM 训练与推理能力,本地只需准备数据和调度,不依赖本地 GPU,前向传播、反向传播、优化器步骤与推理采样均在远端 GPU 集群执行。

安装与导入:pip install pytrio transformers torch。统一使用 import pytrio as trio,所有 API 通过 trio.xxx 访问。

认证:使用前必须登录。检查 ~/.pytrio/config.toml 是否含 api_key。未登录时执行 trio login -k <API_KEY>(注意 CLI 命令是 trio,不是 pytrio)。API Key 可从 https://pytrio.cn/dashboard 获取。也可在代码中传 ServiceClient(api_key="YOUR_API_KEY")。

主要能力:通过 client.create_lora_training_client 创建 LoRA 训练客户端,指定 base_model="Qwen/Qwen3-4B-Instruct-2507",可配置 rank、train_mlp、train_attn、train_unembed。用 train.get_tokenizer() 获取 tokenizer(需安装 modelscope)。构造 trio.Datum,model_input 须用 trio.ModelInput.from_ints() 包装,并按 tokens[:-1]/tokens[1:] 偏移对齐,weights 同步偏移。调用 train.forward_backward(data=[...], loss_fn=...) 与 train.optim_step(trio.AdamParams(...)) 完成训练步骤。支持 cross_entropy、importance_sampling、ppo 损失,也可用 forward_backward_custom 自定义 loss(需本地 torch)。

保存与推理:train.save_weights_for_sampler() 保存推理权重,train.save_state() 保存含优化器的完整检查点;可用 create_training_client_from_state_with_optimizer 续训。推理通过 train.create_sampling_client 或 client.create_sampling_client,sampler.sample(prompt=trio.ModelInput.from_ints(ids), sampling_params=trio.SamplingParams(...))。

管理与限制:create_rest_client() 可列出权重、训练记录、检查点并获取下载链接。注意所有方法返回 APIFuture,必须调用 .result();checkpoint path 是远端路径;必须使用 Instruct 模型;RL 场景应传 weights 对 prompt 做 mask;不支持 -100 masking;采样参数名为 max_tokens;loss key 是 "loss:sum";AdamParams 默认 beta2=0.95、eps=1e-12,与 PyTorch 不同。WebSocket 断连不自动重连,需重建 ServiceClient。如有系统代理,需设置 no_proxy=pytrio.cn 及清空 http(s)_proxy。更多细节见 references/ 与 examples/ 目录。