mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-23 17:56:07 +00:00
Merge branch 'feat/pretrained-revision' into test/gs-gym-integration
This commit is contained in:
@@ -79,6 +79,8 @@ class PreTrainedConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC): # type: igno
|
|||||||
# Either the repo ID of a model hosted on the Hub or a path to a directory containing weights
|
# Either the repo ID of a model hosted on the Hub or a path to a directory containing weights
|
||||||
# saved using `Policy.save_pretrained`. If not provided, the policy is initialized from scratch.
|
# saved using `Policy.save_pretrained`. If not provided, the policy is initialized from scratch.
|
||||||
pretrained_path: Path | None = None
|
pretrained_path: Path | None = None
|
||||||
|
# Optional Hub revision (commit hash, branch, or tag) to pin the pretrained model version.
|
||||||
|
pretrained_revision: str | None = None
|
||||||
|
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
if not self.device or not is_torch_device_available(self.device):
|
if not self.device or not is_torch_device_available(self.device):
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ class RewardModelConfig(draccus.ChoiceRegistry, HubMixin, abc.ABC):
|
|||||||
device: str | None = None
|
device: str | None = None
|
||||||
|
|
||||||
pretrained_path: str | None = None
|
pretrained_path: str | None = None
|
||||||
|
# Optional Hub revision (commit hash, branch, or tag) to pin the pretrained reward model version.
|
||||||
|
pretrained_revision: str | None = None
|
||||||
|
|
||||||
push_to_hub: bool = False
|
push_to_hub: bool = False
|
||||||
repo_id: str | None = None
|
repo_id: str | None = None
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ class ProcessorConfigKwargs(TypedDict, total=False):
|
|||||||
def make_pre_post_processors(
|
def make_pre_post_processors(
|
||||||
policy_cfg: PreTrainedConfig,
|
policy_cfg: PreTrainedConfig,
|
||||||
pretrained_path: str | None = None,
|
pretrained_path: str | None = None,
|
||||||
|
pretrained_revision: str | None = None,
|
||||||
**kwargs: Unpack[ProcessorConfigKwargs],
|
**kwargs: Unpack[ProcessorConfigKwargs],
|
||||||
) -> tuple[
|
) -> tuple[
|
||||||
PolicyProcessorPipeline[dict[str, Any], dict[str, Any]],
|
PolicyProcessorPipeline[dict[str, Any], dict[str, Any]],
|
||||||
@@ -309,6 +310,7 @@ def make_pre_post_processors(
|
|||||||
overrides=kwargs.get("preprocessor_overrides", {}),
|
overrides=kwargs.get("preprocessor_overrides", {}),
|
||||||
to_transition=batch_to_transition,
|
to_transition=batch_to_transition,
|
||||||
to_output=transition_to_batch,
|
to_output=transition_to_batch,
|
||||||
|
revision=pretrained_revision,
|
||||||
)
|
)
|
||||||
postprocessor = PolicyProcessorPipeline.from_pretrained(
|
postprocessor = PolicyProcessorPipeline.from_pretrained(
|
||||||
pretrained_model_name_or_path=pretrained_path,
|
pretrained_model_name_or_path=pretrained_path,
|
||||||
@@ -318,6 +320,7 @@ def make_pre_post_processors(
|
|||||||
overrides=kwargs.get("postprocessor_overrides", {}),
|
overrides=kwargs.get("postprocessor_overrides", {}),
|
||||||
to_transition=policy_action_to_transition,
|
to_transition=policy_action_to_transition,
|
||||||
to_output=transition_to_policy_action,
|
to_output=transition_to_policy_action,
|
||||||
|
revision=pretrained_revision,
|
||||||
)
|
)
|
||||||
_reconnect_relative_absolute_steps(preprocessor, postprocessor)
|
_reconnect_relative_absolute_steps(preprocessor, postprocessor)
|
||||||
return preprocessor, postprocessor
|
return preprocessor, postprocessor
|
||||||
@@ -557,6 +560,7 @@ def make_policy(
|
|||||||
# Load a pretrained policy and override the config if needed (for example, if there are inference-time
|
# Load a pretrained policy and override the config if needed (for example, if there are inference-time
|
||||||
# hyperparameters that we want to vary).
|
# hyperparameters that we want to vary).
|
||||||
kwargs["pretrained_name_or_path"] = cfg.pretrained_path
|
kwargs["pretrained_name_or_path"] = cfg.pretrained_path
|
||||||
|
kwargs["revision"] = cfg.pretrained_revision
|
||||||
policy = policy_cls.from_pretrained(**kwargs)
|
policy = policy_cls.from_pretrained(**kwargs)
|
||||||
elif cfg.pretrained_path and cfg.use_peft:
|
elif cfg.pretrained_path and cfg.use_peft:
|
||||||
# Load a pretrained PEFT model on top of the policy. The pretrained path points to the folder/repo
|
# Load a pretrained PEFT model on top of the policy. The pretrained path points to the folder/repo
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ def make_reward_model(cfg: RewardModelConfig, **kwargs) -> PreTrainedRewardModel
|
|||||||
|
|
||||||
if cfg.pretrained_path:
|
if cfg.pretrained_path:
|
||||||
kwargs["pretrained_name_or_path"] = cfg.pretrained_path
|
kwargs["pretrained_name_or_path"] = cfg.pretrained_path
|
||||||
|
kwargs["revision"] = cfg.pretrained_revision
|
||||||
reward_model = reward_cls.from_pretrained(**kwargs)
|
reward_model = reward_cls.from_pretrained(**kwargs)
|
||||||
else:
|
else:
|
||||||
reward_model = reward_cls(**kwargs)
|
reward_model = reward_cls(**kwargs)
|
||||||
|
|||||||
@@ -346,6 +346,7 @@ def train(cfg: TrainPipelineConfig, accelerator: "Accelerator | None" = None):
|
|||||||
preprocessor, postprocessor = make_pre_post_processors(
|
preprocessor, postprocessor = make_pre_post_processors(
|
||||||
policy_cfg=cfg.policy,
|
policy_cfg=cfg.policy,
|
||||||
pretrained_path=processor_pretrained_path,
|
pretrained_path=processor_pretrained_path,
|
||||||
|
pretrained_revision=getattr(cfg.policy, "pretrained_revision", None),
|
||||||
**processor_kwargs,
|
**processor_kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user