MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / test_grad_2

Function test_grad_2

imperative/python/test/unit/core/test_autodiff.py:89–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

87
88
89def test_grad_2():
90 x_np = np.random.rand(10).astype("float32")
91 x = as_tensor(x_np)
92
93 with Grad() as grad:
94 grad.wrt(x, callback=save_to(x))
95 y = mul(x, x)
96 y = mul(y, y)
97 grad(y, as_tensor(np.ones_like(x_np)))
98
99 np.testing.assert_almost_equal(x.grad.numpy(), 4 * x_np ** 3, decimal=6)
100
101
102@pytest.mark.require_higher_order_directive()

Callers

nothing calls this directly

Calls 8

GradClass · 0.90
save_toFunction · 0.85
gradFunction · 0.85
wrtMethod · 0.80
as_tensorFunction · 0.70
mulFunction · 0.70
astypeMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected