pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
1.44k stars 234 forks source link

Error building coreml_executor_runner #2870

Open orgicus opened 3 months ago

orgicus commented 3 months ago

I'm trying executorch for the first time and I am trying to follow these guide:

I have already built and ran the add.pte example following the getting-start-setup guide.

I'm running into a build error running build-run-coreml guide command: sh examples/apple/coreml/scripts/build_executor_runner.sh it doesn't seem to find the file_data_loader header: fatal error: 'executorch/extension/data_loader/file_data_loader.h' file not found

This is the full error:

CompileC /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/Objects-normal/arm64/main.o /Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/executor_runner/main.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler (in target 'coreml_executor_runner' from project 'coreml_executor_runner')
    cd /Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/executor_runner
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c++ -ivfsstatcache /Users/george.profenza/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx14.2-23C53-df0db8920d7ae99241a1bc0f08d2dced.sdkstatcache -target arm64-apple-macos13.0 -fmessage-length\=245 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit\=0 -fcolor-diagnostics -std\=gnu++20 -fobjc-arc -fobjc-weak -fmodules -gmodules -fmodules-cache-path\=/Users/george.profenza/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -fmodules-prune-interval\=86400 -fmodules-prune-after\=345600 -fbuild-session-file\=/Users/george.profenza/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -fmodules-validate-once-per-build-session -Wnon-modular-include-in-framework-module -Werror\=non-modular-include-in-framework-module -Wno-trigraphs -fpascal-strings -O0 -fno-common -Wno-missing-field-initializers -Wno-missing-prototypes -Werror\=return-type -Wdocumentation -Wunreachable-code -Wquoted-include-in-framework-header -Wno-implicit-atomic-properties -Werror\=deprecated-objc-isa-usage -Wno-objc-interface-ivars -Werror\=objc-root-class -Wno-arc-repeated-use-of-weak -Wimplicit-retain-self -Wno-non-virtual-dtor -Wno-overloaded-virtual -Wno-exit-time-destructors -Wduplicate-method-match -Wno-missing-braces -Wparentheses -Wswitch -Wunused-function -Wno-unused-label -Wno-unused-parameter -Wunused-variable -Wunused-value -Wempty-body -Wuninitialized -Wconditional-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wconstant-conversion -Wint-conversion -Wbool-conversion -Wenum-conversion -Wno-float-conversion -Wnon-literal-null-conversion -Wobjc-literal-conversion -Wshorten-64-to-32 -Wno-newline-eof -Wno-selector -Wno-strict-selector-match -Wundeclared-selector -Wdeprecated-implementations -Wno-c++11-extensions -Wno-implicit-fallthrough -DDEBUG\=1 -DOBJC_OLD_DISPATCH_PROTOTYPES\=0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -fstrict-aliasing -Wprotocol -Wdeprecated-declarations -Winvalid-offsetof -g -fvisibility-inlines-hidden -Wno-sign-conversion -Winfinite-recursion -Wmove -Wcomma -Wblock-capture-autoreleasing -Wstrict-prototypes -Wrange-loop-analysis -Wno-semicolon-before-method-body -Wunguarded-availability -index-store-path /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Index.noindex/DataStore -iquote /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/coreml_executor_runner-generated-files.hmap -I/Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/coreml_executor_runner-own-target-headers.hmap -I/Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/coreml_executor_runner-all-target-headers.hmap -iquote /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/coreml_executor_runner-project-headers.hmap -I/Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/xcode-build/Debug/include -I/Users/george.profenza/Documents -I/Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/executor_runner/include -I/Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/DerivedSources-normal/arm64 -I/Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/DerivedSources/arm64 -I/Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/DerivedSources -F/Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/xcode-build/Debug -MMD -MT dependencies -MF /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/Objects-normal/arm64/main.d --serialize-diagnostics /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/Objects-normal/arm64/main.dia -c /Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/executor_runner/main.mm -o /Users/george.profenza/Library/Developer/Xcode/DerivedData/coreml_executor_runner-enyxizomiqritefhvqsttuxadxho/Build/Intermediates.noindex/coreml_executor_runner.build/Debug/coreml_executor_runner.build/Objects-normal/arm64/main.o -index-unit-output-path /coreml_executor_runner.build/Debug/coreml_executor_runner.build/Objects-normal/arm64/main.o
/Users/george.profenza/Documents/cv/executorch/examples/apple/coreml/executor_runner/main.mm:15:9: fatal error: 'executorch/extension/data_loader/file_data_loader.h' file not found
#import <executorch/extension/data_loader/file_data_loader.h>
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

** BUILD FAILED **

I can see the file does exist (./extension/data_loader/file_data_loader.h). Perhaps this library wasn't build in a previous step ? What's the recommendation for clean build ?

