﻿# vLLM CuMemAllocator.discard: tagged release and state restoration

Understand vLLM discard without confusing mapped-memory release, CPU-backed sleep, wake-up and the complete orchestration needed to switch models correctly.

Author: Retrivium editorial team
Updated: 2026-11-05
Canonical URL: https://retrivium.ai/journal/vllm-cumem-discard-tags-wakeup-state-restoration/
Language: en

The name CuMemAllocator.discard describes a narrower operation than a complete model switch. In the reviewed vLLM source, it releases mapped GPU allocations selected by tags without creating CPU backups of their contents. Understanding that difference is essential when deciding what a later wake-up can restore and what the serving runtime must rebuild.

## Separate the historical proposal from current source

The [original roadmap discussion](https://github.com/vllm-project/vllm/issues/41733#issuecomment-4775215705) describes a contributor's model-switching work and proposes a tag-selective discard primitive. Its reported switching timings concern a broader orchestration system. They are not measurements of the allocator function alone.

The [reviewed upstream source](https://github.com/vllm-project/vllm/blob/82aeedf8db3d0bd45548fc5b9bb0301ae3a3b150/vllm/device_allocator/cumem.py) now contains a discard method. We inspected a dated source snapshot rather than assuming the earlier proposal was still the complete implementation status. A current branch can change, and the presence of a method there does not establish which packaged release or installed deployment contains it.

## Follow the allocation tags and policy

The allocator records tagged allocations and their sleep state. The discard method selects matching active allocations, waits for device work and releases their mapped backing through the sleep helper. Other tags are not selected by that call.

Already sleeping allocations require separate interpretation. The reviewed implementation does not silently change the policy of an allocation that already has a CPU backup. This matters for repeated calls and mixed sleep/discard workflows: the requested tag list alone is not a complete description of the resulting allocation state.

## Distinguish address availability from restored contents

Wake-up recreates mappings and copies back data when a CPU backup exists. An allocation discarded without a backup has no such saved content to restore. Recreating storage therefore differs from recovering the old tensor values.

A higher-level system must know which discarded state can be reinitialized and which needs an external source. Model weights, cache backing, graph-related buffers and runtime metadata have different lifecycles. A function that releases selected memory does not automatically reconstruct model configuration, reload a tokenizer or validate a live request after an architecture change.

## Keep correctness and memory accounting together

Useful checks include live-work synchronization, repeated discard and wake cycles, allocation-state transitions and output correctness after reinitialization. Measuring only free VRAM can miss a broken dependency or stale tensor content. Conversely, keeping an address reservation does not mean the original physical backing remains resident.

The original discussion's complete-switch timings should remain attributed to that contributor's setup. They should not become a universal restart time for every vLLM model or accelerator. Device synchronization, weight loading and other reconstruction work can dominate the operation around the allocator call.

## Record the exact reviewed version

A reproducible investigation needs the source revision, platform, allocation tags and the caller's reconstruction procedure. It should also identify which bytes are backed up and which are deliberately discarded. Memory release is a resource-management action, not evidence that every higher-level state transition or data-erasure property has been validated.

We read the upstream discard, sleep helper and wake-up paths together with the original discussion without running vLLM or changing inference settings. The [reproducible-stack guide](/journal/software-stack-reproducibility/) covers version records, and the [document-split guide](/journal/document-level-data-split-leakage/) covers a separate evaluation-data issue. The practical distinction is between freeing storage, recreating storage and restoring usable model state.

## Sources

- [Reviewed vLLM CuMemAllocator source](https://github.com/vllm-project/vllm/blob/82aeedf8db3d0bd45548fc5b9bb0301ae3a3b150/vllm/device_allocator/cumem.py).
- [Original tag-selective discard and model-switching discussion](https://github.com/vllm-project/vllm/issues/41733#issuecomment-4775215705).
