[Bug Report] Residual-decomposition APIs raise KeyError on SSM / hybrid bridges (Qwen3.5, Mamba-2, NemotronH, GraniteMoeHybrid)
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
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)
- Lingua principale
- Python
- Stelle
- 3.9k
- Fork
- 708
- Merge medio
- 1g 9h
- PR unite (30g)
- 84
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] `TransformerBridge.boot_*` methods are invisible to static type checkersForse già presa @koriyoshi2041 l’ha presa 1 giorno fa. Apertabug complexity-simple TransformerBridge
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
TransformerLensOrg/TransformerLens#1980 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug Report] detect_head fails with a list of sequences and a custom tensor detection patternForse già presa @koriyoshi2041 l’ha presa 1 giorno fa. Apertabug complexity-moderate TransformerBridge
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
TransformerLensOrg/TransformerLens#1979 ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Demo or helper for statistical audits of activation-patching results on TransformerBridgeApertacomplexity-moderate enhancement TransformerBridge
Difficoltà 5/5 Più di una settimana Idoneità per principianti 28/100
TransformerLensOrg/TransformerLens#1988 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Demo: auditing a published LLM-written weight edit (Weight-Space Programming, Qwen3.5-0.8B loop fix) with TransformerBridgeForse già presa @emerardd l’ha presa 2 giorni fa. Apertacomplexity-moderate demo TransformerBridge
TransformerLensOrg/TransformerLens#1978 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug Report] `blocks.N.hook_out` never fires on OpenAI GPT because the HF block returns a listForse già presa @ska2704 l’ha presa 3 giorni fa. Apertabug complexity-simple TransformerBridge
Difficoltà 3/5 Mezza giornata Idoneità per principianti 72/100
TransformerLensOrg/TransformerLens#1969 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TransformerLensOrg/TransformerLens
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
FinanceFlash/unvibecode#577 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
area/test type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Clodmony/starship-coop#70 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
punitarani/fli#270 ·
-
🐛 Bug 🔔 Pending processing
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
jumpserver/jumpserver#17980 ·
I maintainer di solito rispondono entro 1 giorno
-
community enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno