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

Function tester

imperative/python/test/unit/xla/functional/test_xla_vision.py:18–38  ·  view source on GitHub ↗
(ishape, osize, fmt, mode, dtype=None)

Source from the content-addressed store, hash-verified

16@pytest.mark.skipif(not is_cuda_available(), reason="only support cuda now")
17def test_resize():
18 def tester(ishape, osize, fmt, mode, dtype=None):
19 dtype = dtype or np.float32
20 inp = tensor(np.random.randn(*ishape), dtype=dtype)
21 oshape = F.vision.resize(inp, osize, fmt, mode).shape
22 dout = tensor(np.random.randn(*oshape), dtype=dtype)
23 mge._full_sync()
24 gm = GradManager()
25
26 @jit.xla_trace(without_host=True, capture_as_const=True)
27 def func(inp, dout, mode):
28 gm.attach([inp])
29 with gm:
30 out = F.vision.resize(inp, osize, fmt, mode)
31 gm.backward(out, dout)
32 return out, inp.grad
33
34 mge_rsts = func(inp, dout, mode)
35 xla_rsts = func(inp, dout, mode)
36
37 for mge_rst, xla_rst in zip(mge_rsts, xla_rsts):
38 np.testing.assert_allclose(mge_rst.numpy(), xla_rst.numpy(), atol=1e-5)
39
40 for mode in ["linear", "nearest"]:
41 tester((4, 3, 1, 1), (1, 1), "NCHW", mode)

Callers 1

test_resizeFunction · 0.70

Calls 4

GradManagerClass · 0.90
resizeMethod · 0.80
funcFunction · 0.70
numpyMethod · 0.45

Tested by

no test coverage detected