# Fix ROCm HIP out of memory (hipErrorOutOfMemory) on AMD Radeon RX 7900 XTX, RX 9070 XT & Strix Halo

> **Direct Error Triage**: On AMD Radeon GPUs (RX 7900 XTX 24GB, RX 9070 XT 16GB) and unified-memory APUs (Ryzen AI Max+ 395 Strix Halo 128GB), ROCm raises RuntimeError: HIP out of memory (hipErrorOutOfMemory) when a HIP allocation exceeds dedicated VRAM or hits Linux's default 50% GTT unified-memory cap. Fix it on discrete RDNA 3/4 cards by setting PYTORCH_HIP_ALLOC_CONF=expandable_segments:True, and on Strix Halo APUs by raising the kernel boot parameter amdgpu.gttsize=112640.

## Error Signature
```
RuntimeError: HIP out of memory. Tried to allocate ... MiB (hipErrorOutOfMemory)
```

## Root Cause & Memory Allocation Mechanics
AMD's ROCm HIP runtime mirrors CUDA's memory model on discrete graphics cards (`gfx1100` RDNA 3 and `gfx1201` RDNA 4), but exhibits two AMD-specific pitfalls. First, ROCm's Triton and MIOpen kernel compilers allocate sizable scratch workspaces during first-run tuning unless `PYTORCH_HIP_ALLOC_CONF=expandable_segments:True,garbage_collection_threshold:0.8` is set. Second, on AMD Strix Halo 128GB unified-memory systems (`gfx1151`), the Linux `amdgpu` driver defaults Graphics Translation Table (`GTT`) memory to only 50% of system RAM (64GB), causing `hipErrorOutOfMemory` on 70B–120B models even when 60GB of system LPDDR5X is sitting idle!

## Step-by-Step CLI Remediation
### Ollama
```bash
# Ensure correct GFX target override (if needed) and enable 8-bit KV cache on ROCm
export OLLAMA_FLASH_ATTENTION=1
export OLLAMA_KV_CACHE_TYPE=q8_0
# For Strix Halo (gfx1151) / RDNA 3 (gfx1100):
ollama serve
```

### Llama.cpp
```bash
# On Strix Halo 128GB Linux, unlock 110GB GTT unified memory in /etc/default/grub:
# GRUB_CMDLINE_LINUX_DEFAULT="quiet splash amdgpu.gttsize=112640 ttm.pages_limit=28835840"
./llama-server -m model.gguf -ngl 99 -fa on -ctk q8_0 -ctv q8_0
```

### vLLM
```bash
# Optimize PyTorch HIP allocator fragmentation and enable ROCm FlashAttention
export PYTORCH_HIP_ALLOC_CONF=expandable_segments:True,max_split_size_mb:128
export VLLM_USE_TRITON_FLASH_ATTN=1
vllm serve model --dtype float16 --max-model-len 8192 --gpu-memory-utilization 0.90
```

## Verified Hardware & Cloud Pathways
- Explore 24GB GPUs on Amazon: https://www.amazon.com/s?k=RTX+4090+24GB+graphics+card&tag=sparecables-20 (rel="noopener sponsored")
- Rent on RunPod: https://runpod.io?ref=ynypzu94 (rel="noopener sponsored")
- Rent on Vast.ai: https://cloud.vast.ai/?ref_id=723130 (rel="noopener sponsored")

---
*Interactive Sizing Calculator available at: https://www.gpugarden.com/oom/rocm-hip-out-of-memory/*
