LeRobot documentation
Policies
Policies
Every policy inherits PreTrainedPolicy, which combines a torch.nn.Module with the Hub mixin, so any
policy can be pushed to and loaded from the Hugging Face Hub with the same two calls.
Each policy has its own guide with training recipes and results — ACT, SmolVLA, π₀, π₀.₅ and the rest are listed under Policies. To add one, see Adding a Policy.
PreTrainedPolicy
Base class for policy models.
forward
< source >( batch: dict[str, Tensor] ) → tuple[Tensor, dict | None]
summary
from_pretrained
< source >( pretrained_name_or_path: str | Pathconfig: PreTrainedConfig | None = Noneforce_download: bool = Falseresume_download: bool | None = Noneproxies: dict | None = Nonetoken: str | bool | None = Nonecache_dir: str | Path | None = Nonelocal_files_only: bool = Falserevision: str | None = Nonestrict: bool = False**kwargs )
The policy is set in evaluation mode by default using policy.eval() (dropout modules are
deactivated). To train it, you should first set it back in training mode with policy.train().
Returns the policy-specific parameters dict to be passed on to the optimizer.
Returns the action chunk (for action chunking policies) for a given observation, potentially in batch mode.
Child classes using action chunking should use this method within select_action to form the action chunk
cached for selection.
push_model_to_hub
< source >( cfg: TrainPipelineConfigpeft_model = Nonestate_dict: dict[str, Tensor] | None = Nonedataset_meta: LeRobotDatasetMetadata | None = None )
Parameters
- cfg (TrainPipelineConfig) — The training config; saved as train_config.json and used to render the model card.
- peft_model — The PEFT wrapper when training adapters, whose weights replace the full model weights in the published repo. Defaults to None.
- state_dict (dict[str, Tensor] | None) — Ignored; weights are now gathered internally when the policy is sharded. Defaults to None.
- dataset_meta (LeRobotDatasetMetadata | None) — Dataset metadata for the model card, if available. Defaults to None.
Publish this policy to the Hub.
Deprecated: use lerobot.common.train_utils.publish_trained_model() instead, which
also publishes the pre/post-processors alongside the model.
To be called whenever the environment is reset.
Does things like clearing caches.
Return one action to run in the environment (potentially in batch mode).
When the model uses a history of observations, or outputs a sequence of actions, this method deals with caching.
Whether this policy implements Real-Time Chunking inference semantics.
wrap_with_peft
< source >( peft_config = Nonepeft_cli_overrides: dict | None = None )
Wrap this policy with PEFT adapters for parameter-efficient fine-tuning.
This method is the single entry point for PEFT integration. Subclasses should
override _get_default_peft_targets() to provide default target modules, and _validate_peft_config() for policy-specific validation.
PreTrainedConfig
class lerobot.configs.PreTrainedConfig
< source >( n_obs_steps: int = 1input_features: dict[str, lerobot.configs.types.PolicyFeature] | None = <factory>output_features: dict[str, lerobot.configs.types.PolicyFeature] | None = <factory>device: str | None = Noneuse_amp: bool = Falseuse_peft: bool = Falsepush_to_hub: bool = Truerepo_id: str | None = Noneprivate: bool | None = Nonetags: list[str] | None = Nonelicense: str | None = Nonepretrained_path: pathlib.Path | None = Nonepretrained_revision: str | None = None )
Parameters
- n_obs_steps — Number of environment steps worth of observations to pass to the policy (takes the current step and additional steps going back).
- input_features — A dictionary defining the PolicyFeature of the input data for the policy. The key represents the input data name, and the value is PolicyFeature, which consists of FeatureType and shape attributes.
- output_features — A dictionary defining the PolicyFeature of the output data for the policy. The key represents the output data name, and the value is PolicyFeature, which consists of FeatureType and shape attributes.
- normalization_mapping — A dictionary that maps from a str value of FeatureType (e.g., “STATE”, “VISUAL”) to a corresponding NormalizationMode (e.g., NormalizationMode.MIN_MAX)
Base configuration class for policy models.
make_policy
lerobot.policies.make_policy
< source >( cfg: PreTrainedConfigds_meta: LeRobotDatasetMetadata | None = Noneenv_cfg: EnvConfig | None = Nonerename_map: dict[str, str] | None = Nonedefer_weight_load: bool = False ) → PreTrainedPolicy
Parameters
- cfg (PreTrainedConfig) — The configuration for the policy to be created. If
cfg.pretrained_pathis set, the policy will be loaded with weights from that path. - ds_meta (LeRobotDatasetMetadata | None) — Dataset metadata used to infer feature shapes and types. Also provides statistics for normalization layers.
- env_cfg (EnvConfig | None) — Environment configuration used to infer feature shapes and
types. One of
ds_metaorenv_cfgmust be provided. - rename_map (dict[str, str] | None) — Optional mapping of dataset or environment feature
keys to match expected policy feature names (e.g.,
"left"→"camera1"). - defer_weight_load (bool) — Build the exact policy
from_pretrainedwould build — same config resolution, same stats-derived buffers, same device placement and eval mode — but skip the safetensors weight load. Used when resuming from a DCP checkpoint, whose sharded weights stream in afteraccelerator.prepare()(the distributed checkpoint engine overwrites the random init).
Returns
PreTrainedPolicy
An instantiated and device-placed policy model.
Raises
ValueError or NotImplementedError
ValueError— If both or neither ofds_metaandenv_cfgare provided.NotImplementedError— If attempting to use an unsupported policy-backend combination (e.g., VQBeT with ‘mps’).
Instantiate a policy model.
This factory function handles the logic of creating a policy, which requires
determining the input and output feature shapes. These shapes can be derived
either from a LeRobotDatasetMetadata object or an EnvConfig object. The function
can either initialize a new policy from scratch or load a pretrained one.