[Bug Report] `get_caching_hooks` fires for alias names in `names_filter` but caches only under the canonical key
I maintainer di solito rispondono entro 1 giorno
@Mudassiruddin7 ci sta già lavorando.
Dal 6/10/2026.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the bug
TransformerBridge.get_caching_hooks(names_filter=<alias name>) matches the alias entry in hook_dict and the hook fires, but save_hook keys the cache by hook.name, which is the canonical name. The returned cache therefore has no entry under the name the caller asked for: names_filter="blocks.0.hook_resid_pre" produces a cache whose only key is blocks.0.hook_in, and cache["blocks.0.hook_resid_pre"] raises KeyError. Because the hook did fire and the cache is non-empty, nothing warns.
run_with_cache with the same filter returns both the canonical key and the alias key (it copies alias entries into the cache after the forward), so the two caching APIs disagree for the same input.
Code example
import torch
from transformer_lens.config import TransformerBridgeConfig
from transformer_lens.model_bridge import TransformerBridge
cfg = TransformerBridgeConfig(
d_model=32, d_head=16, n_heads=2, n_layers=1, n_ctx=8, d_vocab=16,
d_mlp=64, act_fn="gelu", normalization_type="LN", seed=0,
)
bridge = TransformerBridge.boot_native(cfg)
tokens = torch.randint(0, cfg.d_vocab, (1, 6))
alias = "blocks.0.hook_resid_pre"
with torch.no_grad():
_, ref = bridge.run_with_cache(tokens, names_filter=alias)
print(sorted(ref.cache_dict))
cache, fwd_hooks, _ = bridge.get_caching_hooks(names_filter=alias)
with torch.no_grad(), bridge.hooks(fwd_hooks=fwd_hooks):
bridge.forward(tokens)
print(sorted(cache))
cache[alias] # KeyError
Output on dev (1012730f):
['blocks.0.hook_in', 'blocks.0.hook_resid_pre']
['blocks.0.hook_in']
KeyError: 'blocks.0.hook_resid_pre'
System Info
- Source checkout installed with
uv sync,devat1012730f. - macOS (Apple Silicon), CPU only; Python 3.12.12; torch 2.11.0; transformers 5.13.0.
- No model downloads needed: reproduced with a random-init
TransformerBridge.boot_nativemodel.
Additional context
Found while verifying #1856. Note the fix cannot be a post-forward alias pass like run_with_cache's, because get_caching_hooks hands back the live cache dict before the model runs, it needs alias awareness inside save_hook (e.g. also store under the hook point's alias names, or under the filter name that matched).
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 17h
- PR unite (30g)
- 70
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
-
[Proposal] RoBERTa masked-LM adapter for TransformerBridgeForse già presa @Canonik l’ha presa oggi. Apertacomplexity-moderate new-architecture TransformerBridge
TransformerLensOrg/TransformerLens#1870 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Backward Lens: support gated MLP gate/ up/ down gradient factorsForse già presa @janmenjayap l’ha presa 8 giorni fa. Apertacomplexity-moderate enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1832 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] Sparse probing: optional groups argument so rows from one prompt can't straddle the splitForse già presa @lorenzozanee l’ha presa 13 giorni fa. Apertacomplexity-simple enhancement help wanted TransformerBridge
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
TransformerLensOrg/TransformerLens#1813 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug Report] _BLOCK_LIST_ATTRS hardcoded name list silently drops Raven's blocks from composition-score / head-label analysisForse già presa @LightWork666 l’ha presa 17 giorni fa. Apertabug complexity-moderate TransformerBridge
TransformerLensOrg/TransformerLens#1791 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
[Proposal] SVD Circuits: singular-vector decomposition of a head's QK/ OV into causally-validated subfunctionsForse già presa @janmenjayap l’ha presa 29 giorni fa. Apertacomplexity-high enhancement TransformerBridge
TransformerLensOrg/TransformerLens#1767 · 3 commenti · 1 assegnatario ·
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 70/100
NVIDIA/earth2studio#1241 ·
I maintainer di solito rispondono entro 3 giorni
-
docs(types): update the collection binding note now that typed collections shipped in pycubrid 1.9.0Apertadocumentation priority: low size: S
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
cubrid-lab/sqlalchemy-cubrid#768 ·
I maintainer di solito rispondono entro 1 giorno
-
bug help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Broken link in index.rstApertadocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
ansys/pydpf-core#3547 ·
I maintainer di solito rispondono entro 1 giorno
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OktoLabsAI/okto-pulse#114 ·
I maintainer di solito rispondono entro 1 giorno