Transcribe on the GPU when there is one, fall back to the CPU - #19
Open
simplaerai-sv wants to merge 1 commit into
Open
Transcribe on the GPU when there is one, fall back to the CPU#19simplaerai-sv wants to merge 1 commit into
simplaerai-sv wants to merge 1 commit into
Conversation
scripts/transcribe.py hard-coded device=cpu/int8. Pick cuda/float16 when ctranslate2 sees a CUDA device (KADR_WHISPER_DEVICE=cpu|cuda|auto to override), keep cpu/int8 as the fallback — at model load AND during inference: on Windows the model loads fine and the first kernel dies with 'cublas64_12.dll not found', so the transcribe loop is retried on the CPU, but only while no segment has reached the editor yet (a rerun after partial output would stream everything twice). Windows also needs the DLLs from the nvidia-cublas-cu12 / nvidia-cudnn-cu12 wheels, which pip puts in site-packages/nvidia/<lib>/bin, off the search path; register those folders with os.add_dll_directory before loading. RTX 4060, 60 s Ukrainian clip: small 15.5 s -> 6.9 s; large-v3 8.8 s including model load, i.e. a 50-minute lecture in about seven minutes. stdout stays NDJSON-only; electron/transcribe.ts is unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
What
scripts/transcribe.pyruns faster-whisper on the GPU when one isvisible, and keeps today's CPU path as the fallback. One file changed.
Why
The runner hard-codes
device="cpu", compute_type="int8". On a machinewith an NVIDIA card that leaves most of the box idle. Measured on the same
60-second Ukrainian clip, RTX 4060 (8 GB), 12-core CPU:
A 50-minute lecture on
large-v3goes from "leave it running" to aboutseven minutes.
How
pick_device()—cudawhenctranslate2reports a CUDA device, elsecpu.KADR_WHISPER_DEVICE=cpu|cuda|autooverrides (defaultauto),so a user can pin the CPU without touching code.
load_model()—cuda/float16, falling back tocpu/int8if the loaditself fails (driver too old, no VRAM).
run(). If the GPU fails duringinference — the common Windows case is a missing
cublas64_12.dll,the model loads fine and the first kernel dies — the job is redone on
the CPU. Only while nothing has been streamed yet: a CPU rerun after
partial GPU output would hand the editor every segment twice.
_register_nvidia_dlls()(Windows only) — the pip wheelsnvidia-cublas-cu12/nvidia-cudnn-cu12drop their DLLs undersite-packages/nvidia/<lib>/bin, which is not on the search path;registering those folders is what makes CUDA actually work from a plain
pip install. No-op on Linux/macOS.electron/transcribe.tsneeds no change.Behaviour on a machine without a GPU is byte-for-byte what it was.
Tested
Windows 11, Python 3.12, faster-whisper 1.2.1, ctranslate2 4.8.2:
smallandlarge-v3, timings above, Ukrainian recognisedcudaload →cublas64_12.dllerror → CPU rerun → exit 0, all segments presentKADR_WHISPER_DEVICE=cpu→ CPU path, unchanged outputUsers on Windows who want the GPU need
pip install nvidia-cublas-cu12 nvidia-cudnn-cu12on top offaster-whisper— happy to add a line to the README if you would like itin this PR.
🤖 Generated with Claude Code