mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-21 17:01:53 +00:00
fix: move algorithm-owned modules to the policy device
This commit is contained in:
@@ -74,6 +74,7 @@ class SACAlgorithm(RLAlgorithm):
|
|||||||
self._init_critic_encoder()
|
self._init_critic_encoder()
|
||||||
self._init_critics()
|
self._init_critics()
|
||||||
self._init_temperature()
|
self._init_temperature()
|
||||||
|
self._move_to_device()
|
||||||
|
|
||||||
def _init_critic_encoder(self) -> None:
|
def _init_critic_encoder(self) -> None:
|
||||||
"""Build or share the encoder used by critics."""
|
"""Build or share the encoder used by critics."""
|
||||||
@@ -131,6 +132,14 @@ class SACAlgorithm(RLAlgorithm):
|
|||||||
dim = action_dim + (1 if self.config.num_discrete_actions is not None else 0)
|
dim = action_dim + (1 if self.config.num_discrete_actions is not None else 0)
|
||||||
self.target_entropy = -np.prod(dim) / 2
|
self.target_entropy = -np.prod(dim) / 2
|
||||||
|
|
||||||
|
def _move_to_device(self) -> None:
|
||||||
|
"""Move algorithm-owned modules to the policy device."""
|
||||||
|
self.critic_ensemble.to(self._device)
|
||||||
|
self.critic_target.to(self._device)
|
||||||
|
self.log_alpha = nn.Parameter(self.log_alpha.data.to(self._device))
|
||||||
|
if hasattr(self, "discrete_critic_target"):
|
||||||
|
self.discrete_critic_target.to(self._device)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self) -> float:
|
def temperature(self) -> float:
|
||||||
return self.log_alpha.exp().item()
|
return self.log_alpha.exp().item()
|
||||||
|
|||||||
Reference in New Issue
Block a user