fix(asr): CrisperWhisper ct2 venv needs torch+transformers for HF→CT2 conversion - #540
Merged
Merged
Conversation
…2 conversion
The Linux-x86 CrisperWhisper backend builds its subprocess venv from
`crisperwhisper[ct2]` only. CT2 *inference* is torch-free, but the first-run
HF->CT2 *conversion* (model._init_v2 -> converter.ensure_ct2_model ->
ctranslate2.converters.transformers._load) needs torch AND transformers: that
module does `try: import huggingface_hub, torch, transformers` and, when they are
absent, leaves the names unbound, then calls `torch.no_grad()` + the transformers
loader -> `NameError: name 'torch'/'transformers' is not defined`.
Effect at scale: the venv "builds" but every clip's CrisperWhisper ASR fails in
~0.7s with that NameError, silently dropping the whisper model from multi-ASR
runs (observed on a CUDA-13.1 GPU batch; canary-qwen + Qwen3-ASR still succeed).
macOS is unaffected: it uses the transformers backend, which already declares
torch and never invokes the CT2 converter.
Fix: add the `[transformers]` extra (transformers + torch + accelerate) to the
ct2 requirements and pin torch/torchaudio so ensure_venv routes them through the
CUDA index. The conversion is cached, so torch/transformers are installed but
never loaded at inference.
Why tests missed it: crisperwhisper_test.py's assembly test mocks
ensure_venv/subprocess (never builds the ct2 venv), and the end-to-end test is
skipif(not CRISPER_VENV.exists()) -> skipped in CI, and on macOS runs the
torch-having transformers backend. No test builds the [ct2] venv on Linux-x86 and
runs a conversion; a GPU-gated regression test (mirroring brouhaha_venv_gpu_test)
would cover it.
Verified on a GPU node: rebuilt venv transcribes a Stroop clip ("blue or maybe
green blue red blue blue"); all three ASR models return.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
Author
|
the other option, which requires a bit more logic, would be to create a one time venv for the conversion and then another for the inference. The challenge is that it is more work + if the cache directory for the model gets changed/moved, the venv needs to be reconstituted |
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.
Problem
On Linux x86_64, the CrisperWhisper backend builds its subprocess venv from
crisperwhisper[ct2]only. CT2 inference is torch-free, but the first-run HF→CT2 conversion (model._init_v2→converter.ensure_ct2_model→ctranslate2.converters.transformers._load) needs torch and transformers: that module doestry: import huggingface_hub, torch, transformersand, when they're absent, leaves the names unbound;_load()then callstorch.no_grad()and the transformers loader →NameError: name 'torch' / 'transformers' is not defined.Impact: the venv "builds" but every clip's CrisperWhisper ASR fails in ~0.7 s with that
NameError, silently dropping thewhispermodel from multi-ASR runs (found on a CUDA-13.1 GPU batch;canary-qwen+Qwen3-ASRstill succeed). macOS is unaffected — it uses the transformers backend (torch already declared) and never invokes the CT2 converter.Fix
Add the
[transformers]extra (== [all]alongside ct2: transformers + torch + accelerate) to the Linux-x86 ct2 requirements, and pintorch/torchaudiosoensure_venvroutes them through the CUDA-aware index. The conversion result is cached, so torch/transformers are installed but never loaded at CT2 inference time.Why CI didn't catch it
crisperwhisper_test.py:ensure_venv/venv_python/subprocess→ the ct2 venv is never built;test_crisperwhisper_transcribes_when_venv_presentis@skipif(not CRISPER_VENV.exists())→ skipped in CI, and where a dev has the venv (macOS) it runs the torch-having transformers backend.So no test builds the
[ct2]venv on Linux-x86 and runs a conversion — the only path that hits this. A GPU-gated regression test mirroringbrouhaha_venv_gpu_test.py(build ct2 venv + transcribe) would cover it; happy to add as a follow-up.Validation
Rebuilt the venv on a GPU node: CrisperWhisper now transcribes (e.g. "blue or maybe green blue red blue blue" on a Word-color-Stroop clip) and all three ASR models return.
Notes
Base:
alpha. Independent of #539 (HF-cache) — the two touch different regions ofcrisperwhisper.py(requirements list vshf_subprocess_envmodel staging) and merge cleanly.🤖 Generated with Claude Code
Version
Published prerelease version:
1.3.1-alpha.39Changelog
🐛 Bug Fix
Authors: 3