Skip to content

[LoRA] Support LoRA under DP attention: idle-forward guards, attn-TP-local slicing, per-rank tensor serialization - #31520

Closed
yushengsu-thu wants to merge 6 commits into
mainfrom
yusheng/lora-dp-attention
Closed

yushengsu-thu wants to merge 6 commits into
mainfrom
yusheng/lora-dp-attention

Conversation

@yushengsu-thu

@yushengsu-thu yushengsu-thu commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Goal

Run LoRA under --enable-dp-attention: inference with adapters, and dynamic /load_lora_adapter / /unload_lora_adapter.

Why the current code fails

  • Idle DP forwards (a DP group with zero local tokens) skip prepare_lora_batch(), so LoRA layers read the previous batch's stale metadata and crash.
  • LoRA weight slicing and buffer sizing use the global TP rank/size, but under DP attention the attention layers shard on the attn-TP group (tp_size / dp_size) — slices overshoot and buffer shapes mismatch.
  • The dynamic-LoRA endpoints assert dp_size == 1.

How

  • batch_info = None means "no batch prepared": prepare_lora_batch() resets it on idle forwards (BaseLoRABackend.reset_batch_state()), and every LoRA layer takes the base path via the lora_active property.
  • Slice LoRA weights by base_layer.tp_rank — the rank the wrapped layer was actually built with. The old tp_rank parameter of slice_lora_a/b_weights is removed: it was what made passing the wrong (global) rank possible.
  • Size attention-module LoRA buffers by attn_tp_size (_effective_tp_size()).
  • Relax the asserts to dp_size == 1 or enable_dp_attention.

Ports the DP-attention side of sglang-miles #25141. The tensor-loading (RL) path is split into #32580.

Tests

8x H200, DeepSeek-V2-Lite, synthetic o_proj adapter, greedy:

  • --tp 8 --dp 8 --enable-dp-attention --enable-lora: load / generate with lora_path (7/8 DP ranks idle) / unload all pass; adapter shifts prefill logprobs and base is restored exactly after unload.
  • --tp 8 --dp 2 --enable-dp-attention (attn_tp = 4): buffer-shape asserts pass, LoRA applied correctly.
  • Same --dp 8 launch on main (asserts bypassed) crashes during CUDA-graph capture — the feature is unlocked, not just un-asserted.
  • Unit: test/registered/unit/lora/ 38 passed (incl. new attn-TP shape regressions).

Checklist


CI States

Latest PR Test (Base): 🚫 Run #30313112157
Latest PR Test (Extra): ❌ Run #30313112005

…cal slicing, per-rank tensor serialization

Skip LoRA application on DP-attention idle forwards via a None batch_info
guard in every LoRA-wrapped layer, and clear stale batch info on idle batches.
Slice LoRA A/B weights by the base layer's attn_tp-local rank and size the
memory-pool buffers of attention modules by attn_tp_size.
Relax the dp_size == 1 asserts for dynamic LoRA load/unload when DP attention
is enabled, and ship load_lora_adapter_from_tensors payloads as one serialized
copy per TP rank, mirroring update_weights_from_tensor.
Derive CUDA-graph MoE LoRA buffer dims from the base FusedMoE so all quant
schemes work.

Ported from the sglang-miles branch (original PR #25141).
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added the lora label Jul 17, 2026
@yushengsu-thu yushengsu-thu added the ci continue integration related label Jul 17, 2026
yushengsu-thu added a commit that referenced this pull request Jul 26, 2026
Match update_weights_from_distributed's existing contract (dp_size == 1 or
dp attention enabled): all dp-attention ranks join the weight-update NCCL
group and receive the tokenizer fan-out, so the broadcast load works
unchanged. Verified on the sglang-miles branch by a GLM-5.2 multi-LoRA
e2e (2 engines, dp-attention ep=dp=2): both DP ranks of both engines
receive the initial load and per-step upserts. Serving the adapters under
dp attention additionally requires the dp-attention LoRA support (#31520).
…m forwards, full prefill CG

Fixes for LoRA surfaces that landed on main after this PR's base:
- add qkvr to ATTENTION_LINEAR_LORA_NAMES so its LoRA-B buffer is sized by
  attn_tp_size, matching the attn-TP-sharded InklingQKVRLinear
- slice qkvr LoRA-B by the base layer's attn-TP-local rank, like the other
  slicers
- skip the two-stream LoRA forwards when batch_info is None (idle DP
  forwards); the original forwards carry the guard
- disable full prefill CUDA graph under LoRA: capture runs before any
  prepare_lora_batch, so the recorded graph would silently drop adapter
  deltas on replayed prefill batches
@yushengsu-thu

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

1 similar comment
@yushengsu-thu

Copy link
Copy Markdown
Collaborator Author

/rerun-failed-ci

Keep the DP-attention runtime side: idle-forward guards, attn-TP-local
slicing and buffer shapes, and the path-based dynamic LoRA asserts.
- lora_active property replaces the 11 scattered
  'set_lora and batch_info is not None' guards
- prepare_lora_batch dispatches on forward_mode; idle reset moves onto
  the backend as reset_batch_state() (triton also clears sgemm_batch_info,
  now declared in __init__ instead of reached via getattr)
- _sgemm_info asserts a prepared batch so a layer that forgets the guard
  fails loudly instead of reading stale segments
- drop the dead tp_rank parameter from slice_lora_a/b_weights: slicing
  is by base_layer.tp_rank (attn-TP-local) by design
- delete dead _get_standard_shape and the dead batch_info hasattr
@yushengsu-thu

Copy link
Copy Markdown
Collaborator Author

@Jiminator
Jiminator deleted the yusheng/lora-dp-attention branch September 14, 2026 04:42
@alexnails
alexnails restored the yusheng/lora-dp-attention branch September 14, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci continue integration related lora run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants