If SadTalker stops during generation with an error such as:
torch.cuda.OutOfMemoryError: CUDA out of memoryyour GPU has run out of usable VRAM for the current operation.
This usually does not mean SadTalker is installed incorrectly. In most cases, the GPU either does not have enough free memory, another program is already using part of the VRAM, or the current SadTalker settings require more memory than is available.
Start with the low-VRAM settings below, then verify the result on your own GPU. These steps are based on upstream documentation and public reports; they are not a locally reproduced OOM recovery test.
Quick Fix
Try these changes in this order:
- Close other applications using your NVIDIA GPU.
- Restart SadTalker or its Python process.
- Set SadTalker batch size to
1. - Use the
256face model instead of512. - Turn off GFPGAN Face Enhancer.
- Turn off the background enhancer if enabled.
- Run SadTalker again while monitoring VRAM with
nvidia-smi.
Run this from your SadTalker folder with its Python environment active. Replace input.wav and input.png with your own file paths. The multiline examples use Bash; in Windows PowerShell or Command Prompt, put the command on one line:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--size 256 \
--batch_size 1What Does CUDA Out of Memory Mean?
SadTalker uses PyTorch to run neural-network operations on an NVIDIA GPU.
The GPU has its own memory called VRAM. When PyTorch requests another block of GPU memory and enough usable VRAM is not available, generation can stop with a CUDA out-of-memory error.
A typical error begins with:
torch.cuda.OutOfMemoryError: CUDA out of memoryThe rest of the message may tell you how much memory PyTorch attempted to allocate, how much VRAM the GPU contains, and how much memory remained free.
The exact numbers will be different on every system.
First Check Your GPU Memory
Open another terminal while SadTalker is running:
nvidia-smiLook for:
Memory-UsageFor example:
8000 MiB / 12288 MiBThis illustrative reading means about 7.8 GiB of a 12 GiB GPU is occupied; it is not a measurement from our test.
Also inspect the Processes section at the bottom of nvidia-smi.
You may find another Python process, AI application, Stable Diffusion instance, browser workload, or another GPU program already consuming VRAM.
Monitor VRAM Continuously on Linux
Use:
watch -n 1 nvidia-smiThis refreshes GPU usage every second.
Press:
Ctrl+Cto stop monitoring.
Fix 1: Close Other GPU Processes
This is the first fix I recommend.
Run:
nvidia-smiCheck which processes are using GPU memory.
If another program that belongs to you is consuming several gigabytes of VRAM, close it before starting SadTalker.
On Linux you can also inspect Python processes:
ps -ef | grep pythonDo not terminate random processes on a shared GPU server. Only stop a process when you know it belongs to your own workload.
After closing the unwanted process, run:
nvidia-smiagain.
Make sure the GPU now has substantially more free memory.
Then retry SadTalker.
Fix 2: Reduce SadTalker Batch Size
SadTalker's command-line interface uses:
--batch_sizefor face rendering.
The default is 2.
Try:
--batch_size 1Example:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--batch_size 1If you use the SadTalker WebUI, reduce the batch size in generation setting to:
1A smaller batch generally requires less GPU memory.
Fix 3: Use 256 Instead of 512
SadTalker supports 256 and 512 face-render resolutions.
If you are running:
--size 512change it to:
--size 256Example:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--size 256 \
--batch_size 1SadTalker's default CLI resolution is already 256, making this a sensible setting for GPUs with limited VRAM.
In the WebUI, select:
256for the face model resolution.
Fix 4: Disable GFPGAN Face Enhancement
SadTalker can optionally run a face-restoration model after generating the animation.
You may see:
--enhancer gfpganin your command.
Try removing it.
Instead of:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--enhancer gfpganrun:
python inference.py \
--driven_audio input.wav \
--source_image input.pngIf you're using WebUI, turn off:
GFPGAN as Face enhancerThis isolates the additional restoration stage so you can check whether basic generation completes first.
Fix 5: Disable Background Enhancement
SadTalker also supports:
--background_enhancer realesrganIf you enabled it, remove the option while troubleshooting.
Start with basic generation first.
Once basic SadTalker generation works reliably, you can test optional enhancement separately.
Recommended Low-VRAM Command
If your GPU is struggling, use this as your starting point:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--result_dir results \
--size 256 \
--batch_size 1Notice what is intentionally missing:
--enhancer gfpgan
--background_enhancer realesrganStart with the simpler configuration before enabling additional processing.
Fix 6: Restart SadTalker
PyTorch uses a CUDA caching allocator.
This means GPU memory shown by nvidia-smi can sometimes remain reserved while a Python process is still alive.
Stop SadTalker completely and start it again.
Then check:
nvidia-smibefore generating another video.
If an old Python process remains active, identify it with:
ps -ef | grep pythonand stop only the process you own and recognize.
Does torch.cuda.empty_cache() Fix CUDA OOM?
You may see this command recommended online:
torch.cuda.empty_cache()It can release unused cached memory so that memory becomes available to other GPU applications.
However, it does not free GPU memory that is still being used by active PyTorch tensors.
For a normal SadTalker user, completely restarting the failed Python/SadTalker process is usually easier than modifying SadTalker's code to call empty_cache().
What About PYTORCH_CUDA_ALLOC_CONF?
Some CUDA OOM messages mention:
PYTORCH_CUDA_ALLOC_CONFUse the documentation for your installed PyTorch version. Current PyTorch documents PYTORCH_ALLOC_CONF, with PYTORCH_CUDA_ALLOC_CONF retained as a compatibility alias; older SadTalker environments commonly use the latter.
Allocator tuning can sometimes help when memory fragmentation is the actual problem.
However, PyTorch describes options such as max_split_size_mb as a last-resort setting for workloads that fail because of allocator fragmentation.
I would not use allocator settings as the first SadTalker fix.
First try:
- freeing VRAM,
- batch size
1, - resolution
256, - disabling GFPGAN,
- disabling background enhancement,
- restarting SadTalker.
Only investigate allocator configuration if the error specifically suggests that reserved but unused memory is unusually large.
Check PyTorch GPU Memory Directly
You can verify your CUDA GPU from the SadTalker environment with:
python -c "import torch; ok=torch.cuda.is_available(); print(ok); print(torch.cuda.get_device_name(0) if ok else 'CUDA unavailable')"A healthy NVIDIA setup should return something similar to:
True
NVIDIA GeForce RTX 3060If CUDA is available, inspect free and total GPU memory. This checks device-wide availability in a separate process; it does not measure SadTalker’s peak allocation:
python -c "import torch; free,total=torch.cuda.mem_get_info(); print('Free:',round(free/1024**3,2),'GiB'); print('Total:',round(total/1024**3,2),'GiB')"CUDA OOM vs CUDA Driver Errors
Do not confuse a CUDA OOM with a CUDA initialization problem.
A genuine memory error usually contains:
CUDA out of memoryErrors such as:
Failed to initialize NVMLor:
Driver/library version mismatchare different problems.
Likewise, CUDA initialization errors should be fixed at the NVIDIA driver/CUDA level rather than by lowering SadTalker's batch size.
How to Verify the Fix
After applying a change, first run:
nvidia-smiRecord the free VRAM.
Then run SadTalker:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--result_dir results \
--size 256 \
--batch_size 1While generation is running, monitor:
watch -n 1 nvidia-smiThe fix is verified when:
- SadTalker completes without a CUDA OOM,
- an MP4 is created in the results directory,
- the MP4 opens and plays with the expected audio,
- and the process releases its GPU allocations when it exits (other programs may still occupy VRAM).
My Suggested Troubleshooting Order
If you want the shortest path, use this order:
| Step | Change |
|---|---|
| 1 | Run nvidia-smi |
| 2 | Close your unused GPU processes |
| 3 | Restart SadTalker |
| 4 | Set batch size to 1 |
| 5 | Set resolution to 256 |
| 6 | Disable GFPGAN |
| 7 | Disable background enhancement |
| 8 | Retest and monitor VRAM |
| 9 | Investigate allocator fragmentation only if the error points to it |
| 10 | Use CPU or a GPU with more VRAM if the workload still cannot fit |
Can SadTalker Run on a 4 GB GPU?
There is no single VRAM requirement that guarantees every SadTalker configuration will work.
A user in SadTalker discussion #457 reported an OOM on a 4 GB NVIDIA laptop GPU. That report is evidence of a failure, not a verified recovery or a universal minimum-VRAM requirement.
Available VRAM also depends on other GPU processes and the options enabled during inference.
If you're working with limited VRAM, start with:
256 resolution
batch size 1
no GFPGAN
no background enhancerCan I Run SadTalker on CPU Instead?
SadTalker's CLI includes a CPU option.
You can try:
python inference.py \
--driven_audio input.wav \
--source_image input.png \
--cpuCPU inference will normally be significantly slower than NVIDIA GPU inference, so I would treat this as a fallback rather than the first solution.
FAQ
Why does SadTalker say CUDA out of memory?
The GPU does not have enough usable VRAM for the current operation. Another GPU process, higher rendering settings, batch size, or optional enhancement can contribute to the problem.
What batch size should I use?
For troubleshooting low VRAM, start with:
batch size = 1Should I use SadTalker 256 or 512?
Try 256 first when GPU memory is limited.
Does GFPGAN require additional resources?
GFPGAN runs an additional face-restoration stage. If SadTalker fails during or around enhancement, disable GFPGAN and test basic generation first.
Will torch.cuda.empty_cache() solve every OOM?
No. It releases unused cached allocations, not memory occupied by active tensors.
How do I know another program is using my GPU?
Run:
nvidia-smiand inspect the process list and GPU memory usage.
What if nvidia-smi itself fails?
Then you probably have a GPU driver or NVIDIA runtime problem rather than a normal SadTalker CUDA OOM. Fix the NVIDIA environment before troubleshooting SadTalker's memory settings.