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

Function test_modify_params

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

Source from the content-addressed store, hash-verified

188
189
190def test_modify_params():
191
192 a = Tensor([1, 2])
193 b = Tensor([3, 4])
194
195 @trace(symbolic=True, capture_as_const=True)
196 def fwd(a, b):
197 return (a + b) * 2
198
199 fwd(a, b)
200 orig_model = io.BytesIO()
201 fwd.dump(
202 orig_model, arg_names=["a", "b"], output_names="o", optimize_for_inference=False
203 )
204 orig_model.seek(0)
205
206 graph = Net.load(orig_model)
207 param_const = graph.params_filter.as_unique()
208 param_const.set_value(3)
209
210 modified_model = io.BytesIO()
211 graph.dump(modified_model)
212 modified_model.seek(0)
213 load_graph = GraphInference(modified_model)
214
215 out = load_graph.run(a, b)
216 np.testing.assert_equal(out["o"], [12, 18])
217
218
219def test_make_const():

Callers

nothing calls this directly

Calls 10

runMethod · 0.95
TensorClass · 0.90
GraphInferenceClass · 0.90
assert_equalMethod · 0.80
fwdFunction · 0.70
dumpMethod · 0.45
seekMethod · 0.45
loadMethod · 0.45
as_uniqueMethod · 0.45
set_valueMethod · 0.45

Tested by

no test coverage detected