MCPcopy Index your code
hub / github.com/apache/tvm / gen_mod

Function gen_mod

tests/python/relax/test_transform_fold_constant.py:29–57  ·  view source on GitHub ↗

Select relax function with name, rename to main and bind constant. Parameters ---------- mod: IRModule The input module name: str The name of relax function to preserve and rename to main binding: Dict[str, array] The const parameter bindings

(mod, name, binding)

Source from the content-addressed store, hash-verified

27
28
29def gen_mod(mod, name, binding):
30 """Select relax function with name, rename to main and bind constant.
31
32 Parameters
33 ----------
34 mod: IRModule
35 The input module
36
37 name: str
38 The name of relax function to preserve and rename to main
39
40 binding: Dict[str, array]
41 The const parameter bindings
42 """
43 funcs = {}
44 binding = {k: tvm.runtime.tensor(v) for k, v in binding.items()}
45
46 for k, v in mod.functions.items():
47 if isinstance(v, tvm.relax.Function):
48 if k.name_hint == name:
49 # rename to main
50 gv = tvm.ir.GlobalVar("main")
51 funcs[gv] = tvm.relax.Function(v.params, v.body, v.ret_struct_info).with_attr(
52 "global_symbol", "main"
53 )
54 else:
55 funcs[k] = v
56 mod = tvm.IRModule(funcs)
57 return relax.transform.BindParams("main", binding)(mod)
58
59
60def test_one_fold_addone():

Calls 3

FunctionMethod · 0.80
itemsMethod · 0.45
with_attrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…