Sub topic 12
Speed and Memory: GPU Use, FP16, and Quantization
This chapter assumes you know how to load a Whisper model and transcribe an audio file with Python. The goal is to make that transcription faster without using more memory than your hardware provides.
Choosing the right device
Whisper performs many matrix calculations. A graphics processing unit (GPU) can perform these calculations in parallel, so it usually transcribes audio much faster than a central processing unit (CPU).
A GPU must have enough video memory (VRAM) for the model and its working data. Larger models need more VRAM. Audio length also affects memory use, especially when you request timestamps or process several files at once.
import torch
import whisper
device = "cuda" if torch.cuda.is_available() else "cpu"
model = whisper.load_model("small", device=device)
result = model.transcribe(
"audio.mp3",
fp16=(device == "cuda"),
)
print(f"device: {device}")
print(result["text"])The fp16 option uses 16-bit floating-point numbers instead of the usual 32-bit numbers. FP16 reduces memory use and often increases GPU speed. Most modern NVIDIA GPUs support it well. On a CPU, FP16 may be unsupported or slower, so use fp16=False.
Model size and memory trade-offs
A smaller model needs less memory and usually runs faster. A larger model can recognize difficult speech more accurately, but it requires more computation.
| Model family | Relative speed | Relative accuracy | Typical use |
|---|---|---|---|
| tiny or base | fastest | lower | quick drafts and low-resource devices |
| small | medium | good | general applications |
| medium or large | slowest | highest | demanding transcription and review |
These are relative descriptions, not fixed performance guarantees. Language, hardware, audio quality, and decoding settings all affect the result. Test on representative recordings instead of choosing from model size alone.
When memory is limited, reduce the model size before changing other settings. You can also process files one at a time and release unused model objects.
Quantization
Quantization stores model values with fewer bits. An int8 model uses 8-bit integer representations for much of its computation. This can reduce memory use and improve CPU performance, with a possible small loss in accuracy.
The faster-whisper package uses the CTranslate2 runtime and supports quantized computation directly.
from faster_whisper import WhisperModel
model = WhisperModel(
"small",
device="cpu",
compute_type="int8",
)
segments, info = model.transcribe(
"audio.mp3",
beam_size=5,
)
print(f"language: {info.language}")
for segment in segments:
print(f"[{segment.start:.2f}s -> {segment.end:.2f}s] {segment.text}")For a CUDA GPU, you can try float16 computation:
model = WhisperModel(
"small",
device="cuda",
compute_type="float16",
)The supported compute types depend on the installed runtime, GPU, and operating system. If a type fails, choose a supported type such as int8 on CPU or float16 on a compatible GPU.
A practical tuning process
Change one variable at a time:
- Select a representative test set of recordings.
- Measure transcription time and memory use with the current model.
- Move from CPU to GPU if a compatible GPU is available.
- Try fp16 on the GPU or int8 on the CPU.
- Compare a smaller and a larger model.
- Check word error rate and important domain-specific terms.
Exercise
You need to run the small model on a CPU with limited memory. Which first change is most appropriate: increase the model size, set fp16=True, or use int8 with faster-whisper?
Show answer
Use int8 with faster-whisper. FP16 is mainly useful on compatible GPUs, while int8 can reduce CPU memory use.