I am using OSX 14.1 with the recommended executorch setup (conda with Python 3.10.0, etc.)

Slightly off-topic, since I'm new to deploying PyTorch models on iOS, may I ask: what is the recommendation currently to reliable convert and run computer vision models (classifier/object detector/segmentation ViT models) ?

Context:

  1. The PyTorch > ONNX > CoreML workflow is deprecated / no longer recommended
  2. PyTorch > PyTorch Script > CoreML seems to be recommended path currently thought it can be quite fiddly to get right (sometimes with CoreML models that produce good results in Python, but not in XCode (preview) nor on device) 2.1. https://github.com/facebookresearch/playtorch (which seems nice for prototyping ML apps) is archived since October 2023. 2.2 https://github.com/pytorch/ios-demo-app is archived since November 2023 2.3. LibTorch-Lite optimize_for_mobile and _save_for_lite_interpreter are in beta

    1. Executorch looks great, but is fairly new, not in beta yet

    Thank you so much, George

cymbalrush commented 2 months ago

@orgicus thus could be a path issue, could you please check the name of the cloned directory, if the name is not executorch then please rename it to executorch.

orgicus commented 2 months ago

@cymbalrush Thanks for the the input.

The folder is indeed called executorch. Doesn't look like I need to rename it:

pwd
/Users/george.profenza/Documents/cv/executorch
(executorch) george.profenza@Georges-MacBook-Pro executorch % file extension/data_loader/file_data_loader.h
extension/data_loader/file_data_loader.h: C++ source text, ASCII text

Are there other paths to double check ? (e.g. the from which the compilation process runs relative to the extension/runtime/util folders )

Thank you, George

orgicus commented 2 months ago

I'm checking in if there are updates on how could check/fix paths to get build_executor_runner.sh to build successfully

mergennachin commented 1 month ago

@orgicus

We just released a new stable release.

Can you try with the latest instructions?

Namely, git clone --branch v0.2.0 https://github.com/pytorch/executorch.git

orgicus commented 1 month ago

@mergennachin Thank you for the update.

