vllm.v1.worker.startup_plan
¶
Persist and reuse the memory-profiling result across engine boots.
On startup, vLLM measures how much GPU memory the KV cache can use and
computes the --kv-cache-memory value that reproduces that allocation.
For a fixed (model, config, hardware, library) combination the result is
deterministic, yet it is re-measured on every boot.
When VLLM_ENABLE_STARTUP_PLAN=1, each worker persists that value under
{VLLM_CACHE_ROOT}/startup_plan/ (regenerable derived state, alongside
the torch.compile cache), keyed by a fingerprint of everything the value
depends on, and later boots apply it automatically -- skipping the
memory-profiling measurement and the CUDA-graph memory estimation pass --
if and only if the fingerprint matches and the device has at least as much
free memory as when the plan was recorded. On any mismatch the worker
falls back to full profiling, so a stale plan costs nothing and is never
trusted.
Functions:
-
compute_plan_fingerprint–Hash everything the profiled KV-cache memory value depends on.
-
maybe_apply_startup_plan–If enabled and
--kv-cache-memorywas not set explicitly, apply a -
maybe_save_startup_plan–Atomically persist this boot's profiling result for future boots.
_applicable_kv_cache_memory_bytes(plan, current_free_memory)
¶
The apply-time OOM-safety gate.
The recorded value is only valid if the device has at least as much free memory now as when the plan was measured (co-tenants, leaked allocations, or MIG changes all reduce it). Outside that envelope, return None and let the caller re-profile.
_load_plan(fingerprint)
¶
Load a plan for this fingerprint; None if absent or unreadable.
_plan_path(fingerprint)
¶
Plans are regenerable derived state, so they live under the standard
vLLM cache root (like the torch.compile cache) and relocate with
VLLM_CACHE_ROOT instead of needing a location knob of their own.
compute_plan_fingerprint(vllm_config, rank, world_size, pp_transport='nccl')
¶
Hash everything the profiled KV-cache memory value depends on.
VllmConfig.compile_factors() covers the vLLM version and the model,
cache, parallel, and compilation configs, but deliberately contains no
device identity (DeviceConfig.compile_factors is empty), so device
name, total memory, compute capability, and the torch/CUDA build are
added here. The vLLM version is also pinned as an explicit factor so
version invalidation holds no matter how compile_factors evolves.
Rank is included because per-rank memory use differs under TP/PP.
Driver-only changes are not part of the key; the free-memory gate at
apply time bounds the residual risk.
maybe_apply_startup_plan(worker)
¶
If enabled and --kv-cache-memory was not set explicitly, apply a
persisted plan by setting worker.cache_config.kv_cache_memory_bytes.
No-op unless VLLM_ENABLE_STARTUP_PLAN=1.
maybe_save_startup_plan(worker, kv_cache_memory_bytes)
¶
Atomically persist this boot's profiling result for future boots.
No-op unless VLLM_ENABLE_STARTUP_PLAN=1; failures are logged,
never raised.