perf(whisper): lazy-import timing module to avoid loading scipy/numba#1413
Open
YashD5291 wants to merge 1 commit intoml-explore:mainfrom
Open
perf(whisper): lazy-import timing module to avoid loading scipy/numba#1413YashD5291 wants to merge 1 commit intoml-explore:mainfrom
YashD5291 wants to merge 1 commit intoml-explore:mainfrom
Conversation
Move `from .timing import add_word_timestamps` from module-level to inside the `if word_timestamps:` guard in transcribe(). timing.py imports scipy and numba at module level for word-level timestamp alignment (DTW + median filter). These are heavy dependencies (~212 MB combined) that load ~620 Python modules on import. When word_timestamps=False (the default), none of this code is ever called, yet it all gets loaded eagerly. This change makes scipy and numba truly optional for the common case of transcription without word timestamps, which: - Reduces import time significantly - Enables downstream packagers (PyInstaller, cx_Freeze) to exclude scipy/numba/llvmlite from bundles when word timestamps aren't needed - Saves ~212 MB in frozen/packaged applications
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
from .timing import add_word_timestampsfrom module-level to inside theif word_timestamps:guard intranscribe()scipyandnumbatruly optional whenword_timestamps=False(the default)Problem
timing.pyimportsscipyandnumbaat module level:These are loaded unconditionally via
transcribe.py's top-levelfrom .timing import add_word_timestamps, even whenword_timestamps=False. This eagerly loads ~620 Python modules and ~212 MB of native libraries that are never used.Fix
One-line change: move the import inside the
if word_timestamps:conditional where it's actually needed.Impact
import mlx_whisperno longer loads scipy/numba/llvmliteword_timestamps=True, the import fires on first use and everything works identicallyTesting
word_timestamps=False(default): scipy/numba never imported — verified viasys.modulesinspectionword_timestamps=True: import fires inside the conditional, all word timestamp functionality works as before