physicalai-train-training-a-policy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTraining a policy (library)
训练策略(库端)
Training uses (, a subclass) with a and a . The library deliberately supports two equal entry points:
physicalai.train.Trainerlibrary/src/physicalai/train/trainer.pylightning.TrainerPolicyDataModule- CLI — (and
physicalai fit,validate,test): jsonargparse YAML underpredict, overrides on the command line; checkpoints underlibrary/configs/by default. Seeexperiments/{name}/version_N/.library/docs/how-to/training/cli.md - Python API — construct ,
Policy(or another datamodule), andLeRobotDataModule, thenTrainer(andtrainer.fit(model=policy, datamodule=datamodule)/validate/testwith a checkpoint as needed). Seepredictandlibrary/docs/getting-started/quickstart.md.library/docs/explanation/trainer/README.md
The CLI subcommands and the Python API share the same objects; YAML / should match what you would wire in code.
class_pathinit_argsThe four CLI subcommands share the same / / shape (see ); // additionally take . When a task is about library behavior rather than shell usage, prefer the Python API path first and then verify CLI parity if the change is user-facing.
--model--data--trainer.*cli/_dispatch.pyvalidatetestpredict--ckpt_path训练使用(,的子类),搭配和。该库特意支持两种同等的入口方式:
physicalai.train.Trainerlibrary/src/physicalai/train/trainer.pylightning.TrainerPolicyDataModule- CLI — (以及
physicalai fit、validate、test):使用predict下的jsonargparse YAML配置,可通过命令行覆盖默认配置;检查点默认存储在library/configs/目录下。详见experiments/{name}/version_N/。library/docs/how-to/training/cli.md - Python API — 构造、
Policy(或其他数据模块)和LeRobotDataModule,然后调用Trainer(必要时可结合检查点调用trainer.fit(model=policy, datamodule=datamodule)/validate/test)。详见predict和library/docs/getting-started/quickstart.md。library/docs/explanation/trainer/README.md
CLI子命令与Python API共用同一套对象;YAML中的/应与代码中的组装逻辑一致。
class_pathinit_args四个CLI子命令共用相同的//参数结构(详见);//还额外支持参数。当任务涉及库行为而非Shell使用时,优先采用Python API路径,若变更面向用户,则需验证CLI与API的一致性。
--model--data--trainer.*cli/_dispatch.pyvalidatetestpredict--ckpt_pathAnatomy of a config
配置文件结构
A config wires three pieces via / :
class_pathinit_args- — a
modelsubclass (e.g.Policy).physicalai.policies.ACT - — a
data, usuallyDataModulewith aphysicalai.data.lerobot.LeRobotDataModule(e.g.repo_id).lerobot/pusht - — Lightning args (
trainer,max_epochs,accelerator, callbacks…).devices
Configs live in (first-party: , , , , ) and (LeRobot-wrapped). Compose with and override any field on the CLI ().
library/configs/physicalai/act.yamlpi0.yamlpi05.yamlgroot.yamlsmolvla.yamllibrary/configs/lerobot/__base__--trainer.max_epochs 200 --data.train_batch_size 64配置文件通过/组装三部分内容:
class_pathinit_args- —
model的子类(例如Policy)。physicalai.policies.ACT - — 数据模块,通常是带有
data的repo_id(例如physicalai.data.lerobot.LeRobotDataModule)。lerobot/pusht - — Lightning参数(
trainer、max_epochs、accelerator、回调函数等)。devices
配置文件存储在(官方配置:、、、、)和(LeRobot封装配置)中。可通过组合配置,并在CLI中覆盖任意字段(例如)。
library/configs/physicalai/act.yamlpi0.yamlpi05.yamlgroot.yamlsmolvla.yamllibrary/configs/lerobot/__base__--trainer.max_epochs 200 --data.train_batch_size 64Python API workflow
Python API工作流
Use this path when the user asks for code, notebooks, tests, direct library integration, or changes to , , or datamodules.
TrainerPolicypython
from physicalai.data import LeRobotDataModule
from physicalai.policies import ACT
from physicalai.train import Trainer
datamodule = LeRobotDataModule(repo_id="lerobot/pusht", train_batch_size=2)
policy = ACT()
trainer = Trainer(fast_dev_run=True)
trainer.fit(model=policy, datamodule=datamodule)- Construct the same objects the CLI would instantiate: a , a
Policy, andDataModule.Trainer- Done when: construction works without relying on jsonargparse YAML.
- Smoke-test the API wiring with .
Trainer(fast_dev_run=True)- Done when: one train + one val batch complete without shape or feature errors.
- Validate / test / predict from Python with the corresponding method and
Trainerwhen needed.ckpt_path- Done when: the API call and the equivalent CLI command agree on checkpoint/config behavior.
当用户需要代码、Notebook、测试、直接库集成,或对、、数据模块进行修改时,采用此路径。
TrainerPolicypython
from physicalai.data import LeRobotDataModule
from physicalai.policies import ACT
from physicalai.train import Trainer
datamodule = LeRobotDataModule(repo_id="lerobot/pusht", train_batch_size=2)
policy = ACT()
trainer = Trainer(fast_dev_run=True)
trainer.fit(model=policy, datamodule=datamodule)- 构造与CLI实例化相同的对象:、
Policy和DataModule。Trainer- 完成标志:无需依赖jsonargparse YAML即可成功构造对象。
- 通过进行API组装冒烟测试。
Trainer(fast_dev_run=True)- 完成标志:成功完成一个训练批次和一个验证批次,无形状或特征错误。
- 从Python调用验证/测试/预测:使用对应的方法,必要时传入
Trainer。ckpt_path- 完成标志:API调用与等效CLI命令在检查点/配置行为上保持一致。
CLI workflow
CLI工作流
Use this path when the user asks for terminal commands, docs under , YAML configs, reproducible experiments, or entry-point behavior.
library/docs/how-to/- Start from an existing config matching your policy family; copy it rather than writing from scratch.
- Done when: renders the fully-resolved config with no errors.
physicalai fit --config <your.yaml> --print_config
- Done when:
- Smoke-test the wiring before a real run:
bash
physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true- Done when: one train + one val batch complete without shape or config errors.
- Run training, overriding on the CLI as needed:
bash
physicalai fit --config configs/physicalai/<name>.yaml --trainer.max_epochs 200- Done when: checkpoints appear under .
experiments/{name}/version_N/
- Done when: checkpoints appear under
- Validate / test / predict from a checkpoint:
bash
physicalai validate --config configs/physicalai/<name>.yaml --ckpt_path experiments/<name>/version_0/checkpoints/last.ckpt - Iterate on metrics, not just loss — confirm the val metric relevant to the task moves, and record the config + checkpoint that produced it.
当用户需要终端命令、下的文档、YAML配置、可复现实验或入口点行为时,采用此路径。
library/docs/how-to/- 从匹配策略类型的现有配置开始:复制现有配置而非从头编写。
- 完成标志:可渲染出完全解析的配置且无错误。
physicalai fit --config <your.yaml> --print_config
- 完成标志:
- 正式运行前进行组装冒烟测试:
bash
physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true- 完成标志:成功完成一个训练批次和一个验证批次,无形状或配置错误。
- 运行训练,必要时在CLI中覆盖配置:
bash
physicalai fit --config configs/physicalai/<name>.yaml --trainer.max_epochs 200- 完成标志:检查点出现在目录下。
experiments/{name}/version_N/
- 完成标志:检查点出现在
- 从检查点进行验证/测试/预测:
bash
physicalai validate --config configs/physicalai/<name>.yaml --ckpt_path experiments/<name>/version_0/checkpoints/last.ckpt - 针对指标而非仅损失进行迭代:确认与任务相关的验证指标有所变化,并记录生成该指标的配置和检查点。
Debugging a run
训练运行调试
- API: construct ,
Policy, andDataModuledirectly in a short script or test to isolate whether failure is in object construction, dataloading, or CLI parsing.Trainer - — one batch each stage; the first thing to try on any failure.
--trainer.fast_dev_run=true - — see the exact resolved config jsonargparse built.
--print_config - Shape/feature mismatches usually mean the datamodule's names or action dim disagree with the policy — cross-check against the
Featureskill.physicalai-train-adding-a-policy - Dataset download stalls: the run is pulling a LeRobot ; see the
repo_idskill.physicalai-train-working-with-datasets
- API层面:在简短脚本或测试中直接构造、
Policy和DataModule,以排查故障是出在对象构造、数据加载还是CLI解析环节。Trainer - — 每个阶段仅运行一个批次;出现任何故障时首先尝试此方法。
--trainer.fast_dev_run=true - — 查看jsonargparse生成的精确解析配置。
--print_config - 形状/特征不匹配通常意味着数据模块的名称或动作维度与策略不一致 — 可对照
Feature技能进行交叉检查。physicalai-train-adding-a-policy - 数据集下载停滞:此时运行任务正在拉取LeRobot的;详见
repo_id技能。physicalai-train-working-with-datasets
Required checks
必要检查项
- Config resolves () and
--print_configpasses before any long run.fast_dev_run - The equivalent Python API construction path passes for library-facing changes.
- /
acceleratormatch the installed backend extra (devices/xpu/cuda).cpu - New or renamed config fields stay consistent with the policy's class.
Config - Doc code blocks that show training commands still pass .
tests/test_docs.py
- 正式长时运行前,需确保配置可解析()且
--print_config测试通过。fast_dev_run - 针对库端变更,需确保等效Python API构造路径可通过测试。
- /
accelerator需与已安装的后端扩展(devices/xpu/cuda)匹配。cpu - 新增或重命名的配置字段需与策略的类保持一致。
Config - 文档中展示训练命令的代码块需通过测试。
tests/test_docs.py
Verify
验证步骤
bash
undefinedbash
undefinedfrom library/
进入library/目录
physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true
uv run pytest tests/unit/train
For API-facing changes, add or run an equivalent Python smoke test (not a shell heredoc) that constructs `Policy`, `DataModule`, and `Trainer` directly and calls `trainer.fit(...)`.physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true
uv run pytest tests/unit/train
针对API层面的变更,需添加或运行等效的Python冒烟测试(而非Shell heredoc),直接构造`Policy`、`DataModule`和`Trainer`并调用`trainer.fit(...)`。Related skills
相关技能
- — when the model itself needs changes.
physicalai-train-adding-a-policy - — for the
physicalai-train-working-with-datasetshalf of the config.data - — to evaluate a trained checkpoint in a gym.
physicalai-train-benchmarking-a-policy
- — 当需要修改模型本身时。
physicalai-train-adding-a-policy - — 针对配置中的
physicalai-train-working-with-datasets部分。data - — 在gym环境中评估已训练的检查点。
physicalai-train-benchmarking-a-policy