[Bug Report] NormMatchedPlacebo silently loses norm matching and produces float16 NaNs
维护者通常 1 天内回复
评估
调研方向
Start in transformer_lens/tools/analysis/interchange.py at NormMatchedPlacebo.__call__. Reproduce with the provided torch script to see float16 NaNs and zero-projection silence. Edit to preserve zero-reference rows, normalize at safe precision, and raise on zero placebo projection with nonzero reference. Run the focused regression tests (8 failing) until they pass and new identity/error cases hold.
由索引模型根据 Issue 内容生成。
描述
Describe the bug
NormMatchedPlacebo promises to match the reference intervention's displacement in a different subspace, but a zero projection silently produces no displacement in float32 even when the reference moves. In float16, the 1e-8 denominator clamp rounds to zero and produces NaNs, including when source and base are identical. This can occur with the documented random-neuron control excluding the reference neurons, not just a degenerate dense random basis.
Code example
import torch
from transformer_lens.tools.analysis.interchange import (
NormMatchedPlacebo, SubspaceInterchange, neuron_basis, random_neuron_basis,
)
for dtype in (torch.float32, torch.float16):
base = torch.zeros(2, 4, dtype=dtype)
source = base.clone()
source[0, 0] = 2
reference = SubspaceInterchange(neuron_basis(4, [0]))
control_basis = random_neuron_basis(4, 1, seed=0, exclude=[0])
result = NormMatchedPlacebo(reference, control_basis)(base, source)
print(dtype, (reference(base, source) - base).norm(dim=-1), result)
The reference displacement norms are [2, 0]. Float32 returns two unchanged rows, so the first row is not norm-matched. Float16 returns NaNs in both rows; the second row should simply be an identity control. The current implementation also forms a potentially overflowing low-precision scale factor before multiplying by the direction.
Expected behavior: safely preserve rows with zero reference displacement, normalize nonzero projected directions at safe precision, and explicitly reject a zero placebo projection when the reference displacement is nonzero rather than silently returning an unmatched control. This keeps the existing projected-direction definition without inventing a fallback direction.
System Info
Source checkout at dev commit a7b3213a, Windows, Python 3.12, existing uv project environment, CPU. No model loading or downloads are required. Focused regression tests on this base: 8 failed, 14 passed, 38 deselected, covering float16, bfloat16, float32 and float64. Four failures assert the proposed explicit-error contract; the other four expose current float16 NaNs.
Additional context
The affected implementation is transformer_lens/tools/analysis/interchange.py, NormMatchedPlacebo.__call__. Existing random dense float32 tests cover ordinary nonzero projections, but not the zero-projection or float16 identity cases. This concerns the numerical validity of the control; no pretrained-model accuracy claim is involved.
Checklist
- I have checked that there is no similar issue in the repo.
- 主要语言
- Python
- 星标
- 3.9k
- 派生
- 708
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 87
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TransformerLensOrg/TransformerLens 的其他 Issue
-
[Bug Report] test_faithfulness_recovery_is_graded_not_binary passes or fails on the sign of float32 rounding可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
TransformerLensOrg/TransformerLens#1993 ·
维护者通常 1 天内回复
-
[Bug Report] `TransformerBridge.boot_*` methods are invisible to static type checkers可能已有人在做 @koriyoshi2041 于 3 天前认领。 未关闭bug complexity-simple TransformerBridge
难度 2/5 1-3 小时 新手友好度 76/100
TransformerLensOrg/TransformerLens#1980 ·
维护者通常 1 天内回复
-
[Bug Report] detect_head fails with a list of sequences and a custom tensor detection pattern可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭bug complexity-moderate TransformerBridge
难度 2/5 1-3 小时 新手友好度 76/100
TransformerLensOrg/TransformerLens#1979 ·
维护者通常 1 天内回复
-
[Proposal] MiniCPM adapter (MiniCPMForCausalLM) — I'm working on it可能已有人在做 @pablocs116 于 2 天前认领。 未关闭
TransformerLensOrg/TransformerLens#1992 · 1 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
[Proposal] Pretrained J++ lenses through JacobianLens: artifact provenance and filtered readouts未关闭
难度 5/5 一周以上 新手友好度 45/100
TransformerLensOrg/TransformerLens#1991 ·
维护者通常 1 天内回复
查看 TransformerLensOrg/TransformerLens 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
igormcsouza/tether#278 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 91/100
aws-samples/sample-per-model-bedrock#803 ·
维护者通常 1 天内回复
-
documentation p1
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
huggingface/accelerate#4511 ·
维护者通常 1 天内回复
-
follow-up
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复