diff --git a/src/lerobot/policies/pi0/modeling_pi0.py b/src/lerobot/policies/pi0/modeling_pi0.py index 58b5dc07b..a0263eb24 100644 --- a/src/lerobot/policies/pi0/modeling_pi0.py +++ b/src/lerobot/policies/pi0/modeling_pi0.py @@ -995,7 +995,14 @@ class PI0Policy(PreTrainedPolicy): # Initialize model without loading weights # Check if dataset_stats were provided in kwargs - model = cls(config, **kwargs) + if _transformers_available: + from transformers.modeling_utils import no_init_weights + + with no_init_weights(): + model = cls(config, **kwargs) + model.model.paligemma_with_expert.paligemma.tie_weights() + else: + model = cls(config, **kwargs) # Now manually load and remap the state dict try: diff --git a/src/lerobot/policies/pi05/modeling_pi05.py b/src/lerobot/policies/pi05/modeling_pi05.py index 3929e9ebf..2c57c4824 100644 --- a/src/lerobot/policies/pi05/modeling_pi05.py +++ b/src/lerobot/policies/pi05/modeling_pi05.py @@ -969,6 +969,7 @@ class PI05Policy(PreTrainedPolicy): # Check if dataset_stats were provided in kwargs if _transformers_available: from transformers.modeling_utils import no_init_weights + with no_init_weights(): model = cls(config, **kwargs) model.model.paligemma_with_expert.paligemma.tie_weights() diff --git a/src/lerobot/policies/pi0_fast/modeling_pi0_fast.py b/src/lerobot/policies/pi0_fast/modeling_pi0_fast.py index b4bc7ba22..6343672a7 100644 --- a/src/lerobot/policies/pi0_fast/modeling_pi0_fast.py +++ b/src/lerobot/policies/pi0_fast/modeling_pi0_fast.py @@ -895,7 +895,14 @@ class PI0FastPolicy(PreTrainedPolicy): # Initialize model without loading weights # Check if dataset_stats were provided in kwargs - model = cls(config, **kwargs) + if _transformers_available: + from transformers.modeling_utils import no_init_weights + + with no_init_weights(): + model = cls(config, **kwargs) + model.model.paligemma_with_expert.paligemma.tie_weights() + else: + model = cls(config, **kwargs) # Now manually load and remap the state dict try: