fix(whisper): don't force CTranslate2's cub_caching allocator #9
3 changed files with 20 additions and 25 deletions
13
README.md
13
README.md
|
|
@ -72,12 +72,13 @@ Presets: `super-relaxed`, `relaxed`, `balanced`, `punchy`. See all options with
|
||||||
|
|
||||||
## GPU notes (Linux / NVIDIA)
|
## GPU notes (Linux / NVIDIA)
|
||||||
|
|
||||||
Transcription is memory-lean and degrades instead of crashing: cadence starts
|
Transcription is memory-lean and degrades instead of crashing. On CUDA it uses
|
||||||
with `int8_float16` and, if CTranslate2 still runs out of VRAM partway through a
|
`int8_float16` by default (`large-v3` in `float16` keeps ~3.7 GB resident and
|
||||||
long file (common with `large-v3` on a 6 GB card), it drops and releases the
|
runs out of VRAM on 6 GB cards). If CTranslate2 still reports an out-of-VRAM
|
||||||
model and retries with `int8` + greedy decoding before finally falling back to
|
error partway through a long file, cadence drops and releases the model and
|
||||||
CPU. When unset, `CT2_CUDA_ALLOCATOR=cub_caching` is selected for a more robust
|
retries with `int8` + greedy decoding, then CPU, instead of aborting. The
|
||||||
allocator.
|
CTranslate2 CUDA allocator is left at its default: forcing `cub_caching`
|
||||||
|
pre-reserves a large working set and makes things worse.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
|
|
||||||
27
cadence.py
27
cadence.py
|
|
@ -56,7 +56,7 @@ from typing import Literal
|
||||||
|
|
||||||
logger = logging.getLogger("cadence")
|
logger = logging.getLogger("cadence")
|
||||||
|
|
||||||
__version__ = "0.3.2"
|
__version__ = "0.3.3"
|
||||||
|
|
||||||
# Regex to catch elongated sounds like 'aaaa', 'uhhh', 'ummm', 'mmmm', 'eeeh', etc.
|
# Regex to catch elongated sounds like 'aaaa', 'uhhh', 'ummm', 'mmmm', 'eeeh', etc.
|
||||||
HESITATION_REGEX = re.compile(
|
HESITATION_REGEX = re.compile(
|
||||||
|
|
@ -119,9 +119,9 @@ VERBATIM_PROMPT = (
|
||||||
)
|
)
|
||||||
|
|
||||||
# faster-whisper / CTranslate2 GPU configs tried in order when transcription
|
# faster-whisper / CTranslate2 GPU configs tried in order when transcription
|
||||||
# runs out of VRAM. large-v3 in float16 needs ~4.5 GB, which leaves a 6 GB card
|
# runs out of VRAM. large-v3 in float16 keeps ~3.7 GB resident, which leaves a
|
||||||
# no headroom for decoder spikes, so we start memory-lean and step down on OOM.
|
# 6 GB card no headroom for decoder spikes, so we start memory-lean and step
|
||||||
# Each tuple is (device, compute_type, beam_size).
|
# down on OOM. Each tuple is (device, compute_type, beam_size).
|
||||||
FASTER_WHISPER_FALLBACKS: tuple[tuple[str, str, int], ...] = (
|
FASTER_WHISPER_FALLBACKS: tuple[tuple[str, str, int], ...] = (
|
||||||
("cuda", "int8_float16", 5),
|
("cuda", "int8_float16", 5),
|
||||||
("cuda", "int8", 1),
|
("cuda", "int8", 1),
|
||||||
|
|
@ -413,25 +413,16 @@ def _transcribe_mlx(
|
||||||
return words, raw_segments
|
return words, raw_segments
|
||||||
|
|
||||||
|
|
||||||
def _configure_ct2_cuda_allocator() -> None:
|
|
||||||
"""Prefer CTranslate2's caching CUDA allocator.
|
|
||||||
|
|
||||||
CTranslate2's default ``cuda_malloc_async`` allocator can surface spurious
|
|
||||||
"CUDA failed with error out of memory" errors under fragmentation or memory
|
|
||||||
pressure (OpenNMT/CTranslate2#690); ``cub_caching`` reuses freed blocks and
|
|
||||||
is more robust across a long transcription. Must be set before
|
|
||||||
``ctranslate2``/``faster_whisper`` is imported.
|
|
||||||
"""
|
|
||||||
if platform.system() == "Linux":
|
|
||||||
os.environ.setdefault("CT2_CUDA_ALLOCATOR", "cub_caching")
|
|
||||||
|
|
||||||
|
|
||||||
def _load_faster_whisper_model(
|
def _load_faster_whisper_model(
|
||||||
model_size: str,
|
model_size: str,
|
||||||
device: str | None = None,
|
device: str | None = None,
|
||||||
compute_type: str | None = None,
|
compute_type: str | None = None,
|
||||||
):
|
):
|
||||||
_configure_ct2_cuda_allocator()
|
# Leave CTranslate2's CUDA allocator at its default (``cuda_malloc_async``
|
||||||
|
# on modern GPUs). Forcing ``cub_caching`` pre-reserves a large working set
|
||||||
|
# -- measured ~2 GB extra on an RTX 3060 -- which pushes large-v3 over a
|
||||||
|
# 6 GB card's budget and *causes* the OOM it was meant to avoid, so
|
||||||
|
# CT2_CUDA_ALLOCATOR is deliberately never set here.
|
||||||
preload_nvidia_libs()
|
preload_nvidia_libs()
|
||||||
from faster_whisper import WhisperModel
|
from faster_whisper import WhisperModel
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,10 @@ def test_load_model_defaults_to_memory_lean_cuda(monkeypatch):
|
||||||
cadence._load_faster_whisper_model("large-v3")
|
cadence._load_faster_whisper_model("large-v3")
|
||||||
|
|
||||||
assert calls == [("large-v3", {"device": "cuda", "compute_type": "int8_float16"})]
|
assert calls == [("large-v3", {"device": "cuda", "compute_type": "int8_float16"})]
|
||||||
assert os.environ["CT2_CUDA_ALLOCATOR"] == "cub_caching"
|
# We must NOT force a CUDA allocator: cub_caching pre-reserves ~2 GB and
|
||||||
|
# makes large-v3 OOM on 6 GB cards, so the default (cuda_malloc_async) is
|
||||||
|
# left untouched.
|
||||||
|
assert "CT2_CUDA_ALLOCATOR" not in os.environ
|
||||||
|
|
||||||
|
|
||||||
def test_load_model_honours_explicit_device(monkeypatch):
|
def test_load_model_honours_explicit_device(monkeypatch):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue