You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TransformerBridgeBug specific to the new TransformerBridge systemcomplexity-moderateModerately complicated issues for people who have intermediate experience with the codeenhancementNew feature or request
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
importtorchfromtransformersimportAutoTokenizerfromtransformer_lens.model_bridgeimportTransformerBridgename="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() # OKcache.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_lens 4.3.0 from PyPI; the code involved is unchanged on dev (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)
Thanks for documenting this and putting together the fix @SBrouck, I just submitted a review on the issue, let me know when you have a moment to review.
TransformerBridgeBug specific to the new TransformerBridge systemcomplexity-moderateModerately complicated issues for people who have intermediate experience with the codeenhancementNew feature or request
Activity
jlarson4 commentedon Nov 5, 2026
Thanks for documenting this and putting together the fix @SBrouck, I just submitted a review on the issue, let me know when you have a moment to review.