Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[Bug Report] `get_caching_hooks` fires for alias names in `names_filter` but caches only under the canonical key

Chiusa
#1,857 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

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

bug complexity-moderate TransformerBridge

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, dev at 1012730f.
  • 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_native model.

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

Apri in Codespaces

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TransformerLensOrg/TransformerLens

Tutte le issue di TransformerLensOrg/TransformerLens

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.