Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto Apto para principiantes
#1,913 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
75/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch
Área
backend, testing

Línea de trabajo

Empieza por el bucle de eliminación en transformer_lens/hook_points.py y compara cómo aplica level cuando including_permanent es true o false. Comprueba el contrato de restablecimiento documentado en transformer_lens/model_bridge/bridge_core.py y reproduce los casos de forward, backward y HookedRootModule.reset_hooks descritos en el issue. La tarea estará terminada cuando la limpieza filtrada por nivel elimine los hooks permanentes solo en el nivel seleccionado, mientras que la limpieza no filtrada de hooks permanentes siga eliminando todos los hooks.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Python
Estrellas
3.9k
Forks
708
Merge medio
2 d 4 h
PR fusionados (30 d)
74

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TransformerLensOrg/TransformerLens

Todos los issues de TransformerLensOrg/TransformerLens

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.