# torch.cuda.OutOfMemoryError: CUDA out of memory

> Markdown version of https://stella.sh/how/local-ai/torch-cuda-out-of-memory for agents and LLMs.
> Model loading, training or chat stopping with CUDA out of memory, tried to allocate? Stella (stella.sh) shrinks the job to fit your graphics card and runs it.

The job asked your graphics card for more memory than it has left. Stella (stella.sh) frees what other programs hold, then loads a smaller copy of the model or trains in smaller steps so the same work fits.

## What you get

- What's eating your card's memory, named
- A 4-bit or 8-bit copy of the model when it helps
- Training settings scaled to your card

## Ask Stella

> Training a LoRA in kohya stops with torch.cuda.OutOfMemoryError: CUDA out of memory, tried to allocate 2 GB. RTX 3060 12 GB.

## An example chat

**You:** Training a LoRA in kohya stops with torch.cuda.OutOfMemoryError: CUDA out of memory, tried to allocate 2 GB. RTX 3060 12 GB.

**Stella:** On it. Seeing what's already using your card.

*Stella works on: Fitting LoRA training on 12 GB*
- Browser and Discord hold 1.4 GB
- Batch size 4 is too big
- Turning on memory-saving training options
- Restarting training from your folder

**Stella:** Training runs now. Batch size is 1 with gradient checkpointing and 8-bit Adam, which keeps the 3060 under its 12 GB. Your LoRA saves to training/output every epoch as before.

Works on Windows, Linux.

## Questions

**Why does it say it tried to allocate only a little?**
Earlier steps already filled the card, so even a small extra request fails.

**Should I run a smaller model instead?**
Often a 4-bit copy of the same model is the better trade. It needs about a quarter of the memory and answers nearly as well.

**Is Stella free?**
Yes. Free with the ChatGPT, Claude or Gemini plan you already have.

## By hand

1. Close other programs using the GPU; check nvidia-smi for leftover Python.
2. Lower batch size or context length; turn on gradient checkpointing for training.
3. Load models in 4-bit or 8-bit with bitsandbytes, or use a GGUF in llama.cpp or Ollama.

## Related

- [ComfyUI out of memory: make it fit your graphics card](https://stella.sh/how/local-ai/comfyui-out-of-memory.md)
- [The best Ollama model for my PC](https://stella.sh/how/local-ai/best-ollama-model-for-your-pc.md)
- [CUDA driver version is insufficient for CUDA runtime version](https://stella.sh/how/local-ai/cuda-driver-version-is-insufficient.md)

Get Stella: https://stella.sh/download. Free with the ChatGPT, Claude or Gemini plan you already have.
