[Bug Report] FactoredMatrix SVD, composition scores and SVDInterpreter fail on bf16/fp16 bridges
Maintainer thường phản hồi trong vòng 1 ngày
@tivris đang làm issue này rồi.
Từ ngày 20/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 3.9k
- Fork
- 708
- Merge trung bình
- 1 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 79
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TransformerLensOrg/TransformerLens
-
[Bug Report] `blocks.N.hook_out` never fires on OpenAI GPT because the HF block returns a listĐang mởbug complexity-simple TransformerBridge
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 72/100
TransformerLensOrg/TransformerLens#1969 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement seen_by_maintainers TransformerBridge
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
TransformerLensOrg/TransformerLens#1957 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] KV-group destinations for direct path patching on GQA/MQA modelsCó thể đã có người làm @emerardd đã nhận 4 ngày trước. Đang mởcomplexity-moderate enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1954 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
TransformerLensOrg/TransformerLens#1939 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] Natural Language Autoencoders demo: explain and reconstruct a Qwen activation with TransformerBridgeCó thể đã có người làm @janmenjayap đã nhận 7 ngày trước. Đang mởcomplexity-moderate enhancement Research Reproduction TransformerBridge
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
TransformerLensOrg/TransformerLens#1884 · 5 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TransformerLensOrg/TransformerLens
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
earthtojake/text-to-cad#758 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
domain:upgrades enhancement needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
gke-labs/kube-agents#4634 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
agardnerIT/opamp-server-py#116 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
elviskahoro/sdk-python-attio#144 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày