[Bug Report] FactoredMatrix SVD, composition scores and SVDInterpreter fail on bf16/fp16 bridges
I maintainer di solito rispondono entro 1 giorno
@tivris ci sta già lavorando.
Dal 20/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 3.9k
- Fork
- 708
- Merge medio
- 1g 23h
- PR unite (30g)
- 88
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TransformerLensOrg/TransformerLens
-
[Bug Report] `success_rate_ci` returns wrong Clopper-Pearson bounds at high success rates or large n (binomial CDF underflows)Forse già presa @bercedev l’ha presa 1 giorno fa. Apertabug complexity-moderate good first issue help wanted TransformerBridge
TransformerLensOrg/TransformerLens#1926 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug Report] Granite MoE Hybrid grouped experts produce incorrect or unstable outputs on MPSForse già presa @janmenjayap l’ha presa 10 giorni fa. Apertabug complexity-simple TransformerBridge
TransformerLensOrg/TransformerLens#1886 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Community Feedback Requested Research Reproduction seen_by_maintainers TransformerBridge
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
TransformerLensOrg/TransformerLens#1884 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Contextual Decomposition: Nonlinear Source Attribution and Dataset-Wide Ranking on GPT-2ApertaCommunity Feedback Requested Research Reproduction seen_by_maintainers
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
TransformerLensOrg/TransformerLens#1883 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Community Feedback Requested enhancement seen_by_maintainers TransformerBridge
Difficoltà 5/5 Più di una settimana Idoneità per principianti 8/100
TransformerLensOrg/TransformerLens#1880 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TransformerLensOrg/TransformerLens
Issue simili
-
[Bug]: Revit selector reads process ids 2000-2099 as years (flaky AgentClientTests.AYearOrAProcessIdSelectsTheHost)Forse già presa @Wurschdhaud l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
pyrevitlabs/pyRevit#3817 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
521xueweihan/HelloGitHub#4074 ·
-
follow-up
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Helm chart: allow setting ingressClassName on the IngressForse già presa @commarla l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
pgadmin-org/pgadmin4#10658 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100