garfield0xff opened a new issue, #18377:
URL: https://github.com/apache/tvm/issues/18377
### Summary
`relax.VirtualMachine` execution returns a `tvm_ffi.container.Array`, which
does not have a `.numpy()` method.
This causes an `AttributeError` when i try to convert the output directly.
[tvm 0.22
guideline](https://tvm.apache.org/docs/how_to/tutorials/e2e_opt_model.html)
### Environment
- OS : Mac M2 ( Sequoia )
- TVM : 0.22.dev0
- Python : 3.11.14
- Pytorch : 2.8.0
### Steps to reproduce
```
import os
import torch
from torch.export import export
from torchvision.models import ResNet18_Weights, resnet18
import numpy as np
import tvm
from tvm import relax
from tvm.relax.frontend.torch import from_exported_program
import tvm.runtime
example_args = (torch.randn(1, 3, 224, 224, dtype=torch.float32),)
IS_IN_CI = os.getenv("CI", "") == "true"
if not IS_IN_CI:
torch_model = resnet18(weights=ResNet18_Weights.DEFAULT).eval()
with torch.no_grad():
exported_program = export(torch_model, example_args)
mod = from_exported_program(exported_program,
keep_params_as_input=True)
mod, params = relax.frontend.detach_params(mod)
exec = tvm.compile(mod, target="llvm")
dev = tvm.cpu()
vm = relax.VirtualMachine(exec, dev)
cpu_data = tvm.runtime.tensor(np.random.rand(1, 3, 224,
224).astype("float32"), dev)
cpu_params = [tvm.runtime.tensor(p, dev) for p in params["main"]]
# fail
cpu_out = vm["main"](cpu_data, *cpu_params).numpy()
# this works
# output = vm["main"](cpu_data, *cpu_params)
# cpu_out = output[0].numpy()
print(f"Output shape: {cpu_out.shape}")
```
### Output
```
Traceback (most recent call last):
File "..../tvm-tutorial/ir/end-to-end2.py", line 34, in <module>
cpu_out = vm["main"](cpu_data, *cpu_params).numpy()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Array' object has no attribute 'numpy'
```
### Note
* bug
* needs-triage
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]