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

Function compute_loss

intermediate_source/per_sample_grads.py:137–143  ·  view source on GitHub ↗
(params, buffers, sample, target)

Source from the content-addressed store, hash-verified

135# use ``torch.unsqueeze`` to add a batch dimension.
136
137def compute_loss(params, buffers, sample, target):
138 batch = sample.unsqueeze(0)
139 targets = target.unsqueeze(0)
140
141 predictions = functional_call(model, (params, buffers), (batch,))
142 loss = loss_fn(predictions, targets)
143 return loss
144
145######################################################################
146# Now, let’s use the ``grad`` transform to create a new function that computes

Callers

nothing calls this directly

Calls 1

loss_fnFunction · 0.85

Tested by

no test coverage detected