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

Need to add Numba JIT support to work with librosa #2652

Open
wl-junlin opened this issue Jan 18, 2024 · 4 comments
Open

Need to add Numba JIT support to work with librosa #2652

wl-junlin opened this issue Jan 18, 2024 · 4 comments
Assignees
Labels
Milestone

Comments

@wl-junlin
Copy link

wl-junlin commented Jan 18, 2024

  • env

ubuntu20.04, python 3.11.5, Nuitka '1.9.7', librosa 0.10.1

  • compile command
    nuitka3 --standalone --onefile tests/test.py

  • compile message

Nuitka-Options:INFO: Used command line options: --standalone --onefile tests/test.py
Nuitka:INFO: Starting Python compilation with Nuitka '1.9.7' on Python '3.11' commercial grade 'not installed'.
Nuitka-Plugins:WARNING: anti-bloat: Undesirable import of 'numba' (intending to avoid 'numba') in 'librosa.core.spectrum' (at
Nuitka-Plugins:WARNING: '/home/me/miniconda3/lib/python3.11/site-packages/librosa/core/spectrum.py:12') encountered. It may slow down
Nuitka-Plugins:WARNING: compilation.
Nuitka-Plugins:WARNING: Complex topic! More information can be found at https://nuitka.net/info/unwanted-module.html
Nuitka-Plugins:WARNING: options-nanny: Using module 'numba' (version 0.58.1) with incomplete support due untrue condition 'not use_numba and
Nuitka-Plugins:WARNING: standalone': Numba is not yet working with Nuitka standalone, try to use '--noinclude-numba-mode', but it may fail.
Nuitka-Plugins:INFO: anti-bloat: Not including '_bisect' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation.
Nuitka-Plugins:INFO: anti-bloat: Not including '_json' automatically in order to avoid bloat, but this may cause: may slow down by using fallback implementation.
Nuitka-Plugins:INFO: anti-bloat: Not including 'matplotlib' automatically in order to avoid bloat, but this may cause: plotting will lack matplotlib.
Nuitka:INFO: Completed Python level compilation and optimization.
Nuitka:INFO: Generating source code for C backend compiler.
Nuitka:INFO: Running data composer tool for optimal constant value handling.
Nuitka:INFO: Running C compilation via Scons.
Nuitka-Scons:INFO: Backend C compiler: gcc (gcc 11).
Nuitka-Scons:INFO: Backend linking program with 907 files (no progress information available for this stage).
Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to
Nuitka-Scons:WARNING: install it.
Nuitka-Plugins:INFO: data-files: Included data file 'librosa/core/intervals.msgpack' due to package data for 'librosa.core.intervals'.
Nuitka-Plugins:INFO: dll-files: Found 1 file DLLs from llvmlite.binding.ffi installation.
Nuitka-Postprocessing:INFO: Creating single file from dist folder, this may take a while.
Nuitka-Onefile:INFO: Running bootstrap binary compilation via Scons.
Nuitka-Scons:INFO: Onefile C compiler: gcc (gcc 11).
Nuitka-Scons:INFO: Onefile linking program with 1 files (no progress information available for this stage).
Nuitka-Scons:WARNING: You are not using ccache, re-compilation of identical code will be slower than necessary. Use your OS package manager to
Nuitka-Scons:WARNING: install it.
Nuitka-Onefile:INFO: Using compression for onefile payload.
Nuitka-Onefile:INFO: Onefile payload compression ratio (20.99%) size 413489570 to 86787222.
Nuitka-Onefile:INFO: Keeping onefile build directory 'test.onefile-build'.
Nuitka:INFO: Keeping dist folder 'test.dist' for inspection, no need to use it.
Nuitka:INFO: Keeping build directory 'test.build'.
Nuitka:INFO: Successfully created 'test.bin'.

  • tests/test.py

    import sys
    from loguru import logger
    import librosa
    logger.remove()  # remove default log handler
    logger.add(sys.stderr, level="INFO")
    
    if __name__ == "__main__":
        audio_file = "tests/4sec.wav"
        sample_rate = 16000
        print('process audio file ', audio_file)
        waveform, _ = librosa.core.load(audio_file, sr=sample_rate)
        s = librosa.stft(waveform)
        logger.info("stft computed, shape: {}, dtype: {}".format(s.shape, s.dtype))
    
  • ran test.bin ----> error message:

