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

Function _attach_pyfuncs_to_irmodule

python/tvm/script/parser/core/entry.py:180–210  ·  view source on GitHub ↗

Attach Python functions to IRModule with reduced nesting.

(irmodule, all_pyfuncs)

Source from the content-addressed store, hash-verified

178
179
180def _attach_pyfuncs_to_irmodule(irmodule, all_pyfuncs):
181 """Attach Python functions to IRModule with reduced nesting."""
182 if not all_pyfuncs:
183 return
184
185 if not hasattr(irmodule, "pyfuncs"):
186 irmodule.pyfuncs = {}
187
188 for global_var, func in irmodule.functions_items():
189 if not isinstance(func, tvm.relax.ExternFunc):
190 continue
191 if not func.attrs.get("is_pyfunc", False):
192 continue
193
194 pyfunc_name = global_var.name_hint
195 if pyfunc_name not in all_pyfuncs:
196 continue
197
198 pyfunc = all_pyfuncs[pyfunc_name]
199 irmodule.pyfuncs[pyfunc_name] = pyfunc
200
201 try:
202 source_code = inspect.getsource(pyfunc)
203 func = func.with_attr("python_source", source_code)
204 except (OSError, TypeError):
205 func = func.with_attr("python_source", f"# Source unavailable for {pyfunc_name}")
206
207 packed_func = _create_python_packed_func(pyfunc)
208 func = func.with_attr("python_packed_func", packed_func)
209
210 irmodule[global_var] = func

Callers 1

parseFunction · 0.85

Calls 4

functions_itemsMethod · 0.80
getMethod · 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…