Skip to content
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

Cannot generate CoreML model #2423

Open
aviaryan opened this issue Sep 19, 2024 · 1 comment
Open

Cannot generate CoreML model #2423

aviaryan opened this issue Sep 19, 2024 · 1 comment

Comments

@aviaryan
Copy link

I am following the instructions given in the README. However, I am not able to generate a CoreML model.

I did the following steps -

conda create -n py310-whisper python=3.10 -y
conda activate py310-whisper
pip install ane_transformers
pip install openai-whisper
pip install coremltools
./models/generate-coreml-model.sh base.en

And this is the error I get -

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/Users/aviaryan/dev/__others/whisper.cpp/models/convert-whisper-to-coreml.py", line 2, in <module>
    import torch
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/torch/__init__.py", line 870, in <module>
    from . import _masked
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/torch/_masked/__init__.py", line 420, in <module>
    def sum(input: Tensor,
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/torch/_masked/__init__.py", line 223, in _apply_docstring_templates
    example_input = torch.tensor([[-3, -2, -1], [0, 1, 2]])
/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/torch/_masked/__init__.py:223: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at  /Users/distiller/project/pytorch/torch/csrc/utils/tensor_numpy.cpp:68.)
  example_input = torch.tensor([[-3, -2, -1], [0, 1, 2]])
Minimum required torch version for importing coremltools.optimize.torch is 2.1.0. Got torch version 1.11.0.
Traceback (most recent call last):
  File "/Users/aviaryan/dev/__others/whisper.cpp/models/convert-whisper-to-coreml.py", line 4, in <module>
    import coremltools as ct
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/__init__.py", line 121, in <module>
    from . import converters, models, optimize, proto
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/__init__.py", line 7, in <module>
    from . import libsvm, sklearn, xgboost
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/libsvm/__init__.py", line 8, in <module>
    from . import _libsvm_converter, _libsvm_util
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/libsvm/_libsvm_converter.py", line 7, in <module>
    from coremltools.models import _METADATA_SOURCE, _METADATA_VERSION
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/models/__init__.py", line 12, in <module>
    from . import pipeline
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/models/pipeline.py", line 12, in <module>
    from . import model as _model
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/models/model.py", line 26, in <module>
    from coremltools.converters.mil.mil.program import Program as _Program
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/__init__.py", line 15, in <module>
    from .frontend.tensorflow.tf_op_registry import register_tf_op
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/frontend/__init__.py", line 6, in <module>
    from . import tensorflow, tensorflow2, torch
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/__init__.py", line 11, in <module>
    from . import ops, quantization_ops
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/ops.py", line 37, in <module>
    from .internal_graph import InternalTorchIRGraph, InternalTorchIRNode
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/internal_graph.py", line 15, in <module>
    from .exir_utils import extract_io_from_exir_program
  File "/Users/aviaryan/miniconda3/envs/py310-whisper/lib/python3.10/site-packages/coremltools/converters/mil/frontend/torch/exir_utils.py", line 100, in <module>
    ) -> Dict[str, torch.fx.Node]:
AttributeError: module 'torch' has no attribute 'fx'
coremlc: error: Model does not exist at models/coreml-encoder-base.en.mlpackage -- file:///Users/aviaryan/dev/__others/whisper.cpp/
mv: rename models/coreml-encoder-base.en.mlmodelc to models/ggml-base.en-encoder.mlmodelc: No such file or directory

Since Python dependency versions vary depending on when you run pip install, maybe someone can provide a lock file like a Pipfile.lock file that will always work.

@hagmonk
Copy link

hagmonk commented Sep 19, 2024

To get this to work I had to do:

pip install "numpy<2"
pip install torch==2.1.0

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

2 participants