Skip to content

Missing operator: [0] aten::add.out #5009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sophda opened this issue Aug 30, 2024 · 3 comments
Closed

Missing operator: [0] aten::add.out #5009

sophda opened this issue Aug 30, 2024 · 3 comments

Comments

@sophda
Copy link

sophda commented Aug 30, 2024

🐛 Describe the bug

Hi, I tried to build an Android app using executorch, I firstly cross compile executorch with xnnpack on:

cmake -DCMAKE_TOOLCHAIN_FILE="/home/user/src/android-ndk-r25c/build/cmake/android.toolchain.cmake"\
	-DCMAKE_INSTALL_PREFIX=/home/user/torch/executorch/arm64xnninstall \
	-DANDROID_ABI="arm64-v8a" \
	-DEXECUTORCH_BUILD_XNNPACK=ON \
	-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
	-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
	..
cmake --build ./ -j12 --target install

Then I use a cpp file:

#include <iostream>
#include <executorch/extension/module/module.h>
using namespace torch::executor;
int main()
{

    Module module("./model.pte");
    float input[3*4];
    Tensor::SizesType sizes[]={3,4};
    TensorImpl tensor(ScalarType::Float,12,sizes,input);
    const auto result = module.forward({EValue(Tensor(&tensor))});

}

and the CMakeLists.txt is:

cmake_minimum_required(VERSION 3.4.1)
set(PROJECT_NAME torchtest)
project(${PROJECT_NAME})
set(CMAKE_CXX_STANDARD 17)
include_directories(
/home/user/torch/
/home/user/torch/executorch/arm64install/include/executorch/kernels/portable
)
link_directories(
/home/user/torch/executorch/arm64xnninstall/lib
)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME}
libexecutorch.a
libextension_module.a
libextension_data_loader.a
libexecutorch_no_prim_ops.a
libextension_module_static.a
libportable_kernels.a
libportable_ops_lib.a
libpthreadpool.a
libxnnpack_backend.a
)
target_link_options(${PROJECT_NAME} PRIVATE -fPIC )

Then use the following script to build:

cmake -DCMAKE_TOOLCHAIN_FILE="/home/user/src/android-ndk-r25c/build/cmake/android.toolchain.cmake"\
	-DCMAKE_BUILD_TYPE="Release" \
	-DANDROID_ABI="arm64-v8a" \
	..
make

I use 'adb push' to deploy the output of this project on Android phone, but after running it, I get the error:
image
could you please tell me how to fix it? Thanks!

Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: 10.0.0-4ubuntu1
CMake version: version 3.30.2
Libc version: glibc-2.31

Python version: 3.9.13 (main, Aug 25 2022, 23:26:10) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Ti
Nvidia driver version: 551.61
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 46 bits physical, 48 bits virtual
CPU(s): 20
On-line CPU(s) list: 0-19
Thread(s) per core: 2
Core(s) per socket: 10
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 183
Model name: 13th Gen Intel(R) Core(TM) i5-13600K
Stepping: 1
CPU MHz: 3494.399
BogoMIPS: 6988.79
Virtualization: VT-x
Hypervisor vendor: Microsoft
Virtualization type: full
L1d cache: 480 KiB
L1i cache: 320 KiB
L2 cache: 20 MiB
L3 cache: 24 MiB
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Unknown: No mitigations
Vulnerability Retbleed: Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology tsc_reliable nonstop_tsc cpuid pni pclmulqdq vmx ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves avx_vnni umip waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm serialize flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] executorch==0.3.0a0+7d77d78
[pip3] numpy==2.1.0
[pip3] torch==2.4.0+cpu
[pip3] torchaudio==2.4.0+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.19.0
[conda] executorch 0.3.0a0+7d77d78 pypi_0 pypi
[conda] numpy 2.1.0 pypi_0 pypi
[conda] torch 2.4.0+cpu pypi_0 pypi
[conda] torchaudio 2.4.0+cpu pypi_0 pypi
[conda] torchsr 1.0.4 pypi_0 pypi
[conda] torchvision 0.19.0 pypi_0 pypi

@sophda
Copy link
Author

sophda commented Aug 30, 2024

The 'model.pte' was generated by the python scripts:

import torch
from torch._export import capture_pre_autograd_graph
from torch.export import export, ExportedProgram
import executorch.exir as exir
from executorch.exir import ExecutorchBackendConfig, ExecutorchProgramManager
class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.param = torch.nn.Parameter(torch.rand(3, 4))
        self.linear = torch.nn.Linear(4, 5)

    def forward(self, x):
        return self.linear(x + self.param).clamp(min=0.0, max=1.0)


example_args = (torch.randn(3, 4),)
print(example_args
      )
pre_autograd_aten_dialect = capture_pre_autograd_graph(M(), example_args)
# Optionally do quantization:
# pre_autograd_aten_dialect = convert_pt2e(prepare_pt2e(pre_autograd_aten_dialect, CustomBackendQuantizer))
aten_dialect: ExportedProgram = export(pre_autograd_aten_dialect, example_args)
edge_program: exir.EdgeProgramManager = exir.to_edge(aten_dialect)
# Optionally do delegation:
# edge_program = edge_program.to_backend(CustomBackendPartitioner)
executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
    ExecutorchBackendConfig(
        passes=[],  # User-defined passes
    )
)

with open("model.pte", "wb") as file:
    file.write(executorch_program.buffer)

@sophda sophda closed this as completed Sep 1, 2024
@sternezsl
Copy link

sternezsl commented Oct 11, 2024

The 'model.pte' was generated by the python scripts:

import torch
from torch._export import capture_pre_autograd_graph
from torch.export import export, ExportedProgram
import executorch.exir as exir
from executorch.exir import ExecutorchBackendConfig, ExecutorchProgramManager
class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.param = torch.nn.Parameter(torch.rand(3, 4))
        self.linear = torch.nn.Linear(4, 5)

    def forward(self, x):
        return self.linear(x + self.param).clamp(min=0.0, max=1.0)


example_args = (torch.randn(3, 4),)
print(example_args
      )
pre_autograd_aten_dialect = capture_pre_autograd_graph(M(), example_args)
# Optionally do quantization:
# pre_autograd_aten_dialect = convert_pt2e(prepare_pt2e(pre_autograd_aten_dialect, CustomBackendQuantizer))
aten_dialect: ExportedProgram = export(pre_autograd_aten_dialect, example_args)
edge_program: exir.EdgeProgramManager = exir.to_edge(aten_dialect)
# Optionally do delegation:
# edge_program = edge_program.to_backend(CustomBackendPartitioner)
executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
    ExecutorchBackendConfig(
        passes=[],  # User-defined passes
    )
)

with open("model.pte", "wb") as file:
    file.write(executorch_program.buffer)
target_link_libraries(${PROJECT_NAME}
libexecutorch.a
libextension_module.a
libextension_data_loader.a
libexecutorch_no_prim_ops.a
libextension_module_static.a
libportable_kernels.a
libportable_ops_lib.a
libpthreadpool.a
libxnnpack_backend.a

remove libportable_ops_lib.a here

@vikasbalaga
Copy link

vikasbalaga commented Apr 4, 2025

Hi @sophda , @sternezsl

I am facing a similar issue (please find the query here)
I tried the steps mentioned here of removing libportable_ops_lib.a from linking, yet I am seeing the issue.
So, can you confirm the fix is working?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants