Open ltoniazzi opened 1 month ago
@ltoniazzi, Seems similar to #35. But this shouldn't happen if you installed the package from pip!! Please try the solution provided in that issue.
@abdeladim-s Thank you, but I cannot locate whisper.cpp in my installation as in the PR solution. The solution points to a path like
GGML_METAL_PATH_RESOURCES=/Users/my_user/Dev/Modules/pywhispercpp/whisper.cpp
But this is what I see in my pip installation of pywhispercpp
(in a virtual environment):
Where should I find the location of whisper.cpp
?
@ltoniazzi, Seems similar to #35. But this shouldn't happen if you installed the package from pip!! Please try the solution provided in that issue.
I'm actually having the same issue with sgml-metal, but my understanding is you must pre-generate the ggml-metal models using whisper.cpp's conversion tools.
whisper_init_state: loading Core ML model from '/Users/user/Library/Application Support/pywhispercpp/models/ggml-base.en-encoder.mlmodelc'
We should really fix this. The model should be loaded from the venv, not arbitrary locations on disk.
Ok, a bit of digging, we can get the en-encoder.mlmodelc from here: https://huggingface.co/ggerganov/whisper.cpp/tree/main
Renaming it to ggml-base.en-encoder.mlmodelc
and putting it in pwhispercpp/models works!
[2024-09-20 09:12:13,861] {model.py:132} INFO - Transcribing ...
Traceback (most recent call last):
File "/Users/user/Desktop/whisper-metal/__main__.py", line 4, in <module>
segments = model.transcribe('file.mp3')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Desktop/whisper-metal/.venv/lib/python3.12/site-packages/pywhispercpp/model.py", line 133, in transcribe
res = self._transcribe(audio, n_processors=n_processors)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Desktop/whisper-metal/.venv/lib/python3.12/site-packages/pywhispercpp/model.py", line 249, in _transcribe
res = Model._get_segments(self._ctx, 0, n)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/Desktop/whisper-metal/.venv/lib/python3.12/site-packages/pywhispercpp/model.py", line 154, in _get_segments
text = pw.whisper_full_get_segment_text(ctx, i)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 57-58: invalid continuation byte
I think we have a regression!
@ltoniazzi, @UsernamesLame, Could you please try the latest pre-built wheel from CI. I haven't pushed a new version yet to PyPI.
Pick the right wheel version from the artifacts and install it on a fresh virtual environment. Let me know if that works ?
@abdeladim-s I tried installing both wheels for Mac on python311 but I get this error inporting the package:
>>> from pywhispercpp.model import Model
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/__init__.py", line 14, in <module>
ctypes.CDLL(os.path.join(os.path.dirname(__file__), 'lib', file))
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ctypes/__init__.py", line 376, in __init__
self._handle = _dlopen(self._name, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: dlopen(/Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/lib/_pywhispercpp.cpython-38-darwin.so, 0x0006): Library not loaded: @rpath/libwhisper.1.dylib
Referenced from: <4499501D-7C43-3580-B7DB-D4F668C98970> /Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/lib/_pywhispercpp.cpython-38-darwin.so
Reason: tried: '/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-38/libwhisper.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-38/libwhisper.1.dylib' (no such file), '/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-38/libwhisper.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-38/libwhisper.1.dylib' (no such file)
>>> find .venv_testpywish/lib/ -name "libwhisper*.dylib"
File "<stdin>", line 1
find .venv_testpywish/lib/ -name "libwhisper*.dylib"
^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax
>>> exit()
Notes:
Install command
pip install ~/Downloads/artifact/pywhispercpp-1.2.0-cp311-cp311-macosx_11_0_universal2.whl
I have these in my venv:
find .venv_testpywish/lib/ -name "libwhisper*.dylib"
.venv_testpywish/lib//python3.11/site-packages/libwhisper.dylib .venv_testpywish/lib//python3.11/site-packages/libwhisper.1.dylib .venv_testpywish/lib//python3.11/site-packages/libwhisper.1.6.2.dylib
@ltoniazzi, could you please check if the lib folder /Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/lib
contains the libwhisper
dylib files ?
@abdeladim-s It contains these three:
>>> find .venv_testpywish_2/lib/ -name "libwhisper*.dylib"
.venv_testpywish_2/lib//python3.11/site-packages/libwhisper.dylib
.venv_testpywish_2/lib//python3.11/site-packages/libwhisper.1.dylib
.venv_testpywish_2/lib//python3.11/site-packages/libwhisper.1.6.2.dylib
@ltoniazzi,
Not in the .venv_testpywish_2/lib/
folder but inside pywhispercpp/lib
folder!
Could you also please check if the extension _pywhispercpp.cpython-38-darwin.so
is also in the pywhispercpp/lib
folder? .. maybe try to delete it and check ?
There is only these .so
files in there:
>>> ls .venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/lib
_pywhispercpp.cpython-310-darwin.so
_pywhispercpp.cpython-311-darwin.so
_pywhispercpp.cpython-38-darwin.so
_pywhispercpp.cpython-39-darwin.so
After deleting them I get this error:
>>> from pywhispercpp.model import Model
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/pywhispercpp/model.py", line 14, in <module>
import _pywhispercpp as pw
ImportError: dlopen(/Users/useruser/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/_pywhispercpp.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libwhisper.1.dylib
Referenced from: <6D5C74BD-6BC9-3B3F-9FBB-A28147E30808> /Users/user/Workspace/pre-screener/.venv_testpywish_2/lib/python3.11/site-packages/_pywhispercpp.cpython-311-darwin.so
Reason: tried: '/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-311/libwhisper.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-311/libwhisper.1.dylib' (no such file), '/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-311/libwhisper.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/runner/work/pywhispercpp/pywhispercpp/build/lib.macosx-10.9-universal2-cpython-311/libwhisper.1.dylib' (no such file)
@ltoniazzi, yeah there were no dylib
files there!
Please try this new build! I’ve added the dylib files to the lib folder.
Issue
Installed with:
and running:
The code runs on cpu as I see the ggml logs:
Question
How to fix this? should I add manually the path to
ggml-metal.metal
as an env variable?Running on Mac/M2