Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug Report] FactoredMatrix SVD, composition scores and SVDInterpreter fail on bf16/fp16 bridges

Chiusa
#1,918 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

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, dev at 2ad49297.
  • 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

Apri in Codespaces

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TransformerLensOrg/TransformerLens

Tutte le issue di TransformerLensOrg/TransformerLens

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.