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

Function test_replace_vars

imperative/python/test/unit/utils/test_cgtools.py:22–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20
21
22def test_replace_vars():
23 g = mgb_graph.Graph()
24 g.options.async_exec_level = 0b100
25 device = "xpux"
26 dtype = np.float32
27 a = mgb_graph.InputNode(device=device, dtype=dtype, graph=g)
28 const = g.make_const(1.234, device=device)
29 add_op = Elemwise(Elemwise.Mode.ADD)
30 mul_op = Elemwise(Elemwise.Mode.MUL)
31 a_plus_a = apply_normal_varnode(add_op, a.outputs[0], a.outputs[0])[0]
32 a_plus_a_mul_const = apply_normal_varnode(mul_op, a_plus_a, const)[0]
33 rst = apply_normal_varnode(add_op, a_plus_a_mul_const, a.outputs[0])[0]
34 (new,) = cgtools.replace_vars([rst._node], {const._node: a_plus_a._node})
35 out = mgb_graph.OutputNode(mgb_graph.VarNode(new))
36 func = g.compile(out.outputs[0])
37 func.execute()
38 x = make_dev_tensor(5.0, device=device)
39 a.set_value(x)
40 res = out.get_value().numpy()
41 np.testing.assert_equal(res, np.array([105.0]))
42
43
44def test_replace_oprs():

Callers

nothing calls this directly

Calls 13

make_constMethod · 0.95
compileMethod · 0.95
set_valueMethod · 0.95
get_valueMethod · 0.95
apply_normal_varnodeFunction · 0.90
make_dev_tensorFunction · 0.85
VarNodeMethod · 0.80
assert_equalMethod · 0.80
arrayMethod · 0.80
ElemwiseClass · 0.50
replace_varsMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected