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

Method extract_grads

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

Source from the content-addressed store, hash-verified

1553 self.out1.retain_grad()
1554
1555 def extract_grads(self, X):
1556 self.forward(X)
1557 self.loss1 = self.out1.sum()
1558 self.loss1.backward()
1559 grads = {
1560 "X": self.X.detach().numpy(),
1561 "b": self.layer1.bias.detach().numpy(),
1562 "W": self.layer1.weight.detach().numpy(),
1563 "y": self.out1.detach().numpy(),
1564 "dLdy": self.out1.grad.numpy(),
1565 "dLdZ": self.z1.grad.numpy(),
1566 "dLdB": self.layer1.bias.grad.numpy(),
1567 "dLdW": self.layer1.weight.grad.numpy(),
1568 "dLdX": self.X.grad.numpy(),
1569 }
1570 return grads
1571
1572
1573class TorchEmbeddingLayer(nn.Module):

Callers 1

test_FullyConnectedFunction · 0.95

Calls 2

forwardMethod · 0.95
backwardMethod · 0.45

Tested by 1

test_FullyConnectedFunction · 0.76