MCPcopy Create free account
hub / github.com/pytorch/examples / closure

Function closure

time_sequence_prediction/train.py:61–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59 for i in range(opt.steps):
60 print('STEP: ', i)
61 def closure():
62 optimizer.zero_grad()
63 out = seq(input)
64 loss = criterion(out, target)
65 print('loss:', loss.item())
66 loss.backward()
67 return loss
68 optimizer.step(closure)
69 # begin to predict, no need to track gradient here
70 with torch.no_grad():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected