Skip to content

fix(asr): CrisperWhisper ct2 venv needs torch+transformers for HF→CT2 conversion - #540

Merged
wilke0818 merged 1 commit into
alphafrom
fix/crisperwhisper-ct2-conversion-deps
Jul 29, 2026
Merged

fix(asr): CrisperWhisper ct2 venv needs torch+transformers for HF→CT2 conversion#540
wilke0818 merged 1 commit into
alphafrom
fix/crisperwhisper-ct2-conversion-deps

Conversation

@wilke0818

@wilke0818 wilke0818 commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

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_v2converter.ensure_ct2_modelctranslate2.converters.transformers._load) needs torch and transformers: that module does try: import huggingface_hub, torch, transformers and, when they're absent, leaves the names unbound; _load() then calls torch.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 the whisper model from multi-ASR runs (found on a CUDA-13.1 GPU batch; canary-qwen + Qwen3-ASR still 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 pin torch/torchaudio so ensure_venv routes them through the CUDA-aware index. The conversion result is cached, so torch/transformers are installed but never loaded at CT2 inference time.

# before
_CRISPER_REQUIREMENTS = ["crisperwhisper[ct2]==2.0.1"]
# after
_CRISPER_REQUIREMENTS = ["crisperwhisper[ct2,transformers]==2.0.1", "torch>=2.4", "torchaudio>=2.4"]

Why CI didn't catch it

crisperwhisper_test.py:

  • the assembly test mocks ensure_venv / venv_python / subprocess → the ct2 venv is never built;
  • test_crisperwhisper_transcribes_when_venv_present is @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 mirroring brouhaha_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 of crisperwhisper.py (requirements list vs hf_subprocess_env model staging) and merge cleanly.

🤖 Generated with Claude Code

Version

Published prerelease version: 1.3.1-alpha.39

Changelog

🐛 Bug Fix

  • fix(asr): CrisperWhisper ct2 venv needs torch+transformers for HF→CT2 conversion #540 (@wilke0818)
  • hf-cache: stop HF Hub 429s under parallel batch (resolve-once + SHA-pin) #539 (@wilke0818)
  • fix(adaptive): guard None history in convergence improvement delta #541 (@wilke0818)
  • refactor(cache): cached-inference layer out of analyze_audio.py (T051, parts 1-2) #538 (@satra)
  • Scene-aware presence/quality axis + ASR transcription overhaul (CrisperWhisper 2.0, Qwen) #536 (@satra @claude)
  • feat(canary): split long audio at pauses to avoid the ~40s truncation #534 (@wilke0818)
  • ScriptLine: accept empty text as "model produced no transcript" signal #520 (@wilke0818)
  • Feat/pii subprocess venv #519 (@wilke0818)
  • subprocess_venv: route torch/torchaudio via CUDA-aware PyTorch index #516 (@satra @wilke0818)
  • subprocess_venv: two-stage install to fix torch/torchaudio CUDA-tag s… #518 (@wilke0818)
  • Fix/ser wav2vec2 regression head #511 (@satra @wilke0818 @claude)
  • comparison & uncertainty stage for analyze_audio.py #512 (@satra)
  • audio analysis script + multilingual MMS aligner + 4 new ASR backends #510 (@satra)

Authors: 3

…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>
@wilke0818

Copy link
Copy Markdown
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

@wilke0818
wilke0818 merged commit 66f244c into alpha Jul 29, 2026
10 checks passed
github-actions Bot added a commit that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant