Load the transcription stack on first use - #1480
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
Conversation
Python runs faster_whisper/__init__.py before any submodule, so `from faster_whisper.vad import get_vad_model` imported faster_whisper.transcribe and ctranslate2 along with it. The VAD needs numpy, one helper from utils and onnxruntime, none of the rest. WhisperModel and BatchedInferencePipeline now resolve through a PEP 562 module __getattr__, the same shape as the already-merged OpenNMT/CTranslate2#2080. Importing either still works, from the package or as an attribute, and an unknown name still raises AttributeError. Measured here, python 3.12: before 6.96s ctranslate2 and faster_whisper.transcribe loaded after 0.14s neither loaded Closes SYSTRAN#1479 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DnFJxiG7r2xeshM4G8rm3y
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.
Closes #1479.
Python runs
faster_whisper/__init__.pybefore any submodule, sofrom faster_whisper.vad import get_vad_modelimportedfaster_whisper.transcribeandctranslate2along with it. The VAD needsnumpy, one helper from
utils, and onnxruntime, none of the rest.WhisperModelandBatchedInferencePipelinenow resolve through a PEP 562module
__getattr__, which is the shape the issue suggested and the same onealready merged as OpenNMT/CTranslate2#2080.
Measured here on Python 3.12:
Nothing about the public API changes.
from faster_whisper import WhisperModel,faster_whisper.WhisperModel, andfrom faster_whisper.transcribe import WhisperModelall still work,dir()still lists both names, and an unknownattribute still raises
AttributeError. There are tests for each of those, plusone asserting that the stack does load on first use, so the laziness cannot
quietly turn into a missing import.
The import assertions run in a subprocess, since
sys.modulesis alreadypopulated inside a pytest session.
black,isortandflake8are clean. Suite goes from 19 to 24 passing.