Skip to content

Sleep Mode

vLLM's Sleep Mode allows you to temporarily release most GPU memory used by a model, including model weights and KV cache, without stopping the server or unloading the Docker container. This is especially useful for RLHF, training, or cost-saving scenarios where GPU resources need to be freed between inference workloads.

Key benefits:

  • Frees GPU memory: Offloads model weights to CPU RAM and discards KV cache, releasing up to 90%+ of GPU memory for other tasks.
  • Fast resume: Quickly wake up the engine and resume inference without full model reload.
  • API endpoints: Control sleep/wake_up state via HTTP endpoints or Python API.
  • Supports distributed workloads: Works with tensor parallelism, pipeline parallelism, etc.
  • Fine-grained control: Optionally wake up only model weights or KV cache to avoid OOM during weight updates.

Note

This feature is now supported on CUDA and ROCm platform.

Note

For more information, see this Blog Post.

Sleep levels

Level 1 sleep will offload the model weights and discard the KV cache. The content of KV cache is forgotten. Level 1 sleep is good for sleeping and waking up the engine to run the same model again. The model weights are backed up in CPU memory. Please make sure there's enough CPU memory to store the model weights. Level 2 sleep will discard both the model weights and the KV cache (while the model's buffers are kept in CPU, like rope scaling tensors). The content of both the model weights and KV cache is forgotten. Level 2 sleep is good for sleeping and waking up the engine to run a different model or update the model, where previous model weights are not needed, e.g. RLHF weight update.

Usage

Offline inference

Enable sleep mode by passing enable_sleep_mode=True to the LLM class.

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

Python API

# Sleep level 1
# Put the engine to sleep (level=1: offload weights to CPU RAM, discard KV cache)
llm.sleep(level=1)

# Wake up the engine (restore weights)
llm.wake_up()
# Sleep level 2
# Put the engine to sleep (level=2: discard both weights and KV cache)
llm.sleep(level=2)

# Reallocate weights memory only
llm.wake_up(tags=["weights"])

# Load weights in-place
llm.collective_rpc("reload_weights")

# Reallocate KV cache
llm.wake_up(tags=["kv_cache"])

RLHF weight updates

During RLHF training, vLLM allows you to selectively wake up only the model weights or the KV cache using the tags argument in wake_up(). This fine-grained control is especially useful when updating model weights: by waking up just the weights (e.g., llm.wake_up(tags=["weights"])), you avoid allocating memory for the KV cache until after the weight update is complete. This approach helps prevent GPU out-of-memory (OOM) errors, particularly with large models, by minimizing peak memory usage during weight synchronization and update operations.

Use tags=["weights"] or tags=["kv_cache"] to control which resources are restored, useful for RLHF and weight updates. is_sleeping will report true until all sleeping memory tags are restored. It also reports true while scheduling is paused or any tag-based sleep has not been woken up.

# Put engine to deep sleep (level=2)
llm.sleep(level=2)
# ... Get the new weights
# Wake up only weights to avoid OOM
llm.wake_up(tags=["weights"])
# ... Update the weights
# wake up KV cache after weights are updated
llm.wake_up(tags=["kv_cache"])

If you need direct resource-level control, use sleep(tags=...) and wake_up(tags=...) with memory tags. Tags identify GPU memory to release; they are not offload directives. Currently supported tags are "kv_cache" and "weights". Sleeping "weights" releases weight GPU memory; sleeping "kv_cache" releases KV cache GPU memory and discards KV cache contents. Sleeping memory is remapped empty on wake-up. Like level-based sleep, tag-based sleep accepts a mode argument to control in-flight requests. The default is mode="abort", which aborts in-flight requests before memory is released.

llm.sleep(tags=["kv_cache"])
llm.wake_up(tags=["kv_cache"])

llm.sleep(tags=["weights"])
llm.wake_up(tags=["weights"])

sleep(level=1/2) remains the preset form, while sleep(tags=...) is the explicit memory-tag form. If tags are provided, they take precedence over the level preset. sleep(level=0) only pauses scheduling. Sleeping an already sleeping tag or waking up a tag that is not sleeping is a no-op.

Online Serving

To enable sleep mode in a vLLM server you need to initialize it with the flag VLLM_SERVER_DEV_MODE=1 and pass --enable-sleep-mode to the vLLM server.

Server in development mode

When using the flag VLLM_SERVER_DEV_MODE=1 you enable development endpoints, and these endpoints should not be exposed to users.

VLLM_SERVER_DEV_MODE=1 vllm serve Qwen/Qwen3-0.6B \
  --enable-sleep-mode \
  --port 8000

Below is an example of how to sleep and wake up a model in level 1.

curl -X POST 'http://localhost:8000/sleep?level=1'
curl -X POST 'http://localhost:8000/wake_up'

And this is an example of how to sleep and wake up a model in level 2.

curl -X POST 'http://localhost:8000/sleep?level=2'
# Reallocate weights memory only
curl -X POST 'http://localhost:8000/wake_up?tags=weights'
# Load weights in-place
curl -X POST 'http://localhost:8000/collective_rpc' -H 'Content-Type: application/json' -d '{"method":"reload_weights"}'
# Reallocate KV cache
curl -X POST 'http://localhost:8000/wake_up?tags=kv_cache'

HTTP endpoints

  • POST /sleep?level=1 — Put the model to sleep (level=1).
  • POST /sleep?tags=kv_cache&mode=abort — Release the requested memory tags. Repeat tags to release multiple resources, for example ?tags=weights&tags=kv_cache.
  • POST /wake_up — Wake up the model. Supports optional tags query parameters for partial wake-up (e.g., ?tags=weights).
  • POST /collective_rpc — Perform a collective remote procedure call (RPC).
  • GET /is_sleeping — Check if the model is sleeping.

Note

These endpoints are only available when passing VLLM_SERVER_DEV_MODE=1.

Limitation

On ROCm, the virtual memory allocation on ROCm is done through chunked memory allocation. You can control the chunk size through VLLM_ROCM_SLEEP_MEM_CHUNK_SIZE (in MB). The default value is set at 256MB. The larger the chunk size the faster the performance. However, setting it too large will cause OOM. So if you encounter OOM when using sleep mode. Try reducing the chunk size. It is recommended to define the chunk size as a power of 2.