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

Function test_make_const

imperative/python/test/unit/utils/test_network.py:219–248  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

217
218
219def test_make_const():
220
221 a = Tensor([1, 2])
222 b = Tensor([3, 4])
223
224 @trace(symbolic=True, capture_as_const=True)
225 def fwd(a, b):
226 return (a + b) * 2
227
228 fwd(a, b)
229 orig_model = io.BytesIO()
230 fwd.dump(
231 orig_model, arg_names=["a", "b"], output_names="o", optimize_for_inference=False
232 )
233 orig_model.seek(0)
234
235 graph = Net.load(orig_model)
236 const_b = graph.make_const(np.array([0.0, 0.0]), name="b")
237 varb = graph.var_filter.name("b").as_unique()
238
239 repl_dict = {varb: const_b}
240 graph.replace_vars(repl_dict)
241
242 modified_model = io.BytesIO()
243 graph.dump(modified_model)
244 modified_model.seek(0)
245 load_graph = GraphInference(modified_model)
246
247 out = load_graph.run(a)
248 np.testing.assert_equal(out["o"], [2, 4])
249
250
251def test_add_input():

Callers

nothing calls this directly

Calls 13

runMethod · 0.95
TensorClass · 0.90
GraphInferenceClass · 0.90
arrayMethod · 0.80
assert_equalMethod · 0.80
fwdFunction · 0.70
dumpMethod · 0.45
seekMethod · 0.45
loadMethod · 0.45
make_constMethod · 0.45
as_uniqueMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected