segKI: `install_decode_attention` patches non-gated q/k-norm attention (dense Qwen3)

オープン
#9,163 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@shotsan がすでに取り組んでいます。

2026年11月24日 から。

  • #9165 @shotsan による — オープン

評価

難易度
3/5
見積もり時間
半日
初心者へのやさしさ
18/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, pytorch

調査の方向性

Start in install_decode_attention, where the gated [q|gate] check compares q_proj.out_features against head_dim, and compare it with find_glu_segments. The failing test is TestArenaWeightViews::test_glu_only_model_refresh_clears_backend_cat_cache, and _decode_attn_forward assumes Qwen3.5 semantics. Linked PR #9165 is already open against this issue, so check it before starting.

索引モデルが issue の本文から書いたものです。

説明

TestArenaWeightViews::test_glu_only_model_refresh_clears_backend_cat_cache fails on master (039bfc9f3) with AttributeError: 'Qwen3RMSNorm' object has no attribute 'eps'. Earlier PR comments (#9077, #9079, #9127) attributed this to a Transformers API change. That is not the cause: it fails the same way on Transformers 5.17.0.

Root cause

install_decode_attention treats a layer as the gated [q|gate] layout when q_proj.out_features is divisible by 2 * head_dim. Dense Qwen3-0.6B has 16 heads × 128 = 2048 = 2 × 8 × 128, so it passes and is patched as 8 gated heads with a (1+w) q/k norm. It then reaches self.q_norm.eps, but Qwen3RMSNorm stores variance_epsilon. Without that crash the output would be wrong anyway, because the head count, the gate split and the norm scale all differ.

In Transformers 5.17, about 40 attention classes have per-head q_norm/k_norm: Qwen3/MoE/VL, Gemma3/4, GLM4-MoE, OLMo2/3, MiniMax-M2, Exaone4, and others. Any of them with an even head count passes the current check. Only qwen3_5, qwen3_5_moe, qwen3_next and qwen4_exp actually use the gated layout.

Proposed fix

Also require q_proj.out_features == 2 * o_proj.in_features. In the gated layout, o_proj consumes only the attention half; in plain attention the two are equal. Both are per-rank under AutoTP, so the ratio holds there too. With Transformers 5.17 this selects exactly the four gated families above. The check only excludes layers, so currently supported models are unaffected. Locally the segKI kernel suite passes (28/28 on L20), and a CPU test covers both the gated and the dense case.

Question

This is still a structural check. A future model with a 2×-wide q_proj but different semantics (plain w norm, a different gate split) would pass it, while _decode_attn_forward already assumes Qwen3.5 semantics (it imports apply_rotary_pos_emb from qwen3_5). Would you prefer:

  1. the structural check above, consistent with find_glu_segments; or
  2. additionally an explicit allowlist (attention class or config.model_type)?

@delock happy to send the PR either way.

主要言語
Python
スター
43.3k
フォーク
5.1k
平均マージ
5日 10時間
マージ済み PR(30日)
85

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

deepspeedai/DeepSpeed のほかの issue

deepspeedai/DeepSpeed の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。