[Bug Report] including_permanent=True makes hook cleanup ignore level
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 75/100
Hướng nghiên cứu
Bắt đầu với vòng lặp xóa trong transformer_lens/hook_points.py và so sánh cách nó áp dụng level khi including_permanent là true hoặc false. Kiểm tra hợp đồng reset được ghi lại trong transformer_lens/model_bridge/bridge_core.py và tái hiện các trường hợp forward, backward và HookedRootModule.reset_hooks được mô tả trong issue. Công việc hoàn tất khi thao tác dọn dẹp có lọc theo level chỉ xóa các hook permanent ở level được chọn, còn thao tác dọn dẹp hook permanent không lọc vẫn xóa tất cả hook.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 throughuvwith 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.
- Ngôn ngữ chính
- Python
- Star
- 3.9k
- Fork
- 708
- Merge trung bình
- 2 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 88
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TransformerLensOrg/TransformerLens
-
[Bug Report] `boot_transformers(hf_model=...)` without `device=` can record the wrong `cfg.device`Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 56/100
TransformerLensOrg/TransformerLens#1945 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
TransformerLensOrg/TransformerLens#1939 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Proposal] Whisper adapter for TransformerBridgeCó thể đã có người làm @dipo101 đã nhận 2 ngày trước. Đang mởcomplexity-moderate new-architecture TransformerBridge
TransformerLensOrg/TransformerLens#1938 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug Report] Granite MoE Hybrid grouped experts produce incorrect or unstable outputs on MPSCó thể đã có người làm @janmenjayap đã nhận 13 ngày trước. Đang mởbug complexity-simple TransformerBridge
TransformerLensOrg/TransformerLens#1886 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Community Feedback Requested Research Reproduction seen_by_maintainers TransformerBridge
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
TransformerLensOrg/TransformerLens#1884 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TransformerLensOrg/TransformerLens
Issue tương tự
-
intake mcp-intake needs-ac needs-human-review priority:medium
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Ikalus1988/MisakaNet#3848 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
521xueweihan/HelloGitHub#4105 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
igormcsouza/bookloud#54 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
aws-samples/sample-per-model-bedrock#526 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ok-oldking/ok-wuthering-waves#1802 ·
Maintainer thường phản hồi trong vòng 2 ngày