Guide to running a 22GB 35B parameter AI model on a 6GB GPU using llama.cpp flags for speed and memory optimization.
Key Takeaways
- Efficiently running large AI models on limited VRAM GPUs is possible by offloading expert weights to CPU RAM.
- Proper flag configuration in llama.cpp can multiply token generation speed without new hardware.
- Memory management strategies like MMAP and mlock are essential for stable and fast inference.
- Batch size tuning is a powerful but often overlooked lever for improving prompt processing speed.
- Turbo Quant offers promising memory savings for key-value cache but is not yet integrated into mainstream tools.
Summary
- The video explains how to run a 22GB QN3.6 35B AI model on a 6GB GPU efficiently using llama.cpp.
- It highlights the model's mixture of experts architecture, where only a subset of experts activate per token, reducing memory traffic.
- Five key llama.cpp flags are introduced to improve token generation speed from 3 to 17 tokens per second on older GPUs.
- The N-CPU-MOA flag offloads expert weights of certain layers to CPU RAM, significantly saving VRAM usage.
- Memory mapping strategies (MMAP, No-MMAP, MLOCK) affect performance depending on system RAM and model size.
- Adjusting n_gpu_layers helps fill VRAM and boosts speed further, while mlock prevents kernel paging for stable performance.
- Token generation speed is limited by memory bandwidth when experts reside in system RAM rather than GPU VRAM.
- Batch size settings influence whether prompt processing runs on CPU or GPU, with larger micro batches greatly accelerating prompt reading.
- Turbo Quant is a quantization technique that drastically reduces key-value cache memory but is not yet merged into llama.cpp.
- Context length management is critical, with this model using linear attention in most layers to reduce cache size and enable very long contexts.
Chapters
- 00:00Introduction and Model Overview
- 00:49Mixture of Experts Architecture Explained
- 01:31Offloading Experts to CPU RAM
- 02:09Flag One: N-CPU-MOA and Speed Gains
- 02:43Tooling Limitations and Ollama
- 03:18Flag Two: Memory Mapping Strategies
- 03:59Flag Three: Adjusting GPU Layers for VRAM
- 04:29Flag Four: Preventing Kernel Paging with mlock
- 05:04Token Generation Speed and Hardware Limits
- 05:21Batch Size Impact on Prompt Processing











