xxmd1132 opened a new issue, #16285:
URL: https://github.com/apache/tvm/issues/16285

   
   
   ### Expected behavior
   
   can run target_model which had compplile throught python API function: 
tvmc.run(target_model, device="cpu")
   
   ### Actual behavior
   
   run fail when run line: `result = tvmc.run(target_model, device="cpu") # 第 3 
步:运行` of python script 'python resnet_test.py'
   here is error message:
   
   ```bash
   get tvm delay model
   One or more operators have not been tuned. Please tune your model for better 
performance. Use DEBUG logging level to see more details.
   get tvm target model, lib name:mod.so
   Traceback (most recent call last):
     File "tests/zxq/resnet_test.py", line 60, in <module>
       local_compile(onnx_path)
     File "tests/zxq/resnet_test.py", line 55, in local_compile
       result = tvmc.run(target_model, device="cpu") # 第 3 步:运行
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/driver/tvmc/runner.py", line 
589, in run_module
       lib = session.load_module(tvmc_package.lib_name)
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/rpc/client.py", line 178, in 
load_module
       return _ffi_api.LoadRemoteModule(self._sess, path)
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/_ffi/_ctypes/packed_func.py", 
line 239, in __call__
       raise_last_ffi_error()
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/_ffi/base.py", line 481, in 
raise_last_ffi_error
       raise py_err
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/rpc/server.py", line 80, in 
load_module
       m = _load_module(path)
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/runtime/module.py", line 693, 
in load_module
       return _ffi_api.ModuleLoadFromFile(path, fmt)
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/_ffi/_ctypes/packed_func.py", 
line 239, in __call__
       raise_last_ffi_error()
     File "/Users/zxq/EzvizEngine/tvm/python/tvm/_ffi/base.py", line 481, in 
raise_last_ffi_error
       raise py_err
   tvm.error.InternalError: Traceback (most recent call last):
     [bt] (8) 9   libffi.8.dylib                      0x000000010512004c 
ffi_call_SYSV + 76
     [bt] (7) 8   libtvm.dylib                        0x0000000179b0580c 
TVMFuncCall + 64
     [bt] (6) 7   libtvm.dylib                        0x0000000179b2c720 void 
tvm::runtime::TypedPackedFunc<tvm::runtime::Module (tvm::runtime::String 
const&, tvm::runtime::String const&)>::AssignTypedLambda<tvm::runtime::Module 
(*)(tvm::runtime::String const&, tvm::runtime::String 
const&)>(tvm::runtime::Module (*)(tvm::runtime::String const&, 
tvm::runtime::String const&), std::__1::basic_string<char, 
std::__1::char_traits<char>, 
std::__1::allocator<char>>)::'lambda'(tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*)::operator()(tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*) const + 148
     [bt] (5) 6   libtvm.dylib                        0x0000000179b27e48 
tvm::runtime::Module::LoadFromFile(tvm::runtime::String const&, 
tvm::runtime::String const&) + 952
     [bt] (4) 5   libtvm.dylib                        0x0000000179b16748 
tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::$_0>>::Call(tvm::runtime::PackedFuncObj
 const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) + 148
     [bt] (3) 4   libtvm.dylib                        0x0000000179b16568 
tvm::runtime::DSOLibrary::Load(std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char>> const&) + 216
     [bt] (2) 3   libtvm.dylib                        0x00000001780033f4 
__clang_call_terminate + 0
     [bt] (1) 2   libtvm.dylib                        0x0000000178006280 
tvm::runtime::detail::LogFatal::Entry::Finalize() + 0
     [bt] (0) 1   libtvm.dylib                        0x00000001780062c4 
tvm::runtime::detail::LogFatal::Entry::Finalize() + 68
     File "/Users/zxq/EzvizEngine/tvm/src/runtime/dso_library.cc", line 125
   InternalError: Check failed: (lib_handle_ != nullptr) is false: Failed to 
load dynamic shared library 
/private/var/folders/jf/nl4dq34n14xcm_xbslm9qyyr0000gq/T/tmpqs9vsxka/mod.so 
dlopen(/private/var/folders/jf/nl4dq34n14xcm_xbslm9qyyr0000gq/T/tmpqs9vsxka/mod.so,
 0x0005): tried: 
'/private/var/folders/jf/nl4dq34n14xcm_xbslm9qyyr0000gq/T/tmpqs9vsxka/mod.so' 
(mach-o file, but is an incompatible architecture (have 'x86_64', need 
'arm64')), 
'/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/jf/nl4dq34n14xcm_xbslm9qyyr0000gq/T/tmpqs9vsxka/mod.so'
 (no such file), 
'/private/var/folders/jf/nl4dq34n14xcm_xbslm9qyyr0000gq/T/tmpqs9vsxka/mod.so' 
(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
   ```
   
   ### Environment
   
   Hardware:
   
       Hardware Overview:
   
         Model Name: Mac
         Model Identifier: Mac14,14
         Model Number: Z180000JDCH/A
         Chip: Unknown
         Total Number of Cores: 24 (16 performance and 8 efficiency)
         Memory: 192 GB
         System Firmware Version: 8422.121.3
         OS Loader Version: 8422.121.3
         Serial Number (system): JXP6CFK63K
         Hardware UUID: 3DEB4A8F-FA91-5263-948A-8C73653657CF
         Provisioning UDID: 3DEB4A8F-FA91-5263-948A-8C73653657CF
         Activation Lock Status: Disabled
   
   llvm-g++ version:
   Apple clang version 14.0.3 (clang-1403.0.22.14.1)
   Target: x86_64-apple-darwin22.5.0
   Thread model: posix
   InstalledDir: /Library/Developer/CommandLineTools/usr/bin
   
   python version(conda virtual env):3.9.16
   
   ### Steps to reproduce
   
   
   1. build 'libtvm.dylib', here is the command which of [refer 
link](https://tvm.hyper.ai/docs/install/from_source) :
   Here are some modification Settings for cmakelist.txt
   
   ```bash
   set(USE_LLVM ON)
   set(USE_LIBBACKTRACE OFF) # Use libbacktrace to supply linenumbers on stack 
traces
   ```
   then get `libtvm_runtime.dylib` and `libtvm.dylib`
   
   2. export PYTHONPATH=$tvm_root/python
   3. run python script:`python resnet_test.py`
   here is python script(resnet_test.py) which refer by example of repo and 
test model is a resnet-50 which download by python example of repo
   
   ```python
   from tvm.contrib.download import download_testdata
   from tvm.driver import tvmc
   from PIL import Image
   import logging
   from pathlib import Path
   import numpy as np
   def local_compile(onnx:Path):
       target_model_p = onnx.with_name(onnx.stem + "_target.tvm")
       relay_model_p = onnx.with_name(onnx.stem + "_relay.tvm")
       tvm_model = tvmc.load(onnx) # onnx -> TVM Relay,可以使用 model.summary()打印
       print(f"get tvm delay model")
       
       ## modify input [optional]
       tvm_model = tvmc.load(onnx, shape_dict={'input1' : [1, 2, 3, 4], 
'input2' : [1, 2, 3, 4]}) # if input model is pt, this step is required!
       
       ## Relay -> Target
       target_model = tvmc.compile(tvm_model, target="llvm", 
package_path=target_model_p) # 第 2 步:编译
       print(f"get tvm target model, lib name:{target_model.lib_name}")
       
       # run test
       result = tvmc.run(target_model, device="cpu") # 第 3 步:运行
       print("run target model success")
   
   onnx_path = Path(r"/Users/zxq/EzvizEngine/tvm/tests/zxq/resnet50-v2-7.onnx")
   local_compile(onnx_path)
   ```
   
   ### Triage
   * backend: llvm


-- 
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]

Reply via email to