Prhub

#25856 Fix attr err

原始 PR 作者 hanwlax 合并时间 2026-05-25 10:26 文件变更 1 提交数 2 评论 3 代码增减 +1 / -0

执行摘要

修复 Qwen3VLMoe encoder_only 模式属性错误

PR body 指出:如果启用 encoder_only 模式,'Qwen3VLMoeForConditionalGeneration' 对象没有 'model' 属性,会抛出 AttributeError。

本次变更是典型的防御性编程修复,变更极小,逻辑清晰,可以快速合入。

讨论亮点

无 review 讨论。

实现拆解

python/sglang/srt/models/qwen3_vl_moe.pyload_weights 方法中,第 238 行的条件判断前增加 hasattr(self, 'model') 检查,确保只有在 self.model 存在时才访问其 start_layer 属性。

文件 模块 状态 重要度
python/sglang/srt/models/qwen3_vl_moe.py 模型加载 modified 4.65

关键符号

load_weights

关键源码片段

python/sglang/srt/models/qwen3_vl_moe.py data-contract

加载权重时缺少对 self.model 存在性的检查,导致 encoder_only 模式 AttributeError。

# python/sglang/srt/models/qwen3_vl_moe.py, load_weights 方法中
# 原代码直接访问 self.model.start_layer,当 encoder_only 模式时 self.model 不存在
# 修复:增加 hasattr(self, "model") 检查
if (
    "visual" not in name
    and layer_id is not None
    and hasattr(self, "model") # 新增防御性检查
    and hasattr(self.model, "start_layer")
    and (
        layer_id < self.model.start_layer
        or layer_id >= self.model.end_layer
    )
):
    continue

评论区精华

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

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

风险与影响

变更极简单(一行),仅增加防御性检查,无引入新风险的可能。但如果存在其他路径未加类似保护,可能仍有隐患,但本 PR 范围明确。

影响范围限定在 Qwen3VLMoeForConditionalGeneration 模型加载流程,仅修复 encoder_only 模式下的异常情况,对其他模式无影响。

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论