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

Method save_function

python/tvm/runtime/vm.py:144–190  ·  view source on GitHub ↗

Convenience function. Takes a function from the module and saves a `Function` that, when called, will invoke the function with the given arguments. The `Function` can be accessed from the module using `saved_name`. This is included to facilitate timing trials:

(
        self,
        func_name: str,
        saved_name: str,
        *args: list[Any],
        include_return: bool = True,
        **kwargs: dict[str, Any],
    )

Source from the content-addressed store, hash-verified

142 return self._invoke_closure(closure, *args)
143
144 def save_function(
145 self,
146 func_name: str,
147 saved_name: str,
148 *args: list[Any],
149 include_return: bool = True,
150 **kwargs: dict[str, Any],
151 ) -> None:
152 """
153 Convenience function. Takes a function from the module and saves
154 a `Function` that, when called, will invoke the function with the given arguments.
155 The `Function` can be accessed from the module using `saved_name`.
156 This is included to facilitate timing trials:
157 Invoking the returned `Function` will have less overhead from dictionary lookups
158 than normally running through the VM.
159
160 If the saved name is taken, it can be overridden, though it cannot override
161 the name of a function defined in the Relax source.
162
163 This is really creating a closure, but the function has a different name
164 to avoid confusion with `invoke_closure` (they are not meant to be used together).
165
166 Parameters
167 ----------
168 func_name : str
169 The function that should be packaged up.
170
171 saved_name : str
172 The name that the resulting closure should be saved under.
173
174 include_return : bool
175 Whether the saved Function should return its output.
176 If timing over RPC, it may not be desirable to send output
177 between machines.
178
179 args : List[Any]
180 The arguments to package up with the function.
181
182 kwargs : Dict[str, Any]
183 Any named arguments to package up with the function
184 """
185 cargs: list[Any] = []
186 if kwargs:
187 args = self._convert_func_named_args(func_name, args, **kwargs)
188 for arg in args:
189 self._convert(arg, cargs)
190 self._save_function(func_name, saved_name, int(include_return), *cargs)
191
192 def _convert(self, arg: Any, cargs: list) -> None:
193 """helper function to convert arguments to vm function."""

Callers 4

test_time_evaluatorFunction · 0.95
check_saved_funcFunction · 0.80

Calls 2

_convertMethod · 0.95

Tested by 3

test_time_evaluatorFunction · 0.76