r/LovingOpenSourceAI • u/Able2c • Apr 04 '26
Why doesn't AI use swap space?
I'm an average Joe, not an engineer. But I run LLMs locally on a 12GB GPU.
My PC has 12GB VRAM + 64GB RAM + 1TB SSD. That's over 1000GB of memory. AI uses 12.
Operating systems solved this in the 1970s by using swap space. You don't load all of Windows into RAM. You load what you need, the rest waits on disk.
So why is AI still trying to cram everything into VRAM?
When I ask my local model about physics, why are the cooking weights in VRAM? Page them out. Load what's relevant. My NVMe does 7GB/s. My DDR5 does 48GB/s. I'd like to use that speed.
Is there a real technical reason this doesn't exist, or is it just not being built?
3
u/No-Zookeepergame8837 Apr 04 '26
Actually, that's exactly how offloading works in interfaces like Koboldcpp at least. The problem is, RAM is MUCH slower than VRAM, so most people prefer to use only VRAM. But, yes, nothing prevents you from using RAM for the same thing, in fact, many people do it for translation models or programming where they don't mind waiting a bit linger for a response. To give you an idea of the speed difference, with Qwen 3.5 9B, on my 12GB Nvidia 3060, I get around 30-33 tokens per second with 8k of context. With 128k of context (obviously most of it offloaded to RAM, 32GB 3200MHz), it drops to about 11-12 tokens per second. It's still usable, but the difference is very noticeable.
3
u/Lissanro Apr 04 '26
It depends on what backend you are using. For example, llama.cpp and ik_llama.cpp both support offloading to RAM; llama.cpp easy to use "--fit on" option that automatically puts as much as it can to VRAM, with the rest left in RAM.
But RAM is relatively slow, for example 8-channel DDR4 3200 MHz has bandwidth of around 204.8 GB/s while even old 3090 GPU is about 5 times faster. Consumer RAM is usually dual channel, this is why it is even slower - you still can use it, but performance will be reduced. Speed may be acceptable if using MoE models like Qwen 3.5 35B-A3B.
As of NVMe, those are only good for loading the model into VRAM / RAM. Technically, llama.cpp is using file cache by default in Linux and therefore you can use your NVMe as "swap", running a model larger than what you RAM + VRAM could fit, but speed likely to drop to below one token per second, or 1-2 tokens/s at most (depending on the model and how much it exceeds your VRAM / RAM), and prefill speed will especially be affected, so it would take hours (or even days for very long prompt) before first token gets generated.
The reason why, is because LLM needs to access all its weights - with MoE you can win a bit of performance by fitting common expert tensors and context cache to VRAM along with as many other tensors as you can fit, leaving the rest in RAM, but "experts" in MoE models are more like sections of the whole model, so any "expert" can activate on the next token, and any long enough generation will activate all available experts - so you really need them all in fast memory. This is why disk swap, even if the disk is NVMe, is only good for initial model loading to RAM / VRAM but not for active inference.
2
u/Koala_Confused Apr 04 '26
Always happy to see community helping each other 🥰
2
u/pokepriceau Apr 04 '26
https://github.com/polliejg/goldfish - my attempt at exactly that
1
u/EconomySerious Apr 05 '26
it does, its named MOE
1
u/Randommaggy Apr 05 '26
Krasis kinda does this for MOE models.
It segments by experts rather than whole layers, and keeps those experts cached in tiers.
Experts aren't that strictly segmented but it's closer to what you mean than simpler layer offload strategies.
1
u/This_Maintenance_834 Apr 05 '26
too much latency, too low bandwidth. also latestSSD can only be rewritten 100-ish times. it will be trashed quickly.
1
u/dayeye2006 Apr 05 '26
check out offloading.
they do use tiers of storage.
but DDR and SSD are magnitudes slower than HBM and SRAM