MCPcopy
hub / github.com/meta-pytorch/captum / test_gradient_multiinput

Method test_gradient_multiinput

tests/utils/test_gradient.py:70–76  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

68 assertTensorAlmostEqual(self, input.grad, [[14.0]], delta=0.0, mode="max")
69
70 def test_gradient_multiinput(self) -> None:
71 model = BasicModel6_MultiTensor()
72 input1 = torch.tensor([[-3.0, -5.0]], requires_grad=True)
73 input2 = torch.tensor([[-5.0, 2.0]], requires_grad=True)
74 grads = compute_gradients(model, (input1, input2))
75 assertTensorAlmostEqual(self, grads[0], [[0.0, 1.0]], delta=0.01, mode="max")
76 assertTensorAlmostEqual(self, grads[1], [[0.0, 1.0]], delta=0.01, mode="max")
77
78 def test_gradient_additional_args(self) -> None:
79 model = BasicModel4_MultiArgs()

Callers

nothing calls this directly

Calls 3

compute_gradientsFunction · 0.90
assertTensorAlmostEqualFunction · 0.90

Tested by

no test coverage detected