Skip to content

Commit

Permalink
closure
Browse files Browse the repository at this point in the history
  • Loading branch information
inikishev authored Dec 25, 2024
1 parent 50ee49d commit 7e5a200
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Some optimizers require closure, which should look like this:
def closure(backward = True):
preds = model(inputs)
loss = loss_fn(preds, targets)

# skip this part if you have no gradients and use zeroth order methods, but keep the unused backward argument.
if backward:
optimizer.zero_grad()
loss.backward()
Expand Down

0 comments on commit 7e5a200

Please sign in to comment.