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

[Bug Report] including_permanent=True makes hook cleanup ignore level

Aperta Adatta ai principianti
#1,913 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch
Ambito
backend, testing

Direzione di ricerca

Inizia dal ciclo di rimozione in transformer_lens/hook_points.py e confronta come applica level quando including_permanent è true o false. Controlla il contratto di reset documentato in transformer_lens/model_bridge/bridge_core.py e riproduci i casi di forward, backward e HookedRootModule.reset_hooks descritti nell’issue. Il lavoro è completato quando la pulizia filtrata per livello rimuove gli hook permanenti solo al livello selezionato, mentre la pulizia non filtrata degli hook permanenti continua a rimuovere tutti gli hook.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

On current dev, HookPoint.remove_hooks(including_permanent=True, level=2) removes hooks at every context level, not just level 2. I also reproduced this through HookedRootModule.reset_hooks(including_permanent=True, level=2).

This means clearing one context's permanent hooks can silently remove an unrelated intervention that should remain active for the next forward or backward pass.

The shared removal loop checks level only in the including_permanent=False branch. The documented reset contract says that a supplied level limits removal to hooks registered at that level. I would expect including_permanent=True to include permanent hooks within that selection, rather than discard the selection.

Code example

import torch
from transformer_lens.hook_points import HookPoint

point = HookPoint()
point.add_hook(lambda value, hook: value + 10, is_permanent=True, level=1)
point.add_hook(lambda value, hook: value + 1, is_permanent=True, level=2)

print("before:", point(torch.tensor(0.0)).item())
point.remove_hooks(including_permanent=True, level=2)
print("remaining levels:", [handle.context_level for handle in point.fwd_hooks])
print("after:", point(torch.tensor(0.0)).item())

Actual output:

before: 11.0
remaining levels: []
after: 0.0

Expected: remaining levels: [1] and after: 10.0.

System Info

  • macOS arm64, Python 3.13.16, PyTorch 2.14.1.
  • Unmodified source checkout at 177d2cc10ba479f767df9834d93ea624e7eba521 (dev), run through uv with compatible CPU dependencies. This was not a restored frozen development environment.
  • No model weights or GPU execution are needed for the example.

Additional context

Three focused regression cases fail at the unwanted removal: forward HookPoint cleanup, backward HookPoint cleanup, and HookedRootModule.reset_hooks. Fifteen controls pass, including the existing hook-introspection tests and checks that default cleanup preserves permanent hooks, ordinary level-filtered cleanup preserves other contexts, and an unfiltered permanent reset still removes everything.

These Python-only checks used the repository's coverage-style pytest options, retaining jaxtyping/beartype instrumentation. The stock notebook/doctest plugins and complete development environment were unavailable, and the unchanged source's full typecheck was not clean in the available environment. I have not verified a native TransformerBridge model or prepared a ready code patch.

This concerns explicit level-filtered cleanup, rather than the retained-helper-hook lifecycle addressed by #1908.

Checklist
  • I have checked that there is no similar issue in the repository.
Lingua principale
Python
Stelle
3.9k
Fork
708
Merge medio
2g 4h
PR unite (30g)
74

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.