Refactor: split CheferInterpretable into AttentionInterpretable and GradientInterpretable
I maintainer di solito rispondono entro 3 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Ambito
- machine-learning
Direzione di ricerca
Start with pyhealth/interpret/api.py and inspect the attention-hook implementations in Transformer and StageAttentionNet, along with the AttentionRollout and CheferRelevance checks described in the issue. A linked open pull request (#1232) is already working on this issue. Done means forward-only hooks work without backward hooks, gradient-based interpretation retains gradients, and the CheferInterpretable alias preserves compatibility.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Background
CheferInterpretable (in pyhealth/interpret/api.py) currently bundles two distinct concerns into a single interface:
- Forward attention capture —
set_attention_hooksstores attention weight tensors during the forward pass so they can be retrieved viaget_attention_layers. - Backward gradient capture —
set_attention_hooksalso registers backward hooks so that attention gradients are stored after.backward().
This bundling made sense when CheferRelevance was the only attention-based interpreter (it needs both). But PR #1158 adds AttentionRollout (Abnar & Zuidema 2020), which is gradient-free: it only needs the forward attention maps and explicitly discards attn_grad with for attn_map, _ in layers:. Requiring backward hook registration for a gradient-free method is semantically wrong, even if it works in practice.
Proposed refactor
Split the interface into two levels:
AttentionInterpretable ← forward attention capture only
set_attention_hooks(enabled) (captures attn maps, no backward hooks)
get_attention_layers() (returns attn maps; attn_grad may be None)
get_relevance_tensor(R, **data)
GradientInterpretable(AttentionInterpretable) ← extends with backward hooks
set_attention_hooks(enabled) (also registers backward hooks)
get_attention_layers() (attn_grad is always populated)
AttentionRolloutchecksisinstance(model, AttentionInterpretable)CheferRelevancechecksisinstance(model, GradientInterpretable)- Keep
CheferInterpretable = GradientInterpretableas a backwards-compatible alias
Impact
- Models (
Transformer,StageAttentionNet) would need to support a "forward-only hooks" mode inset_attention_hooks, so attention maps are captured without registering backward hooks. This would also remove thetorch.no_grad()incompatibility currently documented forAttentionRollout. - No breaking changes to existing callers if the alias is kept.
Context
Surfaced during review of PR #1158. The duck-typing AttentionRollout uses today is a reasonable workaround until this refactor lands.
- Lingua principale
- Python
- Stelle
- 1.7k
- Fork
- 803
- Merge medio
- 5g 20h
- PR unite (30g)
- 56
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la 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 sunlabuiuc/PyHealth
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
sunlabuiuc/PyHealth#1333 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
sunlabuiuc/PyHealth#1297 ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
sunlabuiuc/PyHealth#1295 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
sunlabuiuc/PyHealth#1294 · 1 commento ·
I maintainer di solito rispondono entro 3 giorni
-
Internal transfers are counted as readmissionsForse già presa @thebean27 l’ha presa 21 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
sunlabuiuc/PyHealth#1269 · 3 commenti ·
I maintainer di solito rispondono entro 3 giorni
Tutte le issue di sunlabuiuc/PyHealth
Issue simili
-
fix(ui): serve bundled fonts from the gatewayForse già presa @dkritarth l’ha presa oggi. Apertaagent: in-progress agent: ready P3 type: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
dkritarth/scopewatch#336 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bob
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
khuisman/mcp-gee-sweet#1267 ·
I maintainer di solito rispondono entro 1 giorno
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
open-webui/open-webui#33285 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
tv-list
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
Gathin23/cleanyourtv#2337 ·
I maintainer di solito rispondono entro 1 giorno
-
bug P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno