Skip to content

[Core] Add CuMemAllocator.discard() for tag-selective GPU memory release - #52514

Merged
ZJY0516 merged 7 commits into
vllm-project:mainfrom
andakai:feat/cumem-discard-tags
Aug 16, 2026
Merged

ZJY0516 merged 7 commits into
vllm-project:mainfrom
andakai:feat/cumem-discard-tags

Conversation

@andakai

@andakai andakai commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #46438.

PR #46438 introduces tag-selective discard(), allowing stale allocations such as KV cache to be released while keeping model weights mapped and usable.

Based on 46438, This PR refines the interaction between sleep() and discard() for both CUDA and XPU allocators:

  • Keep mapped weights usable when only KV-cache tags are discarded.
  • Synchronize the device before unmapping allocations.
  • Make wake_up() remap only allocations that are actually asleep.

The conflict check is needed because an asleep allocation has already been unmapped:

  • A discarded allocation has no CPU backup, so a later offload request cannot recover and back up its original contents.
  • An offloaded allocation already has a CPU backup, so a later discard request cannot silently change the established policy.

Repeated requests using the same policy remain silent and idempotent.

AlanFokCo and others added 4 commits July 10, 2026 23:36
Add a discard() method to CuMemAllocator that releases GPU physical
memory for the specified tags without backing up to CPU first.

Unlike sleep(), which operates on all allocations (offloading some and
discarding the rest), discard() only touches allocations matching the
given tags and leaves everything else mapped and usable. This is needed
for multi-model and RL weight-sync scenarios where stale data (e.g. a
previous model's KV cache) should be freed to make room for new
allocations while the current weights remain on GPU.

Reuses the existing is_asleep flag to prevent sleep() from double-
unmapping already-discarded handles. wake_up() already clears the flag
when remapping.

Signed-off-by: AlanFokCo <alanfok2868@gmail.com>
sleep() without arguments defaults to offload_tags=("default",),
but test_discard_tags uses custom tags "weights" and "kv_cache".
Without explicit offload_tags, weights memory was unmapped without
CPU backup, causing wake_up to remap with zeroed physical pages.

Signed-off-by: AlanFokCo <alanfok2868@gmail.com>
Co-authored-by: AlanFokCo <alanfok2868@gmail.com>
Signed-off-by: Dakai An <dakaian108@gmail.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@aoshen02 aoshen02 added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 16, 2026
@aoshen02

Copy link
Copy Markdown
Collaborator

/ci run

@github-actions

Copy link
Copy Markdown

✅ @andakai, CI is now available for this PR.

  • /ci run starts a CI build.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /ci cancel cancels scheduled or running CI builds for this PR branch.

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #84086 for commit 3f4b35216a69.

Comment thread vllm/device_allocator/xpumem.py Outdated
andakai and others added 2 commits August 16, 2026 20:39
Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Dakai An <dakaian108@gmail.com>
@aoshen02

Copy link
Copy Markdown
Collaborator

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #84087 for commit 46af14fc98db.

@ZJY0516 ZJY0516 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved by @aoshen02

@ZJY0516
ZJY0516 merged commit 9409f59 into vllm-project:main Aug 16, 2026
61 checks passed
zufangzhu pushed a commit to zufangzhu/vllm that referenced this pull request Aug 24, 2026
…ase (vllm-project#52514)

Signed-off-by: AlanFokCo <alanfok2868@gmail.com>
Signed-off-by: Dakai An <dakaian108@gmail.com>
Co-authored-by: AlanFokCo <alanfok2868@gmail.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Signed-off-by: Zhu, Zufang <zufang.zhu@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants