Code Monkey home page Code Monkey logo

Comments (28)

BBC-Esq avatar BBC-Esq commented on June 10, 2024 1

Damn, was looking forward to benchmarking cuda whisper.cpp. Anyways, fun little adventure tonight. Have a good one man. I'll follow new releases for when you include the .dll and/or support GPU. How hard can it be, to support cuda, vulkan, openblas, etc. ;-)

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Seems like Python cannot see the DLL module for some reason, even though the wheels were built successfully for Windows.
I would suggest to try to build the package from source or use WSL.

from pywhispercpp.

NBNGaming avatar NBNGaming commented on June 10, 2024

I confirm this problem exists. Building from source results in the same error.

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

@NBNGaming,
if building from source leads to the same error, then I think something's missing from your system, because the Winodws wheels have been successfully built using GitHub actions without any issue.
Please make sure that you have the GCC toolchain and you can compile whisper.cpp first without any problems.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

I'm getting the same exact error message regarding the .dll file...I searched the "lib" directory after pip installing and there are no .dll files within that directory. Any idea why?

I'm not an expert so forgive me, but am I supposed to build whisper.cpp first and then install pywhispercpp? ggerganov's repo? I'm unfamiliar with building but can learn, but need to know if I have to install whisper.cpp first please. Thanks!

BTW, I don't know what GCC toolchain means...

Windows 10
CUDA 12.5
Intel CPU

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

@BBC-Esq, I am not quite sure why this is happening on Windows!
Usually, you don't need to build whisper.cpp if you pip installed the package and basically it should work out of the box. However if the pre-built wheel for your system is not working then you might need to build the project from source.

But, before going through this path, here are some suggestions:

  1. If you are using Python 3.12, try to downgrade to 3.10 or 3.11. This might solve the issue.
  2. Otherwise, use WSL instead if you are unfamiliar with building, this will work without issues I assume.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

I'm using Python 3.11. Not familiar with WSL...any other ideas? Have you actually tested it on Windows?

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Apart from the Github action which ran successfully, I didn't make any tests on Windows unfortunately, I only tested the project on Linux.
I just double checked now the pre-built Windows wheel for Python 3.11
pywhispercpp-1.2.0-cp311-cp311-win_amd64.whl and I can see that the dll .pyd file is there.
Could you please double check on your end ?

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Actually, it wasn't that hard to test and it gave me this error:

Traceback (most recent call last):
  File "D:\Scripts\benchmark_whisper\bench_whisper_cpp.py", line 1, in <module>
    from pywhispercpp.model import Model
  File "D:\Scripts\benchmark_whisper\Lib\site-packages\pywhispercpp\model.py", line 13, in <module>
    import _pywhispercpp as pw
ImportError: DLL load failed while importing _pywhispercpp: The specified module could not be found.

I did pip install and then the link to the wheel you gave me.

Here is the directory structure that another script of mine culled...Everything from the "pywhispercpp" directory downwards:

pywhispercpp/
    constants.py
    model.py
    utils.py
    _logger.py
    __init__.py
    examples/
        assistant.py
        livestream.py
        main.py
        recording.py
        __init__.py
        __pycache__/
            assistant.cpython-311.pyc
            livestream.cpython-311.pyc
            main.cpython-311.pyc
            recording.cpython-311.pyc
            __init__.cpython-311.pyc
    __pycache__/
        constants.cpython-311.pyc
        model.cpython-311.pyc
        utils.cpython-311.pyc
        _logger.cpython-311.pyc
        __init__.cpython-311.pyc

I noticed that the .pyd file is one level up within the "site-packages" folder though.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Correction in case you didn't see my edit to the above message...The .pyd file is a directory higher in "site-packages".

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

@BBC-Esq, so it's there at least. Not sure why Windows cannot find it!!
Can you in that case put the pyd file inside the pywhispercpp directory ?
Or Maybe if didn't work try to put it also in your current working directory D:\Scripts\benchmark_whisper\ ?

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Sure, I'll put it in both at the same time.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Same exact error as before. Might it be that you're importing "_pywhispercpp" with an underscore at the beginning instead of simply "pywhispercpp"?

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

The script I'm using is very simple. I even modified it to add appending the system path but am still getting the same error...

import sys
import os
from pywhispercpp.model import Model

# Add the directory containing the .pyd file to the sys.path
sys.path.append(os.path.dirname(os.path.abspath(r"D:\Scripts\benchmark_whisper\Lib\site-packages\_pywhispercpp.cp311-win_amd64.pyd")))

model = Model('base.en', n_threads=6)
segments = model.transcribe(r"D:\Scripts\benchmark_whisper\test_audio_flac_converted.wav", speed_up=True)
for segment in segments:
    print(segment.text)

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

No, the _pywhispercpp is the extension module :)

Can you try with os.add_dll_directory instead of sys.path.append

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Hmm...same as before...

image

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Hmm...same as before...

You should use os.add_dll... before the import!

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Same error as before and here's the modified script:

import os

dll_path = r"D:\Scripts\benchmark_whisper\_pywhispercpp.cp311-win_amd64.pyd"
dll_directory = os.path.dirname(dll_path)

os.add_dll_directory(dll_directory)

from pywhispercpp.model import Model

model = Model('base.en', n_threads=6)
segments = model.transcribe(r"D:\Scripts\benchmark_whisper\test_audio_flac_converted.wav", speed_up=True)

for segment in segments:
    print(segment.text)

I also tried this script:

import os
import ctypes

dll_path = r"D:\Scripts\benchmark_whisper\_pywhispercpp.cp311-win_amd64.pyd"
dll_directory = os.path.dirname(dll_path)

