mirror of
https://github.com/saymrwulf/stable-baselines3.git
synced 2026-09-15 22:10:25 +00:00
Remove explict forward calls (#753)
* Remove explict forward calls * Changelog and commit checks. * Reverted test forward removal for super call. Co-authored-by: Anssi <kaneran21@hotmail.com>
This commit is contained in:
parent
954daaac37
commit
40bda9a918
6 changed files with 7 additions and 6 deletions
|
|
@ -26,6 +26,7 @@ Bug Fixes:
|
|||
- Fixed a bug in ``HumanOutputFormat``. Distinct keys truncated to the same prefix would overwrite each others value,
|
||||
resulting in only one being output. This now raises an error (this should only affect a small fraction of use cases
|
||||
with very long keys.)
|
||||
- Routing all the nn.Module calls through implicit rather than explict forward as per pytorch guidelines (@manuel-delverme)
|
||||
|
||||
Deprecations:
|
||||
^^^^^^^^^^^^^
|
||||
|
|
@ -917,4 +918,4 @@ And all the contributors:
|
|||
@benblack769 @bstee615 @c-rizz @skandermoalla @MihaiAnca13 @davidblom603 @ayeright @cyprienc
|
||||
@wkirgsn @AechPro @CUN-bjy @batu @IljaAvadiev @timokau @kachayev @cleversonahum
|
||||
@eleurent @ac-93 @cove9988 @theDebugger811 @hsuehch @Demetrio92 @thomasgubler @IperGiove @ScheiklP
|
||||
@simoninithomas @armandpl
|
||||
@simoninithomas @armandpl @manuel-delverme
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ class OnPolicyAlgorithm(BaseAlgorithm):
|
|||
with th.no_grad():
|
||||
# Convert to pytorch tensor or to TensorDict
|
||||
obs_tensor = obs_as_tensor(self._last_obs, self.device)
|
||||
actions, values, log_probs = self.policy.forward(obs_tensor)
|
||||
actions, values, log_probs = self.policy(obs_tensor)
|
||||
actions = actions.cpu().numpy()
|
||||
|
||||
# Rescale and perform action
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class QNetwork(BasePolicy):
|
|||
return self.q_net(self.extract_features(obs))
|
||||
|
||||
def _predict(self, observation: th.Tensor, deterministic: bool = True) -> th.Tensor:
|
||||
q_values = self.forward(observation)
|
||||
q_values = self(observation)
|
||||
# Greedy action
|
||||
action = q_values.argmax(dim=1).reshape(-1)
|
||||
return action
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ class Actor(BasePolicy):
|
|||
return self.action_dist.log_prob_from_params(mean_actions, log_std, **kwargs)
|
||||
|
||||
def _predict(self, observation: th.Tensor, deterministic: bool = False) -> th.Tensor:
|
||||
return self.forward(observation, deterministic)
|
||||
return self(observation, deterministic)
|
||||
|
||||
|
||||
class SACPolicy(BasePolicy):
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ class SAC(OffPolicyAlgorithm):
|
|||
# Compute actor loss
|
||||
# Alternative: actor_loss = th.mean(log_prob - qf1_pi)
|
||||
# Mean over all critic networks
|
||||
q_values_pi = th.cat(self.critic.forward(replay_data.observations, actions_pi), dim=1)
|
||||
q_values_pi = th.cat(self.critic(replay_data.observations, actions_pi), dim=1)
|
||||
min_qf_pi, _ = th.min(q_values_pi, dim=1, keepdim=True)
|
||||
actor_loss = (ent_coef * log_prob - min_qf_pi).mean()
|
||||
actor_losses.append(actor_loss.item())
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ class Actor(BasePolicy):
|
|||
def _predict(self, observation: th.Tensor, deterministic: bool = False) -> th.Tensor:
|
||||
# Note: the deterministic deterministic parameter is ignored in the case of TD3.
|
||||
# Predictions are always deterministic.
|
||||
return self.forward(observation)
|
||||
return self(observation)
|
||||
|
||||
|
||||
class TD3Policy(BasePolicy):
|
||||
|
|
|
|||
Loading…
Reference in a new issue