I cloned the repo as a sibling to the previous clone (git clone --branch v0.2.0 https://github.com/pytorch/executorch.git executorch_v0.2.0)

I then activated the existing executorch conda environment and attempted to run the ./install_requirements.sh script. Unfortunately I ran into a pybind build error with inmemoryfs:

Processing /Users/george.profenza/Documents/cv/executorch_v0.2.0/backends/apple/coreml/runtime/inmemoryfs
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/Users/george.profenza/Documents/cv/executorch_v0.2.0/backends/apple/coreml/runtime/inmemoryfs/setup.py", line 10, in <module>
          from pybind11.setup_helpers import build_ext, Pybind11Extension
      ModuleNotFoundError: No module named 'pybind11'
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
ExecuTorch: Failed to install inmemoryfs extension.
ExecuTorch: Copying protobuf files.

I now notice it's trying to to install https://download.pytorch.org/whl/test/cpu/torch-2.3.0-cp310-none-macosx_11_0_arm64.whl when I have torch 2.2.0.dev20231010 (with MPS support).

Unfortunately I won't have the resources to read source code/debug properly and I hope you can help with a few pointers:

Thank you so much, George

mergennachin commented 1 month ago

a few things to try:

mergennachin commented 1 month ago

Also, there are two install_requirements. And you have to run both of them, in this order:

top-level: ./install_requirement.sh --pybind coreml coreml specific: ./backends/apple/coreml/scripts/install_requirements.sh

orgicus commented 1 month ago

I've followed your advice: thank you for that. Unfortunately I'm running into another error using ./install_requirements.sh --pybind coreml

[ 27%] Building CXX object CMakeFiles/executorch_no_prim_ops.dir/runtime/platform/target/Posix.cpp.o
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/kernel/operator_registry.cpp:137:23: error: no member named 'MAX_SIZE' in 'torch::executor::KernelKey'
    char buf[KernelKey::MAX_SIZE] = {0};
             ~~~~~~~~~~~^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/kernel/operator_registry.cpp:160:23: error: no member named 'MAX_SIZE' in 'torch::executor::KernelKey'
    char buf[KernelKey::MAX_SIZE] = {0};
             ~~~~~~~~~~~^
  2 errors generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/kernel/operator_registry.cpp.o] Error 1
  make[3]: *** Waiting for unfinished jobs....
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/platform/target/Posix.cpp:116:1: error: unknown type name 'et_tick_ratio_t'
  et_tick_ratio_t et_pal_ticks_to_ns_multiplier(void) {
  ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/platform/target/Posix.cpp:118:10: error: excess elements in scalar initializer
    return {1, 1};
           ^ ~~~~
  2 errors generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/platform/target/Posix.cpp.o] Error 1
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/core/exec_aten/util/tensor_util_portable.cpp:58:7: error: use of undeclared identifier 'is_contiguous_dim_order'
        is_contiguous_dim_order(t.dim_order().data(), t.dim_order().size()) ||
        ^
  1 error generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/core/exec_aten/util/tensor_util_portable.cpp.o] Error 1
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:184:12: error: no matching constructor for initialization of 'Program'
      return Program(
             ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:253:3: note: candidate constructor not viable: requires 4 arguments, but 5 were provided
    Program(
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:88:3: note: candidate constructor not viable: requires 1 argument, but 5 were provided
    Program(Program&&) noexcept = default;
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:265:3: note: candidate constructor not viable: requires single argument 'rhs', but 5 arguments were provided
    Program(const Program& rhs) = delete;
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:193:12: error: no matching constructor for initialization of 'Program'
      return Program(
             ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:253:3: note: candidate constructor not viable: requires 4 arguments, but 5 were provided
    Program(
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:88:3: note: candidate constructor not viable: requires 1 argument, but 5 were provided
    Program(Program&&) noexcept = default;
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:265:3: note: candidate constructor not viable: requires single argument 'rhs', but 5 arguments were provided
    Program(const Program& rhs) = delete;
    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:271:30: error: out-of-line definition of 'get_constant_buffer_data' does not match any declaration in 'torch::executor::Program'
  Result<const void*> Program::get_constant_buffer_data(
                               ^~~~~~~~~~~~~~~~~~~~~~~~
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/tensor_parser_portable.cpp:38:7: error: use of undeclared identifier 'isValid'
        isValid(scalar_type) &&
        ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:280:7: error: use of undeclared identifier 'constant_segment_data_'
    if (constant_segment_data_.data() != nullptr) {
        ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/tensor_parser_exec_aten.cpp:58:42: error: too many arguments to function call, expected single argument 'buffer_idx', have 2 arguments
          s_tensor->constant_buffer_idx(), nbytes);
                                           ^~~~~~
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/../executorch/runtime/executor/program.h:96:23: note: 'get_constant_buffer_data' declared here
    Result<const void*> get_constant_buffer_data(size_t buffer_idx) const;
                        ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:297:19: error: use of undeclared identifier 'constant_segment_data_'
      size_t size = constant_segment_data_.size();
                    ^
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/method.cpp:1154:14: error: out-of-line definition of 'log_outputs' does not match any declaration in 'torch::executor::Method'
  void Method::log_outputs() {
               ^~~~~~~~~~~
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/method.cpp:1317:22: error: out-of-line definition of 'get_event_tracer' does not match any declaration in 'torch::executor::Method'
  EventTracer* Method::get_event_tracer() {
                       ^~~~~~~~~~~~~~~~
  /Users/george.profenza/Documents/cv/executorch_v0.2.0/runtime/executor/program.cpp:309:43: error: use of undeclared identifier 'constant_segment_data_'
          static_cast<const unsigned char*>(constant_segment_data_.data()) +
                                            ^
  1 error generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/executor/tensor_parser_portable.cpp.o] Error 1
  1 error generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/executor/tensor_parser_exec_aten.cpp.o] Error 1
  2 errors generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/executor/method.cpp.o] Error 1
  6 errors generated.
  make[3]: *** [CMakeFiles/executorch_no_prim_ops.dir/runtime/executor/program.cpp.o] Error 1
  make[2]: *** [CMakeFiles/executorch_no_prim_ops.dir/all] Error 2
  make[1]: *** [CMakeFiles/portable_lib.dir/rule] Error 2
  make: *** [portable_lib] Error 2
  error: command '/Users/george.profenza/.pyenv/versions/mambaforge-22.9.0-3/envs/executorch/bin/cmake' failed with exit code 2
  error: subprocess-exited-with-error

  × Building wheel for executorch (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /Users/george.profenza/.pyenv/versions/mambaforge-22.9.0-3/envs/executorch/bin/python3.10 /Users/george.profenza/.pyenv/versions/mambaforge-22.9.0-3/envs/executorch/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /var/folders/fm/5zdm6gd15l7086j2jnr291xm0000gn/T/tmp_e0mrfbq
  cwd: /Users/george.profenza/Documents/cv/executorch_v0.2.0
  Building wheel for executorch (pyproject.toml) ... error
  ERROR: Failed building wheel for executorch
Failed to build executorch
ERROR: Could not build wheels for executorch, which is required to install pyproject.toml-based projects
mergennachin commented 1 month ago

cc @shoumikhin - do you have any idea on this issue?

could your recent changes solve this issue?