Skip to content

Commit b7f97b2

Browse files
author
Xingyu Lin
authored
Optimize actor before the critic (#109)
The actor should be optimized first. Otherwise, the weights of the cirtic would have been changed when back propagating the gradients for the actor. The latter will create an error in pytorch 1.5.0
1 parent f136e14 commit b7f97b2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rlkit/torch/sac/sac.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def train_from_torch(self, batch):
132132
"""
133133
Update networks
134134
"""
135+
self.policy_optimizer.zero_grad()
136+
policy_loss.backward()
137+
self.policy_optimizer.step()
138+
135139
self.qf1_optimizer.zero_grad()
136140
qf1_loss.backward()
137141
self.qf1_optimizer.step()
@@ -140,10 +144,6 @@ def train_from_torch(self, batch):
140144
qf2_loss.backward()
141145
self.qf2_optimizer.step()
142146

143-
self.policy_optimizer.zero_grad()
144-
policy_loss.backward()
145-
self.policy_optimizer.step()
146-
147147
"""
148148
Soft Updates
149149
"""

0 commit comments

Comments
 (0)