Skip to content

[KV events] Publish opaque LoRA block IDs and adapter names - #42817

Merged
ShangmingCai merged 11 commits into
mainfrom
kan/lora-kv-events
Oct 14, 2026
Merged

ShangmingCai merged 11 commits into
mainfrom
kan/lora-kv-events

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

LoRA blocks need a public adapter name for prompt lookup and an opaque block ID for stores, parent links, and removals. This adds LoRA support to the default KV-event mode while preserving existing base-model and salt-only events.

Changes

  • Publish BlockStored.lora_name for admitted LoRA requests in both existing event modes. The optional name is appended to the tokenized IPC structs; older senders can omit it and resolve the name from the admitted adapter ID.
  • In default mode, namespace LoRA block IDs by the internal extra_key, including the adapter load's UUID. Two loads of the same public adapter name retain different external IDs. Use the same mix for stored blocks, parent links, and removals.
  • Keep the existing Dynamo-mode block-ID algorithm. Routers derive their own lookup keys from tokens, lora_name, and cache_salt; external IDs do not need to be reproducible from a request.
  • Keep non-LoRA default events byte-identical, including salt-only events and omitted lora_name fields. Tree keys, HiCache storage keys, model execution, and LoRA loading/scheduling are unchanged.
  • Retain selected namespace names for the publisher lifetime. A write-back host store can arrive after the last GPU removal and after the request has finished, so request/block counts alone cannot safely prune identities. The table costs one name entry per selected (adapter load, extra_key) namespace.
  • Both Python and Rust tree paths emit the same default LoRA IDs. Rust event coalescing preserves extra_key boundaries and the Python adapter applies the default mix.

The router follow-up is #42818, which separates external IDs from canonical prompt lookup keys.

Validation

  • Native Rust tree-core tests: 931 passed, 1 ignored.
  • Python CPU checks: 44 radix-cache tests, 35 cache-hash utility tests, 14 unified-cache KV-event tests, and 23 publisher/wire tests passed.
  • All 10 engine-derived prompt lookup parity cases passed, including LoRA, salt, and combined namespaces; the checker also validates opaque LoRA IDs.
  • Black, isort, and diff whitespace checks passed.

Python checks ran on macOS with the production native hash C++ source compiled against the system SHA-256 provider. The Linux-only extension loader was replaced with that compiled module for the checks. Python/Rust binding integration, CUDA HiCache transitions, and serving E2E were not rerun: the GPU devbox was evicted for low ephemeral storage.

Limit

Reloading different weights under the same public adapter name can still credit old blocks until eviction, as in Dynamo/vLLM. Distinct external IDs prevent removals of one load from revoking another; versioned public names are needed to distinguish weights in request lookup.


CI States

Latest PR Test (Base): ❌ Run #38239470723
Latest PR Test (Extra): ❌ Run #38239470805
Latest PR Test (AMD ROCm 10): ❌ Run #38239470773

Kan Wu and others added 4 commits October 11, 2026 22:05
KV events published LoRA blocks with the same hashes as base-model blocks,
so cache-aware routers could not tell them apart. LoRA blocks now publish
the event hash mixed with a seed of the adapter name, and BlockStored
carries lora_name. The name is the only adapter id that is the same on
every worker; the internal lora_id is a per-load uuid4.

Base-model and salt-only events are unchanged. The mix is applied only
when events are emitted; tree keys, storage hashes and LoRA scheduling
are untouched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Append lora_name to the tokenized request structs: they are positional
  msgpack, and the Rust server encodes them by position.
- Register only requests that resolved to an adapter; lora_path="" used to
  name the base namespace and namespace later base-model hashes.
- Keep a name only while a request of its namespace is alive or its
  published blocks are not yet removed, so the table no longer grows with
  every extra_key and adapter reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Rust tree counts a block when its queued event is taken, so pruning
from registration could drop a finished request's name while its store
events were still queued, publishing them without the LoRA namespace.
Prune only in take(), and register only where events are taken: publisher
ranks with a prefix-sharing cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@ShangmingCai ShangmingCai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, let me process #42818

@ShangmingCai

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 12, 2026
@sherlockwu sherlockwu changed the title [KV events] Namespace LoRA block hashes by adapter name [KV events] Publish opaque LoRA block IDs and adapter names Oct 12, 2026
ShangmingCai and others added 3 commits October 12, 2026 16:04
handle_generate_request and handle_embedding_request now call
_record_kv_event_lora_name, which reads kv_events_publisher and
recv_req.lora_name. Two tests drive these handlers on a Scheduler built
with object.__new__, so base-a-test-cpu failed with AttributeError.

Stub the hook next to the _maybe_namespace_elastic_radix_cache stub they
already set, and add lora_name to the TokenizedEmbeddingReqInput fake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Commit 1a2ac97 formatted the evict_device_leaf assert in black's style;
the pinned ruff-format (v0.15.1) wants the message in parentheses instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ShangmingCai

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@ShangmingCai

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@ShangmingCai
ShangmingCai merged commit 010776e into main Oct 14, 2026
430 of 514 checks passed
@ShangmingCai
ShangmingCai deleted the kan/lora-kv-events branch October 14, 2026 14:56
jain-ria added a commit to jain-ria/sglang that referenced this pull request Oct 15, 2026
Two unit tests construct their objects with `__new__` and set only the
attributes they need. Recent main changes read attributes the real
constructors always set but the fakes lacked:

- sgl-project#44326 made `PrefillCudaGraphRunner.can_run_graph` read `max_seq_len`;
  `test_cp_strategy_unit.py`'s runner did not set it.
- sgl-project#42817 made generate-request handling read `kv_events_publisher`;
  `test_request_class_override_points.py`'s fake scheduler (sgl-project#44113) lacked it.

Both failed with AttributeError on main and on every PR running the CPU suite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: jain-ria <[email protected]>
nvpohanh added a commit to weireweire/sglang that referenced this pull request Oct 15, 2026
Resolve the build_fixture signature conflict in
test_unified_radix_cache_unittest.py by keeping both the PR's
swa_max_states_per_path and main's kv_event_lora_names (sgl-project#42817).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants