Skip to content
Open
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions d4rl/rlkit/torch/sac/cql.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def _get_policy_actions(self, obs, num_actions, network=None):
obs_temp, reparameterize=True, return_log_prob=True,
)
if not self.discrete:
return new_obs_actions, new_obs_log_pi.view(obs.shape[0], num_actions, 1)
return new_obs_actions.detach(), new_obs_log_pi.view(obs.shape[0], num_actions, 1).detach()
else:
return new_obs_actions
return new_obs_actions.detach()

def train_from_torch(self, batch):
self._current_epoch += 1
Expand Down Expand Up @@ -283,6 +283,11 @@ def train_from_torch(self, batch):
"""
Update networks
"""
self._num_policy_update_steps += 1
self.policy_optimizer.zero_grad()
policy_loss.backward(retain_graph=False)
self.policy_optimizer.step()

# Update the Q-functions iff
self._num_q_update_steps += 1
self.qf1_optimizer.zero_grad()
Expand All @@ -294,11 +299,6 @@ def train_from_torch(self, batch):
qf2_loss.backward(retain_graph=True)
self.qf2_optimizer.step()

self._num_policy_update_steps += 1
self.policy_optimizer.zero_grad()
policy_loss.backward(retain_graph=False)
self.policy_optimizer.step()

"""
Soft Updates
"""
Expand Down