Fix RuntimeError: CUDA out of memory (PyTorch)
Fix PyTorch CUDA out-of-memory errors with profiling, batch and sequence controls, AMP, checkpointing, allocator tuning, distributed fixes, and GPU diagnostics.
8 articles
Fix PyTorch CUDA out-of-memory errors with profiling, batch and sequence controls, AMP, checkpointing, allocator tuning, distributed fixes, and GPU diagnostics.
If bitsandbytes loads libbitsandbytes_cpu.so, no CUDA binary matched. Upgrade bitsandbytes first, confirm a CUDA PyTorch, then fix the library path.
The traceback lies because CUDA runs async. Get the real line with CUDA_LAUNCH_BLOCKING=1 or the CPU, then fix the out-of-range index behind it.
The fastest test is torch.version.cuda — if it's None you have a CPU-only wheel. PyTorch bundles its own CUDA runtime, so you only need the NVIDIA driver.
These TensorFlow errors fire after the libraries load, so they're not path problems — usually GPU memory exhaustion (enable memory growth), a cuDNN/CUDA version mismatch, or the GPU being held by another process. How to diagnose and fix each.
This means the dynamic loader can't find the exact CUDA library your framework was built against. The '.9.0' suffix must match exactly — here's how to check whether it's a path problem or a missing CUDA toolkit, and fix each.
This TensorFlow message means it needs the CUDA 11.x runtime and can't find it. The '11.0' is a major-version SONAME — any CUDA 11.x provides it, CUDA 12 does not. Here's the triage and fix.
TensorFlow returns an empty GPU list even though CUDA is installed via conda — almost always a CUDA/cuDNN version mismatch or a conda-vs-system conflict. Diagnose it and fix it with tensorflow[and-cuda] or a matched conda environment.