From 69f0b1d814be22fccfb53d0e50b2927c4a18f553 Mon Sep 17 00:00:00 2001 From: Pepijn Date: Mon, 22 Dec 2025 14:50:58 +0100 Subject: [PATCH] run precommit and fix issues --- docs/source/peft_training.mdx | 2 +- src/lerobot/configs/policies.py | 8 ++++++++ src/lerobot/policies/factory.py | 2 +- src/lerobot/scripts/lerobot_eval.py | 11 ++++++----- src/lerobot/scripts/lerobot_train.py | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/source/peft_training.mdx b/docs/source/peft_training.mdx index 8370ab001..dd0b10075 100644 --- a/docs/source/peft_training.mdx +++ b/docs/source/peft_training.mdx @@ -41,7 +41,7 @@ There are more complex methods that have more parameters. These are not yet supp if you want to see a specific PEFT method supported. By default, PEFT will target the `q_proj` and `v_proj` layers of the LM expert in SmolVLA. It will also target the -state and action projection matrices as they are most likely taks-dependent. If you need to target different layers +state and action projection matrices as they are most likely task-dependent. If you need to target different layers you can use `--peft.target_modules` to specify which layers to target. You can refer to the respective PEFT method's documentation to see what inputs are supported, (e.g., [LoRA's target_modules documentation](https://huggingface.co/docs/peft/main/en/package_reference/lora#peft.LoraConfig.target_modules)). Usually a list of suffixes or a regex are supported. For example, to target the MLPs of the `lm_expert` instead of diff --git a/src/lerobot/configs/policies.py b/src/lerobot/configs/policies.py index cc97142a3..79b6b1ae1 100644 --- a/src/lerobot/configs/policies.py +++ b/src/lerobot/configs/policies.py @@ -129,6 +129,8 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno @property def robot_state_feature(self) -> PolicyFeature | None: + if self.input_features is None: + return None for ft_name, ft in self.input_features.items(): if ft.type is FeatureType.STATE and ft_name == OBS_STATE: return ft @@ -136,6 +138,8 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno @property def env_state_feature(self) -> PolicyFeature | None: + if self.input_features is None: + return None for _, ft in self.input_features.items(): if ft.type is FeatureType.ENV: return ft @@ -143,10 +147,14 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno @property def image_features(self) -> dict[str, PolicyFeature]: + if self.input_features is None: + return {} return {key: ft for key, ft in self.input_features.items() if ft.type is FeatureType.VISUAL} @property def action_feature(self) -> PolicyFeature | None: + if self.output_features is None: + return None for ft_name, ft in self.output_features.items(): if ft.type is FeatureType.ACTION and ft_name == ACTION: return ft diff --git a/src/lerobot/policies/factory.py b/src/lerobot/policies/factory.py index fb43eacdb..8c414f235 100644 --- a/src/lerobot/policies/factory.py +++ b/src/lerobot/policies/factory.py @@ -474,7 +474,7 @@ def make_policy( if not cfg.pretrained_path and cfg.use_peft: raise ValueError( "Instantiating a policy with `use_peft=True` without a checkpoint is not supported since that requires " - "the PEFT config parameters to be set. For traning with PEFT, see `lerobot_train.py` on how to do that." + "the PEFT config parameters to be set. For training with PEFT, see `lerobot_train.py` on how to do that." ) if cfg.pretrained_path and not cfg.use_peft: diff --git a/src/lerobot/scripts/lerobot_eval.py b/src/lerobot/scripts/lerobot_eval.py index 4b7c6e99a..243124cc0 100644 --- a/src/lerobot/scripts/lerobot_eval.py +++ b/src/lerobot/scripts/lerobot_eval.py @@ -278,16 +278,17 @@ def eval_policy( raise ValueError("If max_episodes_rendered > 0, videos_dir must be provided.") if not isinstance(policy, PreTrainedPolicy): - exc = ValueError( - f"Policy of type 'PreTrainedPolicy' is expected, but type '{type(policy)}' was provided." - ) try: from peft import PeftModel if not isinstance(policy, PeftModel): - raise exc + raise ValueError( + f"Policy of type 'PreTrainedPolicy' is expected, but type '{type(policy)}' was provided." + ) except ImportError: - raise exc + raise ValueError( + "PEFT is required to evaluate a PEFT-trained policy. Please install PEFT using `pip install peft`." + ) from None start = time.time() policy.eval() diff --git a/src/lerobot/scripts/lerobot_train.py b/src/lerobot/scripts/lerobot_train.py index 5a1c13a6e..286c69906 100644 --- a/src/lerobot/scripts/lerobot_train.py +++ b/src/lerobot/scripts/lerobot_train.py @@ -183,7 +183,7 @@ def wrap_policy_in_peft_model(cfg, policy): if cfg.policy.type == "smolvla" and not cfg.policy.load_vlm_weights: logging.warning( - "Traning SmolVLA from scratch using PEFT. This is unlikely to yield good results. Set " + "Training SmolVLA from scratch using PEFT. This is unlikely to yield good results. Set " "`load_vlm_weights=True` to fine-tune the existing policy." )