MCPcopy
hub / github.com/apache/tvm / local_run

Function local_run

python/tvm/testing/runner.py:80–149  ·  view source on GitHub ↗

Run a TVM module on a local device. Parameters ---------- mod : Module The TVM module to run. device_type : str The device type to run the module on. args : List[Union[np.ndarray, Tensor, int, float]] The arguments to be fed to the module. evaluator_c

(  # pylint: disable=too-many-arguments,too-many-locals
    mod: "Module",
    device_type: str,
    args: list[Union["np.ndarray", "Tensor", int, float]],
    evaluator_config: Optional["EvaluatorConfig"] = None,
    export_func: Callable[["Module", str], None] | Literal["tar", "ndk"] = "tar",
    output_format: str | None = None,
)

Source from the content-addressed store, hash-verified

78
79
80def local_run( # pylint: disable=too-many-arguments,too-many-locals
81 mod: "Module",
82 device_type: str,
83 args: list[Union["np.ndarray", "Tensor", int, float]],
84 evaluator_config: Optional["EvaluatorConfig"] = None,
85 export_func: Callable[["Module", str], None] | Literal["tar", "ndk"] = "tar",
86 output_format: str | None = None,
87):
88 """Run a TVM module on a local device.
89
90 Parameters
91 ----------
92 mod : Module
93 The TVM module to run.
94 device_type : str
95 The device type to run the module on.
96 args : List[Union[np.ndarray, Tensor, int, float]]
97 The arguments to be fed to the module.
98 evaluator_config : Optional[EvaluatorConfig]
99 The evaluator configuration to use.
100 export_func : Union[Callable[Module, str], Literal["tar", "ndk"]]
101 The function to export the module to a file.
102 If callable, it must be a function that takes two arguments: the module to export and the
103 path to export to.
104 If "tar", the module will be exported to a tar file.
105 If "ndk", the module will be exported to a shared library.
106 output_format : Optional[str]
107 The format of the exported module.
108 If not specified, it will be inferred from the `export_func` argument.
109
110 Returns
111 -------
112 args : List[Union[np.ndarray, Tensor, int, float]]
113 The results of running the module.
114 profile_result : tvm.runtime.BenchmarkResult
115 The profiling result of running the module.
116 """
117 import os.path as osp
118 import tempfile
119
120 from tvm.runtime import device, load_module
121 from tvm.s_tir.meta_schedule.runner import EvaluatorConfig
122
123 evaluator_config = EvaluatorConfig._normalized(evaluator_config)
124 export_func, output_format = _normalize_export_func(export_func, output_format)
125
126 with tempfile.TemporaryDirectory() as tmp_dir:
127 artifact_path = osp.join(tmp_dir, "tvm_tmp_mod." + output_format)
128 export_func(mod, artifact_path)
129 device: Device = device(device_type, 0)
130
131 try:
132 args = _args_to_device(args, device)
133 remote_mod = load_module(artifact_path)
134 profile_result = remote_mod.time_evaluator(
135 func_name=remote_mod.entry_name,
136 dev=device,
137 number=evaluator_config.number,

Callers 1

mainFunction · 0.90

Calls 7

load_moduleFunction · 0.90
_normalize_export_funcFunction · 0.85
_args_to_deviceFunction · 0.85
_args_to_numpyFunction · 0.85
_normalizedMethod · 0.45
joinMethod · 0.45
time_evaluatorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…