[Bug Report] Residual-decomposition APIs raise KeyError on SSM / hybrid bridges (Qwen3.5, Mamba-2, NemotronH, GraniteMoeHybrid)
维护者通常 1 天内回复
@SBrouck 已经在做这个了。
开始于 2026年11月5日。
评估
这个 Issue 还没有评估数据。
描述
Describe the bug
On SSM and hybrid bridges, the ActivationCache residual-decomposition APIs raise KeyError on the first block without attention:
| API | Error |
|---|---|
decompose_resid() |
KeyError: 'blocks.0.hook_attn_out' |
decompose_resid(mode="mlp") |
KeyError: 'blocks.0.hook_mlp_out' (Mamba-2, NemotronH, GraniteMoeHybrid) |
compute_head_results(), stack_head_results() |
KeyError: 'blocks.0.attn.hook_z' |
get_full_resid_decomposition() |
KeyError: 'blocks.0.attn.hook_z' |
logit_attrs(cache.decompose_resid(), ...) |
KeyError: 'blocks.0.hook_attn_out' |
Reproduced on Qwen3.5, Mamba-2, NemotronH and GraniteMoeHybrid. accumulated_resid works.
These methods loop over range(n_layers) and assume every block has attn and mlp. Since #1578, gated-delta-net and Mamba blocks intentionally expose their mixer output (linear_attn.hook_out, mixer.hook_out) instead of hook_attn_out, and Mamba / NemotronH blocks have no MLP. The cache APIs were not updated for that.
The fix looks straightforward because the residual stream still decomposes exactly. On Qwen3.5, NemotronH and Mamba-2, resid_post - resid_pre equals the mixer output (attention or SSM) plus mlp_out when present, within ~1e-8.
Code example
import torch
from transformers import AutoTokenizer
from transformer_lens.model_bridge import TransformerBridge
name = "Qwen/Qwen3.5-0.8B"
bridge = TransformerBridge.boot_transformers(name, device="cpu", dtype=torch.float32)
ids = AutoTokenizer.from_pretrained(name)("The capital of Germany is", return_tensors="pt").input_ids
_, cache = bridge.run_with_cache(ids)
cache.accumulated_resid() # OK
cache.decompose_resid() # KeyError: 'blocks.0.hook_attn_out'
cache.stack_head_results() # KeyError: 'blocks.0.attn.hook_z'
The same happens without Hub access on the tiny random fixtures in tests/integration/model_bridge/test_ssm_effective_attention_dispatch.py.
System Info
transformer_lens4.3.0 from PyPI; the code involved is unchanged ondev(837fb72)- macOS (Apple Silicon), CPU, fp32
- Python 3.12, transformers 5.13 and 5.22
Additional context
I have a fix with tests ready and will open a PR against dev. Blocks without attention contribute their mixer output in the attention slot, only attention layers contribute heads, and only blocks with an MLP contribute mlp_out or neurons. All decompositions still sum to the residual stream.
Checklist
- I have checked that there is no similar issue in the repo (required)
- 主要语言
- 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 于 2 天前认领。 未关闭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 今天认领。 未关闭
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 good first issue
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 76/100
graphql-python/graphql-core#304 ·
维护者通常 1 天内回复
-
docs size:S
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
Gathin23/cleanyourtv#3464 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复