with os.add_dll_directory(dll_directory):
    ctypes.CDLL(dll_path)

    from pywhispercpp.model import Model

    model = Model('base.en', n_threads=6)
    segments = model.transcribe(r"D:\Scripts\benchmark_whisper\test_audio_flac_converted.wav", speed_up=True)

for segment in segments:
    print(segment.text)

It gave me a slightly different error:

Traceback (most recent call last):
  File "D:\Scripts\benchmark_whisper\bench_whisper_cpp.py", line 8, in <module>
    ctypes.CDLL(dll_path)
  File "C:\Users\Airflow\AppData\Local\Programs\Python\Python311\Lib\ctypes\__init__.py", line 376, in __init__
    self._handle = _dlopen(self._name, mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Could not find module 'D:\Scripts\benchmark_whisper\_pywhispercpp.cp311-win_amd64.pyd' (or one of its dependencies). Try using the full path with constructor syntax.

NOTE: It says "or one of its dependencies"

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Windows is weird to be honest!
if it complains about the dependencies then maybe you need Windows c++ redistributables or something! A lot of things can go wrong! Not quite sure what's the real issue.
That's why I suggested to use WSL!
In that case try to build whisper.cpp first and see if it works, you can find the instructions on their reop.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

I asked jeeves and he told me to try "dependency walker" from Microsoft but it didn't work...https://www.dependencywalker.com/

Then I tried https://github.com/lucasg/Dependencies/releases/tag/v1.11.1

The "file" "open" dialog only lets you select .dll files so you'll have to drag and drop the .pyd file...Anyways, this is what it gave me:

image

It seems that "whisper.dll" is missing? So basically, I need to install openai's whisper?

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Great idea @BBC-Esq,
Here is the whisper.dll file from ggerganov/whisper.cpp repo.
Maybe include it in the same directroy as well, hopefully this will solve the issue

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

Fucking A...it worked. I put it in the "site-packages" folder, the "benchmark_whisper" folder, and the "pywhispercpp" folder and it worked...now it's just a matter of narrowing it down to which folder hierarchy it should be in.

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

...correction, it didn't actually work. It resolved that error, but now I'm getting "failed to compute log mel spectrogram:"

[2024-05-29 22:58:13,706] {utils.py:38} INFO - No download directory was provided, models will be downloaded to C:\Users\Airflow\AppData\Local\pywhispercpp\pywhispercpp\models
[2024-05-29 22:58:13,707] {utils.py:46} INFO - Model base.en already exists in C:\Users\Airflow\AppData\Local\pywhispercpp\pywhispercpp\models
[2024-05-29 22:58:13,707] {model.py:221} INFO - Initializing the model ...
whisper_init_from_file_with_params_no_state: loading model from 'C:\Users\Airflow\AppData\Local\pywhispercpp\pywhispercpp\models\ggml-base.en.bin'
whisper_model_load: loading model
whisper_model_load: n_vocab       = 51864
whisper_model_load: n_audio_ctx   = 1500
whisper_model_load: n_audio_state = 512
whisper_model_load: n_audio_head  = 8
whisper_model_load: n_audio_layer = 6
whisper_model_load: n_text_ctx    = 448
whisper_model_load: n_text_state  = 512
whisper_model_load: n_text_head   = 8
whisper_model_load: n_text_layer  = 6
whisper_model_load: n_mels        = 80
whisper_model_load: ftype         = 1
whisper_model_load: qntvr         = 0
whisper_model_load: type          = 2 (base)
whisper_model_load: adding 1607 extra tokens
whisper_model_load: n_langs       = 99
whisper_model_load:      CPU buffer size =   147.46 MB
whisper_model_load: model size    =  147.37 MB
whisper_init_state: kv self size  =   16.52 MB
whisper_init_state: kv cross size =   18.43 MB
whisper_init_state: compute buffer (conv)   =   14.86 MB
whisper_init_state: compute buffer (encode) =   85.99 MB
whisper_init_state: compute buffer (cross)  =    4.78 MB
whisper_init_state: compute buffer (decode) =   96.48 MB
[2024-05-29 22:58:14,083] {model.py:130} INFO - Transcribing ...
whisper_full_with_state: failed to compute log mel spectrogram
[2024-05-29 22:58:14,083] {model.py:133} INFO - Inference time: 0.000 s

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

Finally! so that's what was missing! I should find a way to include it with the wheel!
For the failed to compute log mel spectrogram error, just remove speed_up True or set it to False!

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

I/we fixed it! Mind explaining to me what whisper.dll is and why we need it? Also, I have cuda installed. How can I use gpu acceleration in my script?

import os
import ctypes

dll_directory = r"D:\Scripts\benchmark_whisper\Lib\site-packages"
ctypes.windll.kernel32.SetDllDirectoryW(dll_directory)

ctypes.CDLL(os.path.join(dll_directory, '_pywhispercpp.cp311-win_amd64.pyd'))

from pywhispercpp.model import Model

model = Model(r"D:\Scripts\benchmark_whisper\Models\ggml-large-v2-q5_0.bin", n_threads=6)
segments = model.transcribe(r"D:\Scripts\benchmark_whisper\test_audio_flac_converted.wav", speed_up=False)

for segment in segments:
    print(segment.text)

from pywhispercpp.

BBC-Esq avatar BBC-Esq commented on June 10, 2024

...do tell me you've implemented the gpu acceleration like cuda, etc. in your repo? I don't see anything in the documentation about a cuda let alone any other gpu acceleration parameters... ;-)

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

The whisper.dll is very simply the file containing the executable code of whisper.cpp.
Unfortunately GPU is not supported at the moment, I didn't find time to add it!

from pywhispercpp.

abdeladim-s avatar abdeladim-s commented on June 10, 2024

It shouldn't be so hard I assume, but it'll need time, this is the problem :)
But feel free to take a look at the code as well, PRs are always welcome!

from pywhispercpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.