physicalai-train-adding-a-policy
Original:🇺🇸 English
Translated
Adds or modifies a Physical AI Studio policy under library/src/physicalai/policies. Use when creating a new policy family with the config/model/policy split, registering it in the get_policy factory and package exports, or keeping a policy compatible with Lightning training and export. Covers Pi0.5, Pi0, ACT, GR00T, SmolVLA, and LeRobot-wrapped policies.
9installs
Added on
NPX Install
npx skill4agent add open-edge-platform/physical-ai-studio physicalai-train-adding-a-policyTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Adding a Studio Policy
Policies live in . Each family is a Lightning-facing wrapping a , split across three files. Base classes are in ( in , in ); shared / types come from Runtime () — see Runtime docs and .
library/src/physicalai/policies/<name>/Policytorch.nn.ModuleModelpolicies/base/Policypolicy.pyModelmodel.pyConfigFromConfigphysicalai.configuse-from-configconfigurationWorkflow
-
Read a nearby family first. Study(current reference implementation):
policies/pi05/(config.py),Pi05Config(Config)(model.py),Pi05Model(Model)(policy.py),Pi05(ExportablePolicyMixin, Policy), and any extra modules the architecture needs (e.g.preprocessor.py). For a deliberately minimal family,pi_gemma.pyis a smaller three-file layout without the VLM stack.policies/act/- Done when: you can name which existing file each new file mirrors.
-
Create the three-file split in:
policies/<name>/- —
config.py, all hyperparameters as typed fields.<Name>Config(Config) - —
model.py, pure<Name>Model(Model)logic.torch.nn.Module - —
policy.py(add<Name>(Policy)only when export is implemented).ExportablePolicyMixin - Done when: imports cleanly.
from physicalai.policies.<name> import <Name>, <Name>Config, <Name>Model
-
Implement the policy interface used by both training and inference through the base:
Policy- — training path; return values compatible with
forward(...).training_step - — inference path; return a tensor with the configured action horizon.
predict_action_chunk(...) - — use base-class action-queue behavior unless a specialized flow is justified.
select_action(...) - Done when: shapes match the checks below for a synthetic batch.
-
Register the family so both API and CLI users can find it:
- Add exports to (
policies/__init__.pyand imports, e.g.__all__,<Name>,<Name>Config).<Name>Model - Add the lowercase name to the /
get_physicalai_policy_class(...)dispatch inget_policy(...).policies/__init__.py - Done when: works,
from physicalai.policies import <Name>, get_policyreturns an instance, andget_policy("<name>")resolves.--model physicalai.policies.<Name>
- Add exports to
-
Prove direct API construction before adding CLI config:python
from physicalai.policies import get_policy policy = get_policy("<name>")- Done when: direct construction, config round-trip, and synthetic /
forward(...)shape checks pass.predict_action_chunk(...)
- Done when: direct construction, config round-trip, and synthetic
-
Add a training config inwhen the policy is user-facing from the CLI. Wire
library/configs/physicalai/<name>.yaml, amodel.class_path(usuallydata.class_path), andphysicalai.data.lerobot.LeRobotDataModule. Mirrortrainer.*.configs/physicalai/pi05.yaml- Done when: completes one step.
physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true
- Done when:
-
Wire export only when ready. Addand a valid sample input, then follow the
ExportablePolicyMixinskill. If export is intentionally unsupported, say so explicitly in the policy docstring.physicalai-train-exporting-and-validating -
Add tests undernext to existing policy tests: at least one construction/config path and one shape-validation test.
library/tests/unit/policies/- Done when: passes.
uv run pytest tests/unit/policies -k <name>
- Done when:
-
Update docs if the policy is user-visible:and any config/API examples.
library/docs/explanation/policy/
Required checks
Account for every item below (not just "looks fine"):
- Action shape semantics — batch, horizon/chunk length, and action dimension are correct and unchanged from the family's convention.
- Observation features — feature names align with dataset/config conventions (:
data/observation.py,Feature).FeatureType - API construction path — imports, , direct constructor use, and synthetic shape checks pass without CLI involvement.
get_policy(...) - Config path — construction works through the jsonargparse CLI path used by (
physicalai fit/class_path) when the policy is CLI-visible.init_args - Heavy dependencies — gate large families behind an optional extra in and import lazily, matching
library/pyproject.toml/pi05/pi0/groot.smolvla - No silent contract changes — do not alter action dims, feature names, or preprocessing without coordinating export/Runtime.
Verify
From :
library/bash
uv run pytest tests/unit/policies -k <name>
physicalai fit --config configs/physicalai/<name>.yaml --trainer.fast_dev_run=true
prek run --all-files library/References
- — the
references/base-classes.md/Policycontract and file-split expectations.Model