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

Class HybridVMModule

docs/how_to/tutorials/mix_python_and_tvm_with_pymodule.py:351–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

349
350 @I.ir_module
351 class HybridVMModule(BasePyModule):
352 @I.pyfunc
353 def silu(self, x):
354 """SiLU/Swish activation — using Python as fallback."""
355 return torch.sigmoid(x) * x
356
357 @I.pyfunc
358 def layer_norm(self, x):
359 """LayerNorm — another Python fallback."""
360 return F.layer_norm(x, x.shape[-1:])
361
362 @R.function
363 def main(
364 x: R.Tensor((4, 8), "float32"),
365 ) -> R.Tensor((4, 8), "float32"):
366 # The VM calls back into Python for these two ops
367 h = R.call_py_func("layer_norm", (x,), out_sinfo=R.Tensor((4, 8), "float32"))
368 out = R.call_py_func("silu", (h,), out_sinfo=R.Tensor((4, 8), "float32"))
369 return out
370
371 mod = HybridVMModule(device=tvm.cpu(0))
372 x = torch.randn(4, 8)

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…