| 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) |
no outgoing calls
no test coverage detected
searching dependent graphs…