Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d89d088
init model
mshukor May 28, 2025
8d6acb3
load model
mshukor May 28, 2025
4719f41
training the model
mshukor May 28, 2025
97d609f
precommit
mshukor May 28, 2025
44b4578
precommit fix
mshukor May 28, 2025
1c5a358
launch training
mshukor May 28, 2025
a9d425f
cleaning
mshukor May 28, 2025
a3a73f6
add stuff related to real eval
mshukor May 30, 2025
ac0f2e9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 30, 2025
8097f66
clean train
mshukor May 30, 2025
302bdd5
install accelerate
mshukor May 30, 2025
312d45b
skipping keys containing lists, bc the robot gives nothing but tensors
May 31, 2025
6d776f7
minor fixes iterating on steven's comments
May 31, 2025
3ae5583
clean gitignore
mshukor Jun 1, 2025
496c9d0
remove train script
mshukor Jun 1, 2025
4027d97
fix for observations with text
mshukor Jun 1, 2025
5fd40b1
avoid import pytest
mshukor Jun 1, 2025
95a16c6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 1, 2025
7f3fe83
instructions to train the model
mshukor Jun 1, 2025
825e0e1
instructions for smolvla
mshukor Jun 1, 2025
2d98bf6
Merge branch 'main' into user/mshukor/smolvla_fix
imstevenpmwork Jun 2, 2025
492b181
fix: device to send VLM to is found automatically
Jun 2, 2025
17625ca
fix: copyright (time flies when having fun)
Jun 2, 2025
093773f
remove: commented out line
Jun 2, 2025
64cc944
fix: docstring more informative
Jun 2, 2025
60389f7
Apply suggestions from code review
danaaubakirova Jun 2, 2025
73fd12d
minor fixes
mshukor Jun 2, 2025
1fd53b4
more comments
mshukor Jun 2, 2025
c2d6457
assume always there is state
mshukor Jun 2, 2025
345bc8b
precommit
mshukor Jun 2, 2025
31c30cc
Merge branch 'main' into user/mshukor/smolvla_fix
imstevenpmwork Jun 2, 2025
efeef4e
fixes for merging (#1188)
danaaubakirova Jun 3, 2025
209f89a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 3, 2025
95f3da4
update (#1192)
danaaubakirova Jun 3, 2025
a211a98
fix(control_utils): remove robot_type from the observation frame (#1190)
imstevenpmwork Jun 3, 2025
068f382
chore(init): remove `smolvla` from available_policies to skip it from…
imstevenpmwork Jun 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions lerobot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,7 @@
)

# lists all available policies from `lerobot/common/policies`
available_policies = [
"act",
"diffusion",
"tdmpc",
"vqbet",
]
available_policies = ["act", "diffusion", "tdmpc", "vqbet"]

# lists all available robots from `lerobot/common/robot_devices/robots`
available_robots = [
Expand Down
1 change: 1 addition & 0 deletions lerobot/common/policies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
from .act.configuration_act import ACTConfig as ACTConfig
from .diffusion.configuration_diffusion import DiffusionConfig as DiffusionConfig
from .pi0.configuration_pi0 import PI0Config as PI0Config
from .smolvla.configuration_smolvla import SmolVLAConfig as SmolVLAConfig
from .tdmpc.configuration_tdmpc import TDMPCConfig as TDMPCConfig
from .vqbet.configuration_vqbet import VQBeTConfig as VQBeTConfig
7 changes: 7 additions & 0 deletions lerobot/common/policies/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from lerobot.common.policies.pi0.configuration_pi0 import PI0Config
from lerobot.common.policies.pi0fast.configuration_pi0fast import PI0FASTConfig
from lerobot.common.policies.pretrained import PreTrainedPolicy
from lerobot.common.policies.smolvla.configuration_smolvla import SmolVLAConfig
from lerobot.common.policies.tdmpc.configuration_tdmpc import TDMPCConfig
from lerobot.common.policies.vqbet.configuration_vqbet import VQBeTConfig
from lerobot.configs.policies import PreTrainedConfig
Expand Down Expand Up @@ -59,6 +60,10 @@ def get_policy_class(name: str) -> PreTrainedPolicy:
from lerobot.common.policies.pi0fast.modeling_pi0fast import PI0FASTPolicy

return PI0FASTPolicy
elif name == "smolvla":
from lerobot.common.policies.smolvla.modeling_smolvla import SmolVLAPolicy

return SmolVLAPolicy
else:
raise NotImplementedError(f"Policy with name {name} is not implemented.")

Expand All @@ -76,6 +81,8 @@ def make_policy_config(policy_type: str, **kwargs) -> PreTrainedConfig:
return PI0Config(**kwargs)
elif policy_type == "pi0fast":
return PI0FASTConfig(**kwargs)
elif policy_type == "smolvla":
return SmolVLAConfig(**kwargs)
else:
raise ValueError(f"Policy type '{policy_type}' is not available.")

Expand Down
154 changes: 154 additions & 0 deletions lerobot/common/policies/smolvla/configuration_smolvla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Copyright 2025 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from dataclasses import dataclass, field

from lerobot.common.optim.optimizers import AdamWConfig
from lerobot.common.optim.schedulers import (
CosineDecayWithWarmupSchedulerConfig,
)
from lerobot.configs.policies import PreTrainedConfig
from lerobot.configs.types import FeatureType, NormalizationMode, PolicyFeature


@PreTrainedConfig.register_subclass("smolvla")
@dataclass
class SmolVLAConfig(PreTrainedConfig):
# Input / output structure.
n_obs_steps: int = 1
chunk_size: int = 50
n_action_steps: int = 50

normalization_mapping: dict[str, NormalizationMode] = field(
default_factory=lambda: {
"VISUAL": NormalizationMode.IDENTITY,
"STATE": NormalizationMode.MEAN_STD,
"ACTION": NormalizationMode.MEAN_STD,
}
)

# Shorter state and action vectors will be padded
max_state_dim: int = 32
max_action_dim: int = 32

# Image preprocessing
resize_imgs_with_padding: tuple[int, int] = (512, 512)

# Add empty images. Used by smolvla_aloha_sim which adds the empty
# left and right wrist cameras in addition to the top camera.
empty_cameras: int = 0

# Converts the joint and gripper values from the standard Aloha space to
# the space used by the pi internal runtime which was used to train the base model.
adapt_to_pi_aloha: bool = False

# Converts joint dimensions to deltas with respect to the current state before passing to the model.
# Gripper dimensions will remain in absolute values.
use_delta_joint_actions_aloha: bool = False

# Tokenizer
tokenizer_max_length: int = 48

# Decoding
num_steps: int = 10

# Attention utils
use_cache: bool = True

# Finetuning settings
freeze_vision_encoder: bool = True
train_expert_only: bool = True
train_state_proj: bool = True

# Training presets
optimizer_lr: float = 1e-4
optimizer_betas: tuple[float, float] = (0.9, 0.95)
optimizer_eps: float = 1e-8
optimizer_weight_decay: float = 1e-10
optimizer_grad_clip_norm: float = 10

scheduler_warmup_steps: int = 1_000
scheduler_decay_steps: int = 30_000
scheduler_decay_lr: float = 2.5e-6

vlm_model_name: str = "HuggingFaceTB/SmolVLM2-500M-Video-Instruct" # Select the VLM backbone.
load_vlm_weights: bool = False # Set to True in case of training the expert from scratch. True when init from pretrained SmolVLA weights

add_image_special_tokens: bool = False # Whether to use special image tokens around image features.

attention_mode: str = "cross_attn"

prefix_length: int = -1

pad_language_to: str = "longest" # "max_length"

num_expert_layers: int = -1 # Less or equal to 0 is the default where the action expert has the same number of layers of VLM. Otherwise the expert have less layers.
num_vlm_layers: int = 16 # Number of layers used in the VLM (first num_vlm_layers layers)
self_attn_every_n_layers: int = 2 # Interleave SA layers each self_attn_every_n_layers
expert_width_multiplier: float = 0.75 # The action expert hidden size (wrt to the VLM)

min_period: float = 4e-3 # sensitivity range for the timestep used in sine-cosine positional encoding
max_period: float = 4.0

def __post_init__(self):
super().__post_init__()

"""Input validation (not exhaustive)."""
if self.n_action_steps > self.chunk_size:
raise ValueError(
f"The chunk size is the upper bound for the number of action steps per model invocation. Got "
f"{self.n_action_steps} for `n_action_steps` and {self.chunk_size} for `chunk_size`."
)
if self.use_delta_joint_actions_aloha:
raise NotImplementedError(
"`use_delta_joint_actions_aloha` is used by smolvla for aloha real models. It is not ported yet in LeRobot."
)

def validate_features(self) -> None:
for i in range(self.empty_cameras):
key = f"observation.images.empty_camera_{i}"
empty_camera = PolicyFeature(
type=FeatureType.VISUAL,
shape=(3, 480, 640),
)
self.input_features[key] = empty_camera

def get_optimizer_preset(self) -> AdamWConfig:
return AdamWConfig(
lr=self.optimizer_lr,
betas=self.optimizer_betas,
eps=self.optimizer_eps,
weight_decay=self.optimizer_weight_decay,
grad_clip_norm=self.optimizer_grad_clip_norm,
)

def get_scheduler_preset(self):
return CosineDecayWithWarmupSchedulerConfig(
peak_lr=self.optimizer_lr,
decay_lr=self.scheduler_decay_lr,
num_warmup_steps=self.scheduler_warmup_steps,
num_decay_steps=self.scheduler_decay_steps,
)

@property
def observation_delta_indices(self) -> list:
return [0]

@property
def action_delta_indices(self) -> list:
return list(range(self.chunk_size))

@property
def reward_delta_indices(self) -> None:
return None
Loading
Loading