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

Function call_py_func

python/tvm/relax/script/builder/ir.py:464–512  ·  view source on GitHub ↗

Create a relax Call, which calls a Python function. Parameters ---------- py_func_name: str The name of the Python function to call. This should correspond to a function in the IRModule's pyfuncs attribute. *args : Expr The arguments. out_sinfo: Union[Str

(
    py_func_name: py_str,
    *args: Expr,
    out_sinfo: StructInfo | list[StructInfo],
)

Source from the content-addressed store, hash-verified

462
463
464def call_py_func(
465 py_func_name: py_str,
466 *args: Expr,
467 out_sinfo: StructInfo | list[StructInfo],
468) -> Call:
469 """Create a relax Call, which calls a Python function.
470
471 Parameters
472 ----------
473 py_func_name: str
474 The name of the Python function to call. This should correspond to a function
475 in the IRModule's pyfuncs attribute.
476 *args : Expr
477 The arguments.
478 out_sinfo: Union[StructInfo, List[StructInfo]]
479 The structure info of the call_py_func output.
480 It should be a single or a list of TensorStructInfo. Each one denotes the
481 structure info of a returned tensor.
482
483 Returns
484 -------
485 call: Call
486 The created Relax Call for call_py_func operator.
487 """
488 args = py_tuple(convert_to_expr(a) for a in args)
489 if isinstance(out_sinfo, py_tuple): # type: ignore
490 out_sinfo = list(out_sinfo)
491 elif not isinstance(out_sinfo, list):
492 out_sinfo = [out_sinfo]
493
494 out_sinfo = [
495 (
496 sinfo()
497 if callable(sinfo)
498 else sinfo.asobject()
499 if isinstance(sinfo, ObjectConvertible)
500 else sinfo
501 )
502 for sinfo in out_sinfo
503 ]
504
505 # Convert string to StringImm
506 try:
507 func_name_imm = (
508 StringImm(py_func_name) if isinstance(py_func_name, py_str) else py_func_name
509 )
510 except (TypeError, ValueError, AttributeError):
511 func_name_imm = StringImm(py_func_name)
512 return _call_py_func(func_name_imm, args, out_sinfo)
513
514
515def _sinfo_arg_wrapper(func):

Callers

nothing calls this directly

Calls 3

convert_to_exprFunction · 0.90
StringImmClass · 0.90
asobjectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…