MCPcopy
hub / github.com/ddbourgin/numpy-ml / extract_grads

Method extract_grads

numpy_ml/tests/nn_torch_models.py:330–344  ·  view source on GitHub ↗
(self, X)

Source from the content-addressed store, hash-verified

328 return self.Y
329
330 def extract_grads(self, X):
331 self.forward(X)
332 self.loss = self.Y.sum()
333 self.loss.backward()
334 grads = {
335 "Xs": X,
336 "Sum": self.sum.detach().numpy(),
337 "Y": self.Y.detach().numpy(),
338 "dLdY": self.Y.grad.numpy(),
339 "dLdSum": self.sum.grad.numpy(),
340 }
341 grads.update(
342 {"dLdX{}".format(i + 1): xi.grad.numpy() for i, xi in enumerate(self.Xs)}
343 )
344 return grads
345
346
347class TorchMultiplyLayer(nn.Module):

Callers 1

test_AddLayerFunction · 0.95

Calls 3

forwardMethod · 0.95
backwardMethod · 0.45
updateMethod · 0.45

Tested by 1

test_AddLayerFunction · 0.76