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)
| 27 | |
| 28 | |
| 29 | def 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 | |
| 60 | def test_one_fold_addone(): |
no test coverage detected
searching dependent graphs…