Prhub

#25759 [BugFix][EPD]Fix Qwen3VLMoe encoder-only AttributeError

原始 PR 作者 ZhengWG 合并时间 2026-05-21 11:07 文件变更 1 提交数 1 评论 4 代码增减 +1 / -0

执行摘要

修复 EPD 模式下 Qwen3VL MoE 权重加载崩溃

启动 encoder-only EPD 服务器加载 Qwen3VLMoeForConditionalGeneration 权重时崩溃:AttributeError: 'Qwen3VLMoeForConditionalGeneration' object has no attribute 'model'。原因是 encoder_only 模式下父类跳过创建 self.model,而子类 load_weights 直接访问 self.model.start_layer 未做存在性检查。

值得快速合并,修复明确且安全。建议关注 MoE 子类是否还有其他未对齐父类防护的模式,可系统审计 qwen3_vl_moe.py 中其他可能直接访问 self.model 的位置。

讨论亮点

Review 中无实质争议,liusy58 和 ShangmingCai 均直接 approve,gemini-code-assist[bot] 仅简评确认变更安全性。

实现拆解

  1. python/sglang/srt/models/qwen3_vl_moe.pyload_weights 方法中,第 238 行原有条件 hasattr(self.model, "start_layer") 前增加 hasattr(self, "model") 短路保护。
  2. self.model 不存在时(encoder_only 模式),直接跳过依赖 self.model 的 layer 范围过滤逻辑,避免 AttributeError。
  3. 对齐父类 Qwen3VLForConditionalGeneration.load_weights(qwen3_vl.py:1345)已有的相同防护模式。
文件 模块 状态 重要度
python/sglang/srt/models/qwen3_vl_moe.py 模型层 modified 4.39

关键符号

load_weights

关键源码片段

python/sglang/srt/models/qwen3_vl_moe.py bugfix

修复核心文件,单行变更添加 hasattr 短路保护,避免 encoder-only EPD 模式下权重加载 AttributeError。

# python/sglang/srt/models/qwen3_vl_moe.py
# load_weights 方法中的关键条件判断片段(第 235-244 行)
if (
    "visual" not in name
    and layer_id is not None
    # 新增:先确保 self.model 存在,再访问其属性
    # encoder_only 模式下父类不会创建 self.model,没有此检查会触发 AttributeError
    and hasattr(self, "model")
    and hasattr(self.model, "start_layer") # 原检查,仅在 self.model 存在时有效
    and (
        layer_id < self.model.start_layer
        or layer_id >= self.model.end_layer
    )
):
    continue

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

变更仅添加一行 hasattr(self, "model") 短路检查,风险极低。潜在问题是如果 self.model 属性存在但类型异常(如为 None),hasattr 仍返回 True,后续 self.model.start_layer 仍会 AttributeError。但此设计对齐父类已有模式,且该场景在正常 EPD 流程中不应出现。

影响范围高度局限:仅修复 Qwen3VL MoE 模型在 EPD encoder-only 模式下的权重加载崩溃,不涉及推理路径或性能。无用户可见行为变化,系统可用性提升(避免启动失败)。

边缘路径修复 无测试覆盖

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论