MCPcopy Index your code
hub / github.com/pytorch/tutorials / loss_batch

Function loss_batch

beginner_source/nn_tutorial.py:633–641  ·  view source on GitHub ↗
(model, loss_func, xb, yb, opt=None)

Source from the content-addressed store, hash-verified

631
632
633def loss_batch(model, loss_func, xb, yb, opt=None):
634 loss = loss_func(model(xb), yb)
635
636 if opt is not None:
637 loss.backward()
638 opt.step()
639 opt.zero_grad()
640
641 return loss.item(), len(xb)
642
643###############################################################################
644# ``fit`` runs the necessary operations to train our model and compute the

Callers 1

fitFunction · 0.85

Calls 3

stepMethod · 0.80
modelFunction · 0.70
backwardMethod · 0.45

Tested by

no test coverage detected