Skip to content

[LoRA] Publish fresh streamed versions alongside generation - #38165

Merged
yushengsu-thu merged 15 commits into
sglang-milesfrom
yusheng/lora-publication-overlap
Sep 9, 2026
Merged

yushengsu-thu merged 15 commits into
sglang-milesfrom
yusheng/lora-publication-overlap

Conversation

@yushengsu-thu

@yushengsu-thu yushengsu-thu commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation and Modification

Scenario: lora_a, lora_b, and lora_c are separate LoRA adapters sharing one base model. A has finished rollout and training; its updated weights will become lora_a@2. lora_b, and lora_c are still generating.

  1. SGLang PR — allow publication alongside generation
    Most important file: tokenizer_control_mixin.py.
    Previously, updates acquired a writer lock while the engine was running, making them mutually exclusive with generation.
    For validated fresh-version publication, the PR selects a reader lock:
# Inside _weight_update_session_call()
if not is_paused:
    lock = (
        self.model_update_lock.reader_lock
        if self._weight_update_new_loras
        else self.model_update_lock.writer_lock
    )
    async with lock:
        results = await communicator(obj)

lora_b, and lora_c generation already uses reader locks, so publication can coexist with it.
Supporting changes make this safe:

  • Register lora_a’s new version with ready=False, blocking premature sampling.
  • Validate session targets, preserve received IPC tensors, and check completeness and TP worker results.
  • Mark the adapter ready only after successful loading.
    _weight_update_new_loras contains validated pending adapters; a session ID alone does not enable this path. Base updates and same-name overwrites retain exclusive locking.

CI States

Latest PR Test (Base): ❌ Run #34296559933
Latest PR Test (Extra): ❌ Run #34296559792
Latest PR Test (AMD ROCm 7.2): ❌ Run #34296560027

@yushengsu-thu
yushengsu-thu force-pushed the yusheng/lora-publication-overlap branch 2 times, most recently from 7fef956 to e3e3861 Compare September 8, 2026 07:20
@github-actions github-actions Bot added quant LLM Quantization dependencies Pull requests that update a dependency file Multi-modal multi-modal language model deepseek hicache Hierarchical Caching for SGLang blackwell SM100/SM120 model-gateway jit-kernel memory-pool labels Sep 8, 2026
@yushengsu-thu
yushengsu-thu force-pushed the yusheng/lora-publication-overlap branch from e3e3861 to 7fef956 Compare September 8, 2026 07:24
A weight-update session may now register adapters with defer_publish: the
backends hold their zeroed identities and stash the streamed tensors as
before, but the names stay out of the serving registry until
end_weight_update commits — so publishing a fresh immutable adapter version
never needs the engine paused. Fresh names only: a published name has
readers and must not be staged over.

- register_lora_adapter gains lora_path: with a disk artifact the adapter is
  reloadable, so it may be LRU-evicted and refilled instead of being
  rejected at the --max-loaded-loras cap.
- end_weight_update gains abort: discard the stash and the deferred
  registrations (base tensors already written in place are not rolled back).
- A deferred publication commits only under a full checksum manifest; a
  session that ends without one is aborted (fail closed).
Generate/embedding requests gain lora_backfill_paths ({lora_name: path}):
when a requested adapter is neither registered nor in the ref cache, the
engine loads it from the carried path instead of rejecting the request.
The request is self-sufficient, so a fresh or restarted engine can serve
any published version without prior state; residency stays engine-managed.
The session stash holds references until end_weight_update applies them,
but a CUDA-IPC sender reuses the shared bucket as soon as the RPC
replies, so stashed tensors from the tensor transport must be copied out
(and the copies synchronized) before the reply.
A staged session (adapter-only, deferred publications pending) touches
nothing a running forward reads: the deferred names are not servable and
base tensors are rejected. Taking the writer lock would serialize the
push against generation for no correctness gain, so begin/bucket/end
select the reader lock for staged sessions; base and fixed-name sessions
keep the writer lock.

The reader lock makes three guards load-bearing: a staged bucket must
not flush caches, abort requests, or move the base weight version; a
pending name cannot be re-registered or unloaded until its session
commits or aborts; and a sample request cannot serve or backfill a name
that a staged session is still streaming.
Multi-line comments cut to the one constraint that makes each line read
right; the mechanism narration they carried is visible in the code.
The two bucket handlers inlined the same pause-aware lock selection that
_weight_update_session_call already implements, and the end handler
duplicated its cleanup across the missing-manifest and normal paths; a
missing manifest is now just a forced abort on the single path. The
staged serving-state guard is one helper.
…mentation

Keeps the prior implementation in history for the record; the tree is
the rewrite: deferred publication held at the tokenizer, reader-lock
staged sessions, request-carried backfill, IPC stash clones, and the
pending ack. Companion to radixark/miles#3127.
@yueming-yuan
yueming-yuan force-pushed the yusheng/lora-publication-overlap branch from f1b2f7d to cfbe52d Compare September 8, 2026 23:17
@yushengsu-thu
yushengsu-thu merged commit 3283911 into sglang-miles Sep 9, 2026
73 of 92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 deepseek dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation hicache Hierarchical Caching for SGLang jit-kernel lora memory-pool model-gateway Multi-modal multi-modal language model quant LLM Quantization run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants