执行摘要
修复 LoRA 分块请求槽位遗漏
当前 LoRA 准入代码未考虑分块请求,导致分块请求的 LoRA 槽位未被正确标记为已占用,进而可能引发同一 LoRA 被重复调度。
值得阅读以了解 LoRA 调度中的分块请求处理陷阱。虽然代码改动极小,但反映了状态同步容易遗漏的典型场景。
Reviewer Fridge003 对新增的测试文件评论 "No need to add this test",随后作者删除了该测试文件。其他评论均为 CI 重跑命令,未涉及代码逻辑讨论。
当前 LoRA 准入代码未考虑分块请求,导致分块请求的 LoRA 槽位未被正确标记为已占用,进而可能引发同一 LoRA 被重复调度。
值得阅读以了解 LoRA 调度中的分块请求处理陷阱。虽然代码改动极小,但反映了状态同步容易遗漏的典型场景。
Reviewer Fridge003 对新增的测试文件评论 "No need to add this test",随后作者删除了该测试文件。其他评论均为 CI 重跑命令,未涉及代码逻辑讨论。
scheduler.py 的 _get_new_batch_prefill_raw 方法中,LoRA 门控代码只从 self.running_batch.reqs 收集 LoRA ID,忽略了已通过 add_chunked_req 加入 adder.can_run_list 的分块请求。running_loras 集合初始化后,增加一行 running_loras.update(req.lora_id for req in adder.can_run_list),确保分块请求占用的 LoRA 也被计入已占用槽位。python/sglang/srt/managers/scheduler.py,新增 2 行代码(一行注释加一行逻辑)。| 文件 | 模块 | 状态 | 重要度 |
|---|---|---|---|
python/sglang/srt/managers/scheduler.py |
调度器 | modified | 4.53 |
python/sglang/srt/managers/scheduler.py
core-logic
核心修复文件,在 LoRA 门控逻辑中增加了对 adder.can_run_list 中请求的 LoRA ID 的计数。
# In _get_new_batch_prefill_raw method of Scheduler class
if self.enable_lora:
# 从当前运行批次收集 LoRA ID
running_loras = {req.lora_id for req in self.running_batch.reqs}
# 关键修复:加入已在 adder 中的请求(如 chunked requests)的 LoRA ID
running_loras.update(req.lora_id for req in adder.can_run_list)
if self.lora_drainer:
self.lora_drainer.update_draining_state(
self.waiting_queue,
self.running_batch.reqs,
)
# 后续循环使用 running_loras 检查新请求是否可调度
for req in self.waiting_queue:
if self.enable_lora and not self._can_schedule_lora_req(req, running_loras):
continue
# ...
Reviewer Fridge003 评论 "No need to add this test",认为改动较小,无需单独测试文件。
结论:作者删除了测试文件,只保留核心源代码修改。 · 已解决
风险极低。修改仅追加一个集合更新操作,本质是修正计数逻辑,不影响其他代码路径。需确保 adder.can_run_list 中请求的 lora_id 有效,且 set.update 天然去重,不会导致重复计数。
影响范围仅限于使用 LoRA 且启用 chunked prefill 的场景。修复后这些场景下 LoRA 槽位计算正确,避免因计数遗漏导致的调度错误。无需用户配置变更。
当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。
参与讨论