Prhub

#25856 Fix attr err

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

执行摘要

修复 encoder_only 模式下的 AttributeError

当 Qwen3VL MoE 模型启用 encoder_only 模式时,Qwen3VLMoeForConditionalGeneration 没有 self.model 属性,但 load_weights 方法直接访问 self.model.start_layer,导致 AttributeError: 'Qwen3VLMoeForConditionalGeneration' object has no attribute 'model'。该提交在条件判断中增加 hasattr(self, "model") 检查,避免此错误。

此 PR 为小的 bugfix,逻辑简单且安全。如果团队使用 Qwen3VL MoE 模型的 encoder_only 模式,建议合并;否则可视为常规维护。

讨论亮点

该 PR 的 review 讨论不多,仅有的评论来自 CI 机器人和作者请求批准 CI 运行。没有深入的架构或设计讨论。

实现拆解

  1. python/sglang/srt/models/qwen3_vl_moe.pyload_weights 方法中,找到第 235-244 行的条件判断。
  2. 在现有条件 "visual" not in name and layer_id is not None and hasattr(self.model, "start_layer") 之前增加 hasattr(self, "model") 检查。
  3. 该修改确保只有当 self.model 存在时才继续访问其 start_layer 属性,从而避免在 encoder_only 模式下因缺少 self.model 而引发 AttributeError。
文件 模块 状态 重要度
python/sglang/srt/models/qwen3_vl_moe.py 模型加载 modified 3.99

关键符号

load_weights

关键源码片段

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

修改了 Qwen3VL MoE 模型的权重加载逻辑,添加了 `hasattr` 检查以修复 encoder_only 模式下的 AttributeError。

# python/sglang/srt/models/qwen3_vl_moe.py
# 在 load_weights 方法中,跳过层范围检查的条件增加了 hasattr 保护
if (
    "visual" not in name
    and layer_id is not None
    and hasattr(self, "model") # 新增:避免 encoder_only 模式下 self.model 不存在
    and hasattr(self.model, "start_layer")
    and (
        layer_id < self.model.start_layer
        or layer_id >= self.model.end_layer
    )
):
    continue

评论区精华

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

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

风险与影响

风险较低。修改仅添加了一个属性存在性检查,不影响正常模式下的行为,且逻辑简单。未添加对应的单元测试,但修改本身安全。

影响范围为 Qwen3VL MoE 模型在 encoder_only 模式下的权重加载流程。修复后,该模式下的模型可以正常加载权重而不再崩溃。影响程度较小,仅针对特定模型和特定配置。

缺少测试覆盖

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论