You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by GitBox <gi...@apache.org> on 2026/04/24 20:13:03 UTC

[GH] (tvm-ffi/benchmark-pycall): Workflow run "CI" is working again!

The GitHub Actions job "CI" on tvm-ffi.git/benchmark-pycall has succeeded.
Run started by GitHub user tqchen (triggered by tqchen).

Head commit for run:
b8c34a816d6574afabed555e2f2936ea00c495b4 / tqchen <ti...@gmail.com>
[REFACTOR] Optimized Python callback path via TVMFFIPyCallbackArgSetter

This PR optimizes python callback specifically when the arguments expect
a torch.Tensor class.

`tvm_ffi.convert_func(pyfunc, tensor_cls=None)` is provided. If `tensor_cls`
is provided, the closure threads its `__dlpack_c_exchange_api__` capsule
into the callback so tensor args are delivered as `tensor_cls` instances
(e.g., `torch.Tensor`) directly from the C-level setter — no per-arg
Python-level conversion.

Example:

```python
import torch
import tvm_ffi

def callback(a: torch.Tensor, b: torch.Tensor, c: torch.Tensor) -> None:
    # a, b, c arrive as torch.Tensor, converted in C via the closure's
    # DLPack exchange API — no from_dlpack() needed inside the callback.
    torch.add(a, b, out=c)

f = tvm_ffi.convert_func(callback, tensor_cls=torch.Tensor)
```

| Variant                               | Per-call |
|---------------------------------------|----------|
| pycallback[tensor_cls=torch.Tensor]   | ~640 ns  |
| pycallback+from_dlpack (explicit x3)  | ~9.1 us  |

The closure-threaded path is ~14x faster than doing per-arg DLPack
conversion in the Python callback body.

Report URL: https://github.com/apache/tvm-ffi/actions/runs/24909225587

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org