Skip to content

Commit

Permalink
gradient clipping added back in
Browse files Browse the repository at this point in the history
  • Loading branch information
jdv committed Nov 30, 2023
1 parent 3b756a5 commit c98f423
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tutorials/examples/train_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def train(
loss.backward()

# Gradient Clipping.
# for p in gflownet.parameters():
# if p.ndim > 0 and p.grad is not None: # We do not clip logZ grad.
# p.grad.data.clamp_(
# -gradient_clip_value, gradient_clip_value
# ).nan_to_num_(0.0)
for p in gflownet.parameters():
if p.ndim > 0 and p.grad is not None: # We do not clip logZ grad.
p.grad.data.clamp_(
-gradient_clip_value, gradient_clip_value
).nan_to_num_(0.0)

optimizer.step()
states_visited += len(trajectories)
Expand Down

0 comments on commit c98f423

Please sign in to comment.