Skip to content
VoidIndex - Alexander Lee
Go back

How vLLM Sleep Mode Works

Edit page

Sleep Mode keeps the vLLM process alive and hands back only the physical GPU memory used by weights and KV cache; on wake-up it remaps memory at the same virtual addresses, cutting a model switch from tens of seconds to under a second [1][2].

Key points

Level 0 / 1 / 2

Level 0Level 1Level 2
What it doesPause schedulingOffloadDiscard
WeightsStay on GPUBacked up to pinned CPU memoryDiscarded
KV cacheStays on GPU; can be freed with release_kv_cache_memory()DiscardedDiscarded
After wake-upReady; if KV was freed, wake_up(tags=["kv_cache"])Readyreload_weights + reset_prefix_cache
CPU memoryNone≈ size of weightsMBs
Use forTemporarily freeing KV cache memoryRotating between modelsRLHF weight updates, low CPU RAM

How it works

CuMemAllocator takes over PyTorch allocations and uses CUDA virtual memory to separate virtual addresses from physical memory [3]:

flowchart LR
  T["Tensor / CUDA graph pointers"] --> V["Virtual address (unchanged)"]
  V -- map --> P["Physical GPU memory"]
  P -- "sleep: Level 1 backs up first" --> C["Pinned CPU memory"]
  V -. "sleep: unmap and release" .-> X["Memory returned"]
  C -- "wake_up: remap at same address, copy back" --> P

Usage

llm = LLM("Qwen/Qwen3-0.6B", enable_sleep_mode=True)

llm.sleep(level=1)
llm.wake_up()

# Level 0: pause, then free only the KV cache; weights stay on GPU
llm.sleep(level=0, mode="keep")
llm.release_kv_cache_memory()
llm.wake_up(tags=["kv_cache"])

# Level 2: wake in stages to keep peak memory low during a weight update
llm.sleep(level=2)
llm.wake_up(tags=["weights"])
llm.collective_rpc("reload_weights")
llm.wake_up(tags=["kv_cache"])

Online serving [1]:

VLLM_SERVER_DEV_MODE=1 vllm serve Qwen/Qwen3-0.6B --enable-sleep-mode
curl -X POST 'localhost:8000/sleep?level=1'
curl -X POST 'localhost:8000/wake_up'

VLLM_SERVER_DEV_MODE=1 enables development endpoints — don't expose them publicly.

Speedup

A100, TP=1, vLLM 0.11.0, switching between Qwen3-0.6B and Phi-3-vision 5 times [2]:

No sleepLevel 1Level 2
Total time357.1s112.6s124.6s
Per switch37.6–58.1s0.26–0.82s0.85–2.58s

Level 2 still reads weights from disk; it's faster because it skips process startup, graph capture, and kernel compilation.

Pitfalls

References

  1. vLLM Docs — Sleep Mode
  2. vLLM Blog — Zero-Reload Model Switching with vLLM Sleep Mode
  3. vLLM source — vllm/device_allocator/cumem.py
  4. vLLM API Docs — sleep mode backend

Edit page
Share this post:

Next Post
vLLM Quantization