Conversation
aoshen02
force-pushed
the
codex/artifact-r3-shm-pr12-rewrite
branch
5 times, most recently
from
August 1, 2026 09:40
f614b7d to
8471306
Compare
Co-authored-by: OpenAI Codex <codex@openai.com> Signed-off-by: aoshen02 <aoshen@inferact.ai>
aoshen02
force-pushed
the
codex/artifact-r3-shm-pr12-rewrite
branch
from
August 1, 2026 14:22
8471306 to
e64a44b
Compare
Derive full and partial artifact keys from the same logical token hashes used by prefix caching, plus the model weight version. Defer missing-object errors to materialization instead of coupling artifact readiness to KV hit selection. Keep capture collectives initialized on every TP rank while limiting SHM publication and request buffering to rank zero. Encapsulate materialization, terminal acknowledgements, and capture tasks behind Artifact Connector APIs, and simplify frontend stop handling around the terminal artifact value. Signed-off-by: Aoshen <aoshen@users.noreply.github.com> Co-authored-by: OpenAI Codex <codex@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack and review scope
aoshen02/vllm:codex/mrv2-r3-stackedata3caf7b0c4, the head of xhx1022/vllm#12.aoshen02/vllm:codex/artifact-r3-shm-pr12-rewriteate64a44b48e.This PR implements the first production-shaped Artifact Connector slice: R3
(routed-expert IDs), Model Runner V2, prefix reuse keyed like KV cache, and a
same-node SHM backend. It deliberately does not include Mooncake,
TransferQueue, prompt-logprobs artifacts, DSA artifacts, multimodal artifacts,
or request-wise top-p token IDs.
Why replace #4
#4 mixed parts of the old physical-slot mmap/offload lifecycle with the new
logical Artifact Connector. That made Artifact behavior influence KV admission
and left too much request/slot cleanup in Scheduler.
This rewrite establishes two strict boundaries:
block release. Artifact code never shortens a KV hit. If KV reports a hit but
the corresponding immutable Artifact object is missing, the engine fails
closed instead of recomputing or altering KV behavior.
does not depend on mutable physical KV slots, so CPU KV offload does not need
to move R3 alongside KV blocks.
Data and control flow
The last sampled token is excluded because it has not executed a target-model
forward pass.
Non-test changes and rationale
Configuration and compatibility
vllm/config/artifact.py,vllm/config/__init__.py,vllm/config/vllm.py, andvllm/engine/arg_utils.pyadd one explicitArtifactConfigand normal CLI/config plumbing.enable_routed_experts,backend selection, SHM path, capacity, and TTL have one canonical owner in
ArtifactConfig;ModelConfigno longer carries Artifact state. The legacy--enable-return-routed-expertsoption is translated once inEngineArgsfor compatibility. The SHM backend defaults to an 8 GiB
per-engine/per-DP-rank capacity and one-hour inactive-store TTL.
/dev/shm, rejects PP andcontext parallelism whose writer/ordering semantics are not implemented, and
rejects PD-disaggregated KV transfer. TP, asynchronous scheduling, prefix
caching, MTP speculative decoding, and
kv_role=kv_bothremain supported.gpu_worker.pyfollows the existingV1/V2 dynamic-import pattern but calls only the generic
init_artifacts()entrypoint after KV initialization. Routed-experts capture and backend
construction remain private ModelRunner/Artifact implementation details.
Unified routed-experts capture
routed_experts_capture/{__init__,common,state,async_output}.pykeeps onefocused MRV2 capture state.
ArtifactWorkerConnectornow creates, owns,clears, and snapshots that state;
GPUModelRunnerowns only the genericconnector and no longer exposes R3 capture internals. Every TP rank creates
and binds the capture state because router capture participates in TP
collectives. Only global rank zero constructs the SHM store, logical request
buffer, and request core, so publication remains single-writer without
deadlocking multi-rank capture. The no-op
close()and artificial Optional capturer state are removed; only theArtifact Store owns a closeable resource.
speculative rejection counts to the same stable async output. Router IDs are
converted from their compute dtype to the compact schema dtype
(
uint8/uint16) before entering the logical buffer.manager.pyandshared_region.pyphysical-slot mmap implementationis deleted. There is no second routed-experts cache indexed by mutable KV
slots.
gpu_model_runner.py,gpu/model_runner.py,gpu/async_utils.py, andgpu_worker.pyroute sync and async MRV2 output through the same Artifactconnector handoff. The async path depends only on the structural
ArtifactWriteTaskprotocol rather than an R3-specific task type. Theexisting V1 runner remains unchanged when Artifact mode is disabled.
Artifact Core and immutable key space
artifact_connector/buffer.pyowns only uncommitted logical request rows. Itsupports non-zero cached starts, overlap replacement after recomputation,
rejects gaps, and releases committed full-block prefixes.
artifact_connector/request_core.pyowns deterministic keys, objectenvelopes, checksums, full-block/tail encoding, ordered coverage, and
materialization. Both full blocks and a terminal partial block are addressed
by KV-compatible block hashes plus the model weight version. The Scheduler
computes a partial block hash from the same parent hash, token IDs, and KV
extra keys used by prefix caching; tails are therefore content-addressed and
are not request-attempt scoped.
ModelConfig.compute_hash()namespace orseparate Artifact profile ID. This deployment assumes an equal KV-compatible
hash plus equal model weight version denotes reusable R3; object envelopes
still validate dtype, shape, token range, identity, and checksum when read.
artifact_connector/store.pyis the backend-neutral immutable-objectcontract (
put,exists,get,close). It has no Scheduler, request, orR3-specific policy.
artifact_connector/shm.pyimplements atomic publish, immutable same-keyvalidation, checksums, bounded capacity, writer liveness, and TTL collection
under a trusted
/dev/shmroot. Readers consume values, not mmap paths orphysical-slot handles.
Strict failure semantics
per-request error strings. Capacity, collision, missing-object, checksum, and
finalize failures raise their typed exceptions immediately. Artifact mode is
a correctness mode: the engine must not return a successful response with
missing or partial R3.
ArtifactFinalizeResult.keysis mandatory. The optionalkeys,error, andredundant
ArtifactConnectorOutput.is_empty()branches are deleted.uncommitted logical request buffer. Already-published immutable blocks remain
available to later KV prefix hits.
ArtifactRequestCore.close()is deleted. Worker shutdowncloses the store directly.
routed_experts_prompt_startsampling option and itsScheduler guard are deleted. Artifact output has one canonical coverage rule:
every executed target-model token except the final unexecuted sampled token.
Scheduler/worker protocol
artifact_connector/protocol.pycarries commit/finalize operations usingrequest-attempt IDs, logical ranges, and block hashes. It contains no physical
block IDs.
artifact_connector/connector.pyseparates Scheduler control state fromworker publication. It deliberately has no prefix-readiness preflight:
Artifact availability never changes the KV-selected hit length. The
Scheduler-side connector validates finalize ACKs and materializes through
backend
get; a missing or corrupt object fails the request/engine closed.The rank-zero worker batches immutable puts and returns ordered terminal keys.
sched/output.pyandv1/outputs.pyadd only the Artifact metadata/outputfields needed on the existing SchedulerOutput/ModelRunnerOutput path.
sched/scheduler.pyobserves the KV-selected cached length, submits acceptedfull-block progress, and starts terminal finalization. It never checks
Artifact existence during KV admission and does not modify
KVCacheManager.get_computed_blocks,max_cache_hit_length, allocation,preemption, or block-free decisions.
finish_requestspathfor request lookup, queue removal, and finished-state update. Normal
completion and frontend-resolved stop both reuse
_free_request(..., artifact_token_end=...). Artifact delays only terminaldelivery until finalize ACK; it does not create a parallel request-removal or
resource-release lifecycle.
has_pending_workengine keep-alive.Active requests, existing
finished_req_idsmetadata scheduling, and thenormal async batch queue already provide progress; a private flag would create
an empty-step busy loop after a lost ACK.
sched/interface.py,engine/{__init__,core,core_client,async_llm,llm_engine, output_processor}.pypropagate the exact frontend-resolved token boundaryand hold only the terminal output until worker ACK materialization.
get_grammar_bitmaskstructured-output implementation isunchanged; it only appears in large Scheduler diff context.
Remove obsolete KV-offload sidecars
kv_transfer/.../sidecar.py,offloading/sidecar.py, and the sidecar test aredeleted;
offloading_connector.pydrops the corresponding hooks.Moving it in every CPU KV transfer would duplicate storage and couple
Artifact correctness back to one KV connector implementation.
Terminal API delivery
serial_utils.pyadds ndarray.npybase64 encoding.R3 only to the terminal choice/output. HTTP users do not receive SHM paths and
do not concatenate blocks themselves.
is returned only by the existing non-streaming terminal response paths.
boundary while the terminal response waits for Artifact finalization. A
terminal
routed_expertsvalue is itself the ACK-backed completion signal;stale frames without that value cannot complete a pending frontend stop.
Weight-version isolation
Prefix reuse across in-place model updates therefore cannot return R3 produced
by an older weight version.
Validation
Current unit and static checks
Run against the exact tree in commit
8d38626b00:Results:
git diff --check: passed.98 passed, with only pre-existing/dependency warnings.GPU E2E status
Earlier TP1/nightly numbers were removed from this description because that
container had received a whole-source overlay on top of a different nightly
build; its Python/native-extension provenance was not trustworthy. They are
not evidence for this commit.
Clean GPU revalidation is in progress under
vllm-agent-infrawith a dedicatedSLURM claim, task-specific container, and path-identical bind mount of this
worktree. No editable install and no container-source overwrite will be used.
The following runtime matrix remains required before this draft can be marked
ready:
kv_role=kv_bothCPU KV offload compatibility;Compatibility represented by this PR
partial keys, weight-version isolation, logical request buffering, terminal
ACK/materialization, frontend stop clipping, config validation, and TP-rank
ownership construction.
MRV2, TP1/TP2, asynchronous scheduling, MTP, prefix caching, SHM, and
kv_role=kv_bothCPU KV offload.cross-node Artifact storage, and MRV1 Artifact mode.
Duplicate-work and AI assistance
Upstream open-PR searches found no implementation of this immutable logical R3
Artifact Connector. vllm-project/vllm#45635
and PR12 provide the capture/offload baseline; they do not provide this key
space, store boundary, fail-closed prefix semantics, or terminal Artifact ACK
path. This draft supersedes #4 because its cache and lifecycle contracts are
materially different.
AI assistance was used for implementation, simplification, testing, and PR
documentation. The human submitter must review every changed line, rerun the
remaining compatibility matrix, and be able to defend the design end to end
before marking this draft ready.