-
fix(inference): backport vLLM SHM buffer ownership fix (#4031)
released this
2026-10-14 00:04:48 +00:00 Large out-of-band NumPy arrays returned by vLLM can still alias a
shared-memory ring slot afterMessageQueue.dequeue()releases it.
Subsequent messages overwrite retained routed-expert IDs, so router
replay can consume different IDs from those originally produced.Backport merged vLLM
#61000 through Prime
RL's general plugin. Copy SHM out-of-band buffers inside the read
context, and reuse the ownedbytearraywhen rebuilding Torch tensors.
Inline metadata, overflow/remote ZMQ paths and the wire format retain
their existing behavior. The patch is idempotent; its code comment links
upstream and identifies when the backport can be removed.Validation ran in isolated CPU processes without editing installed
dependencies:- The upstream unpatched queue fails both SHM NumPy retention cases;
this backport passes the applicable upstream queue suite: 52 passed, 2
GPU skips, 6 deselected due to the login node's 64 MiB SHM limit. - The pinned vLLM 0.31.0 source passes the lifetime and tensor
compatibility cases: 21 passed, 1 skipped. The private harness
explicitly closes test ZMQ contexts with zero linger: that version's
shutdown()only wakes readers, and the initial combined run hung
during context destruction. The production patch does not change
shutdown. - Patch installation is idempotent. Ruff check, Ruff format and
git diff --checkpass.
No fresh GPU serving or training benchmark was run for this backport;
upstream's merged PR includes GPU validation.
Note
Medium Risk
Patches core vLLM inter-process messaging (MessageQueue.dequeue);
incorrect behavior could affect distributed inference correctness,
though the change mirrors an upstream fix and is scoped to buffer
lifetime.Overview
Backports vLLM’s shared-memory buffer ownership fix into Prime RL’s
vLLM plugin so large out-of-band payloads no longer alias reusable ring
slots afterMessageQueue.dequeue()returns.The new
monkey_patch_shm_buffer_ownership()copies non-primary SHM
slices into ownedbytearrays while still inside the read lock, and
registers a matching_rebuild_tensorhelper so pickled torch tensors
rebuild from those copies. Overflow/remote ZMQ paths and the on-wire
layout are unchanged; the patch is idempotent and is meant to be dropped
once the pinned vLLM version includes upstream #61000.This addresses incorrect routed-expert IDs during router replay
when retained NumPy arrays were overwritten by later SHM messages.Reviewed by Cursor Bugbot for commit
c629d022462755dc268b82423fe6c6aea3827eda. Bugbot is set up for automated
code reviews on this repo. Configure
here.Downloads
- The upstream unpatched queue fails both SHM NumPy retention cases;