process audio file tests/4sec.wav
Traceback (most recent call last):
File "/tmp/onefile_285719_1705472870_807632/test.py", line 20, in
File "", line 1176, in _find_and_load
File "", line 1147, in _find_and_load_unlocked
File "", line 690, in _load_unlocked
File "/tmp/onefile_285719_1705472870_807632/librosa/core/audio.py", line 1135, in
File "/tmp/onefile_285719_1705472870_807632/numba/stencils/stencil.py", line 816, in stencil
File "/tmp/onefile_285719_1705472870_807632/numba/stencils/stencil.py", line 825, in decorated
File "/tmp/onefile_285719_1705472870_807632/numba/core/compiler.py", line 334, in run_frontend
File "/tmp/onefile_285719_1705472870_807632/numba/core/interpreter.py", line 1363, in interpret
File "/tmp/onefile_285719_1705472870_807632/numba/core/byteflow.py", line 118, in run
File "/tmp/onefile_285719_1705472870_807632/numba/core/byteflow.py", line 281, in _is_implicit_new_block
File "/tmp/onefile_285719_1705472870_807632/numba/core/byteflow.py", line 1571, in get_inst
File "/tmp/onefile_285719_1705472870_807632/numba/core/bytecode.py", line 269, in getitem
KeyError: 2

Originally posted by @wl-junlin in #2418 (comment)

@wl-junlin wl-junlin changed the title can work with librosa can't work with librosa Jan 18, 2024
@kayhayen
Copy link
Member

I think I had some uses of librosa working, but numba is a problem, since we don't have the bytecode in compiled functions for obvious reasons. We recently added module decisions to disable Torch JIT by user choice, and I am looking at doing something similar, such that these functions if they are compiled, are maybe just ignored in that decorator.

I am not sure how new it is, never saw if before in numba code, but I didn't look too deep, but there is NUMBA_DISABLE_JIT which we might force to 1 and be good already.

@kayhayen
Copy link
Member

So, librosa is its newest incarnation will not work without numba at all, and does not support disabling the JIT at all. It has a @stencil decorator that just outright wants "kernel code" and handle its internal details. Removing its only use in librosa.audio doesn't help, it won't work without that. That makes it a duplicate of other similar issues. Adding that module decision, might help for some issues, but not for this issue.

@kayhayen kayhayen added bug delayed This is waiting for something else to be done first. labels Jan 22, 2024
@kayhayen kayhayen self-assigned this Jan 22, 2024
@kayhayen
Copy link
Member

While regular Numba JIT is now in fact something you can disable, it seems for librosa, we would have to have bytecode for at least this function, and maybe then it won't even be able to run in standalone fashion. This will take us to support retaining the bytecode of functions for compilation, or the time to devise a workaround, but it's not clear that it is even possible to do one for librosa there.

@kayhayen
Copy link
Member

For Tensorflow we are currently implementing JIT from source code, and it will be working for 2.2, and for Numba, I expect, we can do the same, having bytecode won't be a limitation there as well anymore. It will probably be a while until the new found ability makes it way to fully work with Numba, but it's going to come I guess.

@kayhayen kayhayen added this to the 2.2 milestone Mar 28, 2024
@kayhayen kayhayen removed the delayed This is waiting for something else to be done first. label Mar 28, 2024
@kayhayen kayhayen changed the title can't work with librosa Need to add Numba JIT support to work with librosa Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants