MCPcopy Create free account
hub / github.com/apache/tvm / test_simple_replace_all_uses

Function test_simple_replace_all_uses

tests/python/relax/test_binding_rewrite.py:257–298  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

255
256
257def test_simple_replace_all_uses():
258 @tvm.script.ir_module
259 class Lv0To1:
260 @R.function
261 def main(x: R.Tensor((32, 32), "float32")) -> R.Tensor((32, 32), "float32"):
262 # lv0 => lv1
263 # / \
264 # lv2 lv3
265 # \ /
266 # lv4
267 with R.dataflow():
268 lv0: R.Tensor((32, 32), "float32") = R.call_dps_packed(
269 "my_relu", (x,), R.Tensor((32, 32), dtype="float32")
270 )
271 lv1: R.Tensor((32, 32), "float32") = R.call_dps_packed(
272 "my_sigmoid", (x,), R.Tensor((32, 32), dtype="float32")
273 )
274 lv2: R.Tensor((32, 32), "float32") = R.call_dps_packed(
275 "my_add", (x, lv0), R.Tensor((32, 32), dtype="float32")
276 )
277 lv3: R.Tensor((32, 32), "float32") = R.call_dps_packed(
278 "my_mul", (x, lv0), R.Tensor((32, 32), dtype="float32")
279 )
280 lv4: R.Tensor((32, 32), "float32") = R.call_dps_packed(
281 "my_whatever", (lv2, lv3), R.Tensor((32, 32), dtype="float32")
282 )
283 R.output(lv4)
284 return lv4
285
286 root_fn = Lv0To1["main"]
287 dfb = root_fn.body.blocks[0]
288
289 n2binding = name_to_binding(root_fn)
290
291 rwt = DataflowBlockRewrite(dfb, root_fn)
292 rwt.replace_all_uses(n2binding["lv0"][0].var, n2binding["lv1"][0].var)
293 rwt.remove_unused(n2binding["lv0"][0].var)
294
295 assert_immutability(rwt, dfb, root_fn)
296
297 n2binding_after = name_to_binding(rwt.mutated_root_fn())
298 assert "lv0" not in n2binding_after
299
300
301def test_simple_module_update():

Callers

nothing calls this directly

Calls 6

replace_all_usesMethod · 0.95
remove_unusedMethod · 0.95
mutated_root_fnMethod · 0.95
name_to_bindingFunction · 0.90
assert_immutabilityFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…