LeRobot documentation

Policies

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.6.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

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

class lerobot.policies.PreTrainedPolicy

< >

( config: PreTrainedConfig*inputs**kwargs )

Base class for policy models.

forward

< >

( batch: dict[str, Tensor] ) tuple[Tensor, dict | None]

Parameters

  • batch (dict[str, Tensor]) — description

Returns

tuple[Tensor, dict | None]

The loss and potentially other information. Apart from the loss which is a Tensor, all other items should be logging-friendly, native Python types.

summary

from_pretrained

< >

( 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().

get_optim_params

< >

( )

Returns the policy-specific parameters dict to be passed on to the optimizer.

predict_action_chunk

< >

( batch: dict[str, Tensor]**kwargs: Unpack[ActionSelectKwargs] )

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

< >

( 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.

reset

< >

( )

To be called whenever the environment is reset.

Does things like clearing caches.

select_action

< >

( batch: dict[str, Tensor]**kwargs: Unpack[ActionSelectKwargs] )

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.

supports_rtc

< >

( )

Whether this policy implements Real-Time Chunking inference semantics.

wrap_with_peft

< >

( peft_config = Nonepeft_cli_overrides: dict | None = None )

Parameters

  • peft_config — Optional PEFT adapter configuration (e.g., LoraConfig). If provided, used directly (with CLI overrides applied).
  • peft_cli_overrides — Optional dict of CLI overrides (method_type, target_modules, r, etc.) These are merged with policy defaults to build the final config.

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

< >

( 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

< >

( 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_path is 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_meta or env_cfg must 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_pretrained would 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 after accelerator.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 of ds_meta and env_cfg are 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.

Update on GitHub