[LoRA] Sentinel-pad token->lora mapping for DP-attention foreign tokens - #28566
Closed
nanjiangwill wants to merge 1 commit into
Closed
[LoRA] Sentinel-pad token->lora mapping for DP-attention foreign tokens#28566nanjiangwill wants to merge 1 commit into
nanjiangwill wants to merge 1 commit into
Conversation
Under DP-attention, the gathered forward batch contains both local and
foreign tokens, but ``seg_indptr`` / ``weight_indices`` cover only local
requests. ``_compute_moe_lora_info`` was either reading garbage memory
(CUDA-kernel path leaves un-segmented positions uninitialized in the
``torch.empty(...)`` buffer) or going out of bounds (Python fallback's
``index_select`` indexes ``weight_indices[num_segments]``).
Fix both paths with the same -1-sentinel convention:
* Pre-fill ``token_lora_mapping`` with -1 before either path runs, so
un-segmented slots stay -1 after the kernel returns.
* In the Python fallback, ``cat`` a -1 entry onto ``weight_indices`` and
pass that to ``index_select`` so the same -1 lands at the foreign
positions.
Foreign-token outputs are discarded by the DP-attention scatter, so
mapping them to -1 ("no LoRA") is the correct local behaviour — it
just stops the kernel from acting on uninitialised data.
Carved out of sgl-project#25141 (the sglang-miles version of this fix lived in
``_compute_token_lora_mapping``, which doesn't exist on main; the
equivalent here is ``_compute_moe_lora_info``).
nanjiangwill
requested review from
Fridge003,
Ying1123,
jybsuper,
lifuhuang and
yushengsu-thu
as code owners
June 17, 2026 21:59
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Contributor
Author
|
not needed anymore |
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.
Summary
Under DP-attention, the gathered forward batch contains both local and foreign tokens, but `seg_indptr` / `weight_indices` cover only the local requests. `_compute_moe_lora_info` in `backend/base_backend.py` currently does one of two wrong things at the foreign positions:
This PR fixes both paths with the same -1-sentinel convention:
Foreign-token LoRA outputs are discarded by the DP-attention scatter anyway, so mapping them to `-1` ("no LoRA") is the correct local behaviour — it just stops the kernel from acting on uninitialised data / out-of-bounds reads.
Context
Carved out of #25141. The sglang-miles version of this fix lives in a helper called `_compute_token_lora_mapping` in `lora_moe_runners.py`; on `main` the equivalent work is done in `_compute_moe_lora_info` here, so this PR ports the same idea to the on-main code path.
Test plan
CI States
Latest PR Test (Base): ❌ Run #27722492929
Latest PR Test (Extra): ❌ Run #27851913609