()
| 217 | |
| 218 | |
| 219 | def 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 | |
| 251 | def test_add_input(): |
nothing calls this directly
no test coverage detected