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

Function test_elemwise_relu

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

Source from the content-addressed store, hash-verified

266
267
268def test_elemwise_relu():
269 x_np = [1.0, -1.0]
270 dz_np = [1.0]
271 x = mge.Tensor(x_np)
272 dz = mge.Tensor(dz_np)
273
274 refs = {}
275
276 def f(x):
277 x = x * 2
278 refs["x"] = TensorWeakRef(x)
279 return relu(x)
280
281 with Grad() as grad:
282 grad.wrt(x, callback=save_to(x))
283 z = f(x)
284 assert refs["x"]() is None
285 grad(z, dz)
286
287 np.testing.assert_almost_equal(x.grad.numpy(), [2.0, 0])
288
289
290def test_elemwise_relu_backward_fn():

Callers

nothing calls this directly

Calls 7

GradClass · 0.90
save_toFunction · 0.85
gradFunction · 0.85
wrtMethod · 0.80
fFunction · 0.70
TensorMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected