File size: 4,235 Bytes
2eb3475
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Cross-interaction features.

Each module exposes a plain function ``extract_<name>(model, input_ids,
attention_mask, cache, pred_label=None) -> (features, columns)``. The
extractor entry-point dispatches by name.

PHASE_OF[name] tells the orchestrator whether a feature needs gradients
enabled on the forward pass. Phase 3 and 4 features set this to True;
Phase 0/1/2 use the cheap no-grad ``ForwardCache``.
"""
from .lgap     import extract_lgap
from .scibd_1p import extract_scibd_1p
from .rscd     import extract_rscd
from .owps     import extract_owps
from .kcs      import extract_kcs
from .tcvcg    import extract_tcvcg
from .tcvcg_rand import extract_tcvcg_rand
from .scibd_2p import extract_scibd_2p
from .gclp     import extract_gclp
from .jcsi     import extract_jcsi
from .prep     import extract_prep
from .eapt     import extract_eapt
# Sprint 1: PD-on-attention topology features (clean cross-attention)
from .pd_hdg   import extract_pd_hdg
from .pbd      import extract_pbd
from .rpd      import extract_rpd
from .zap      import extract_zap
from .rcp      import extract_rcp
from .hzap     import extract_hzap
from .rzap     import extract_rzap
from .ttp      import extract_ttp
from .aaa      import extract_aaa
from .mhp      import extract_mhp
from .fzp      import extract_fzp
from .cler     import extract_cler
from .idt      import extract_idt
from .rsc      import extract_rsc
from .art      import extract_art
from .clsph    import extract_clsph
from .ctcka    import extract_ctcka
from .ahj      import extract_ahj
from .mwp      import extract_mwp
from .vas      import extract_vas
from .btl      import extract_btl
from .laed     import extract_laed
from .lid      import extract_lid
from .tbz      import extract_tbz


EXTRACTORS = {
    # Phase 0 β€” hook-only
    "lgap":     extract_lgap,
    "scibd_1p": extract_scibd_1p,
    # Phase 1 β€” 1x forward + light post-processing
    "rscd":     extract_rscd,
    "owps":     extract_owps,
    "kcs":      extract_kcs,
    # Phase 2 β€” setup-heavy, cheap inference
    "tcvcg":    extract_tcvcg,
    "tcvcg_rand": extract_tcvcg_rand,
    "scibd_2p": extract_scibd_2p,
    # Phase 3 β€” gradient-based
    "gclp":     extract_gclp,
    "jcsi":     extract_jcsi,
    # Phase 4 β€” expensive
    "prep":     extract_prep,
    "eapt":     extract_eapt,
    # Sprint 1 β€” PD-on-attention (clean topology)
    "pd_hdg":   extract_pd_hdg,
    "pbd":      extract_pbd,
    "rpd":      extract_rpd,
    "zap":      extract_zap,
    "rcp":      extract_rcp,
    # Sprint 1.5 β€” head-axis zigzag (this paper, admissible cross-feature hunt)
    "hzap":     extract_hzap,
    "rzap":     extract_rzap,
    # Token-trajectory persistence (hidden-state substrate)
    "ttp":      extract_ttp,
    "aaa":      extract_aaa,
    "mhp":      extract_mhp,
    "fzp":      extract_fzp,
    # Sprint-2 β€” Tier-A admissible cross-features (this paper).
    "cler":     extract_cler,
    "idt":      extract_idt,
    "rsc":      extract_rsc,
    "art":      extract_art,
    "clsph":    extract_clsph,
    # Sprint-3 β€” cross-substrate (user directive: combine activations + attention)
    "ctcka":    extract_ctcka,
    "ahj":      extract_ahj,
    # Sprint-4 β€” orthogonal substrate cross-features
    "mwp":      extract_mwp,
    "vas":      extract_vas,
    "btl":      extract_btl,
    "laed":     extract_laed,
    "lid":      extract_lid,
    "tbz":      extract_tbz,
}

PHASE_OF = {
    "lgap":     0, "scibd_1p": 0,
    "rscd":     1, "owps":     1, "kcs": 1,
    "tcvcg":    2, "tcvcg_rand": 2, "scibd_2p": 2,
    "gclp":     3, "jcsi":     3,
    "prep":     4, "eapt":     4,
    # Sprint 1 features form a separate phase 5 ("PD-on-attention").
    "pd_hdg":   5, "pbd": 5, "rpd": 5, "zap": 5, "rcp": 5,
    "hzap":     6,
    "rzap":     6,
    "ttp":      6,
    "aaa":      6,
    "mhp":      6,
    "fzp":      7,
    "cler":     7, "idt": 7, "rsc": 7, "art": 7, "clsph": 7,
    "ctcka":    8, "ahj": 8,
    "mwp":      9, "vas": 9,
    "btl":      10,
    "laed":     10,
    "lid":      10,
}

NEEDS_GRADS = {"gclp", "jcsi", "eapt"}    # features that compute their own bwd
NEEDS_NO_CACHE = {"prep"}                  # features that do their own forwards