[Bug Report] FactoredMatrix SVD, composition scores and SVDInterpreter fail on bf16/fp16 bridges
メンテナーはふだん 1 日以内に返信
@tivris がすでに取り組んでいます。
2026年10月20日 から。
評価
この issue はまだ評価されていません。
説明
Describe the bug
On a bf16 or fp16 bridge, FactoredMatrix.svd() fails, because torch.linalg.svd does not support these dtypes. This affects .S, .U, .V, .norm(), .make_even(), collapse_l() and collapse_r() on OV and QK, all_composition_scores(), and SVDInterpreter.get_singular_vectors(). eigenvalues on the same matrices works, since it casts 16-bit inputs to float32 first (#1155).
Code example
import torch
from transformer_lens import SVDInterpreter
from transformer_lens.model_bridge import TransformerBridge
bridge = TransformerBridge.boot_transformers("roneneldan/TinyStories-1M", device="cpu", dtype=torch.bfloat16)
bridge.OV[0, 0].eigenvalues # works
bridge.OV[0, 0].S
# NotImplementedError: "linalg_svd_cpu" not implemented for 'BFloat16'
bridge.all_composition_scores("Q") # same error
SVDInterpreter(bridge).get_singular_vectors("w_in", layer_index=0) # same error
fp16 fails the same way ('Half'). On a float64 bridge, SVDInterpreter.get_singular_vectors() fails differently: RuntimeError: expected m1 and m2 to have the same dtype, but got: float != double.
System Info
- Source checkout installed with
uv,devat2ad49297. - macOS 27.2, Apple M5; Python 3.12.14; PyTorch 2.11.0; transformers 5.13.0; CPU.
Additional context
FactoredMatrix._svd_cached passes self.A and self.B to torch.linalg.svd in their stored dtype (transformer_lens/FactoredMatrix.py:228-229). eigenvalues casts bf16/fp16 to float32 before torch.linalg.eig (:281-283). SVDInterpreter runs torch.linalg.svd on the raw w_in and w_out matrices (transformer_lens/SVDInterpreter.py:105, :109), and its readout casts the singular vector with .float() but not the unembedding (:126), which also breaks float64.
Proposed fix: cast 16-bit factors to float32 in _svd_cached, as eigenvalues does; do the same for the two SVDInterpreter SVDs; and compute the readout in the singular vectors' dtype without changing stored weights.
Checklist
- I have checked that there is no similar issue in the repo.
- 主要言語
- Python
- スター
- 3.9k
- フォーク
- 708
- 平均マージ
- 2日 3時間
- マージ済み PR(30日)
- 88
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TransformerLensOrg/TransformerLens のほかの issue
-
[Bug Report] `boot_transformers(hf_model=...)` without `device=` can record the wrong `cfg.device`オープン
TransformerLensOrg/TransformerLens#1945 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
TransformerLensOrg/TransformerLens#1939 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Proposal] Whisper adapter for TransformerBridge対応中かも @dipo101 が 2 日前に担当しました。 オープンcomplexity-moderate new-architecture TransformerBridge
TransformerLensOrg/TransformerLens#1938 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Bug Report] Granite MoE Hybrid grouped experts produce incorrect or unstable outputs on MPS対応中かも @janmenjayap が 12 日前に担当しました。 オープンbug complexity-simple TransformerBridge
TransformerLensOrg/TransformerLens#1886 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Community Feedback Requested Research Reproduction seen_by_maintainers TransformerBridge
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
TransformerLensOrg/TransformerLens#1884 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
TransformerLensOrg/TransformerLens の issue をすべて見る
似ている issue
-
Project submission:オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
slavakurilyak/awesome-ai-agents#845 ·
メンテナーはふだん 1 日以内に返信
-
tests: pin that the atomic writers in utils/paths.py stage the temporary file in the target's directory対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンdifficulty:2 enhancement good first issue
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
MakazhanAlpamys/Soup#2178 ·
メンテナーはふだん 1 日以内に返信
-
[BUG] dcg.waggr permutation p-values are folded twice, so near-zero scores get the smallest p-valuesオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
scverse/rapids-singlecell#854 ·
メンテナーはふだん 1 日以内に返信
-
Slang input: int8_t4_packed and uint8_t4_packed are copied into CrossGL対応中かも @ninglinLiu が今日担当しました。 オープンarea:frontend backend:slang bug direction:input
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
random_elements(unique=True) on an OrderedDict: ZeroDivisionError once only zero weights remain, AssertionError with use_weighting=False対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 13 日以内に返信