Prhub

#24187 [Fix] Qwen3-ASR config: set thinker_config before super().__init__

原始 PR 作者 AgainstEntropy 合并时间 2026-05-12 11:52 文件变更 1 提交数 2 评论 4 代码增减 +1 / -1

执行摘要

修复 Qwen3-ASR 配置初始化顺序崩溃

PR body 指出:Launching any Qwen3-ASR model crashes during config init under huggingface_hub >= 1.12。原因是 huggingface_hub.dataclasses 的 init_with_validate 在 base init 期间运行 validate_token_ids → get_text_config(decoder=True),而 get_text_config 读取 self.thinker_config.text_config,但 self.thinker_config 只在 super().init 返回后才设置。该问题由 #22073 引入,并在 huggingface_hub 1.12+ 后暴露。

值得立即合入。这是一个精确的构造顺序修复,属于经典 Python 初始化陷阱,值得团队在自定义配置类中注意此类依赖顺序。

讨论亮点

无 review 讨论。PR body 中详细说明了崩溃原因和验证方式。

实现拆解

  1. python/sglang/srt/configs/qwen3_asr.pyQwen3ASRConfig.__init__ 中,将 super().__init__(**kwargs) 一行从函数体开头移至末尾。
  2. 这样在调用父类初始化时,self.thinker_config 已经设置完毕(由之前的 if isinstance(thinker_config, dict): self.thinker_config = Qwen3ASRThinkerConfig(...) 等逻辑处理),get_text_config 可以正常访问。
  3. 无其他配置、测试或文档变更,仅一行代码顺序调整。
文件 模块 状态 重要度
python/sglang/srt/configs/qwen3_asr.py 配置层 modified 5.12

关键符号

Qwen3ASRConfig.__init__

关键源码片段

python/sglang/srt/configs/qwen3_asr.py core-logic

唯一变更文件,将 super().__init__ 移到设置 thinker_config 之后,修复初始化崩溃

# 修复前:super().__init__ 在开头,get_text_config 访问 thinker_config 时属性未设置
class Qwen3ASRConfig(PretrainedConfig):
    def __init__(self, thinker_config=None, **kwargs):
        super().__init__(**kwargs) # 此行会触发 validate_token_ids → get_text_config
        if thinker_config is None:
            thinker_config = {}
        if isinstance(thinker_config, dict):
            self.thinker_config = Qwen3ASRThinkerConfig(**thinker_config)
        else:
            self.thinker_config = thinker_config
​
    def get_text_config(self, decoder=False) -> PretrainedConfig:
        return self.thinker_config.text_config # 此时 self.thinker_config 还未定义!
# 修复后:先设置 thinker_config,再调用 super().__init__
class Qwen3ASRConfig(PretrainedConfig):
    def __init__(self, thinker_config=None, **kwargs):
        if thinker_config is None:
            thinker_config = {}
        if isinstance(thinker_config, dict):
            self.thinker_config = Qwen3ASRThinkerConfig(**thinker_config)
        else:
            self.thinker_config = thinker_config # 确保父类验证前属性已就绪
        super().__init__(**kwargs) # 此时 get_text_config 可以正常访问
​
    def get_text_config(self, decoder=False) -> PretrainedConfig:
        return self.thinker_config.text_config

评论区精华

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

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

风险与影响

风险极低。仅一行代码顺序调整,逻辑等价于在父类初始化前准备好依赖属性。对 huggingface_hub < 1.12 的用户无影响,对 >= 1.12 的用户修复了启动崩溃。无回归风险,所有现有测试(如 test/manual/models/test_qwen3_asr.py)已验证通过。

影响范围仅限于 Qwen3-ASR 模型配置初始化。对所有使用 huggingface_hub >= 1.12 启动 Qwen3-ASR 的用户是必要的修复;否则服务器无法启动。影响程度中等(阻止了关键功能)。

依赖升级暴露问题 仅一行变更

关联 Issue

未识别关联 Issue

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

完整报告

参与讨论