pytorch / executorch

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

Export to CoreML not working in current version #4425

Closed gustavofuhr closed 1 month ago

gustavofuhr commented 1 month ago

🐛 Describe the bug

Tried to run python3 -m examples.apple.coreml.scripts.export --model_name="mv3"

Torch version 2.5.0.dev20240716 has not been tested with coremltools. You may run into unexpected errors. Torch 2.2.0 is the most recent version that has been tested.
/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/exir/passes/_quant_patterns_and_replacements.py:106: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.
  @impl_abstract("quantized_decomposed::embedding_byte.out")
/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/exir/passes/_quant_patterns_and_replacements.py:153: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.
  @impl_abstract("quantized_decomposed::embedding_byte.dtype_out")
/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/exir/passes/_quant_patterns_and_replacements.py:228: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.
  @impl_abstract("quantized_decomposed::embedding_4bit.out")
/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/exir/passes/_quant_patterns_and_replacements.py:281: FutureWarning: `torch.library.impl_abstract` was renamed to `torch.library.register_fake`. Please use that instead; we will remove `torch.library.impl_abstract` in a future version of PyTorch.
  @impl_abstract("quantized_decomposed::embedding_4bit.dtype_out")
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/homebrew/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/third_party/executorch/examples/apple/coreml/scripts/export.py", line 17, in <module>
    from executorch.backends.apple.coreml.compiler import CoreMLBackend
  File "/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/backends/apple/coreml/compiler/__init__.py", line 5, in <module>
    from .coreml_preprocess import CoreMLBackend
  File "/Users/gustavofuhr/projects/object_detection_ios_comprehensive/executorch/.executorch_test/lib/python3.10/site-packages/executorch/backends/apple/coreml/compiler/coreml_preprocess.py", line 17, in <module>
    import executorchcoreml
ModuleNotFoundError: No module named 'executorchcoreml'

Versions

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

OS: macOS 14.5 (arm64) GCC version: Could not collect Clang version: 15.0.0 (clang-1500.3.9.4) CMake version: version 3.30.0 Libc version: N/A

Python version: 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.3.9.4)] (64-bit runtime) Python platform: macOS-14.5-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

CPU: Apple M3

Versions of relevant libraries: [pip3] executorch==0.4.0a0+9d85965 [pip3] numpy==1.26.4 [pip3] torch==2.5.0.dev20240716 [pip3] torchaudio==2.4.0.dev20240716 [pip3] torchsr==1.0.4 [pip3] torchvision==0.20.0.dev20240716 [conda] Could not collect

gustavofuhr commented 1 month ago

When I tried to downgrade pytorch to other version (2.3 and 2.2) I got different errors.

cymbalrush commented 1 month ago

@gustavofuhr did ./backends/apple/coreml/scripts/install_requirements.sh fail for you? Looks like executorchcoreml is not installed properly.

gustavofuhr commented 1 month ago

Thanks @cymbalrush, I overlooked the error in the install_requirements.sh, sorry about that. It was an incompatibility on the numpy version

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
executorch 0.3.0a0+ca8e0d2 requires numpy>=1.25.2, but you have numpy 1.21.3 which is incompatible.
matplotlib 3.9.1 requires numpy>=1.23, but you have numpy 1.21.3 which is incompatible.
opencv-python 4.10.0.84 requires numpy>=1.21.4; python_version >= "3.10" and platform_system == "Darwin", but you have numpy 1.21.3 which is incompatible.
pandas 2.2.2 requires numpy>=1.22.4; python_version < "3.11", but you have numpy 1.21.3 which is incompatible.
scipy 1.14.0 requires numpy<2.3,>=1.23.5, but you have numpy 1.21.3 which is incompatible.

I did pip install "numpy>=1.22.4,<2.0" and everything is working now, thanks!