Coverage for transformer_lens/tools/analysis/__init__.py: 100%
9 statements
« prev ^ index » next coverage.py v7.10.1, created at 2026-09-21 19:27 +0000
« prev ^ index » next coverage.py v7.10.1, created at 2026-09-21 19:27 +0000
1"""Analysis tools for TransformerLens.
3This subpackage collects high-level, single-call interpretability analyses that
4sit on top of the hook/cache system. Model support is documented per tool;
5new analyses may target the ``TransformerBridge`` API exclusively.
7Tools:
8 - attribution_patching: Attribution patching (gradient-linearized activation
9 patching) over residual-stream nodes and edges: typed computational graph,
10 a names-filtered manual-backward gradient cache, and signed node and edge
11 scores (EAP). Integrated gradients (EAP-IG) and ablate-outside faithfulness
12 are not implemented yet.
13 - backward_lens: GPT-2 MLP weight-gradient factors projected into vocabulary
14 space with explicit raw-gradient sign semantics.
15 - direct_logit_attribution: Direct Logit Attribution (DLA) over components,
16 layers, or attention heads.
17 - direct_path_patching: Direct path patching for head-to-head circuit
18 analysis.
19 - jacobian_lens: The Jacobian lens (J-lens) — per-layer causal transport to
20 the output vocabulary basis, with loading of published lens artifacts,
21 native fitting, readouts, interventions, J-space sparse decomposition, and
22 anchored coordinate patching (offline and dynamic/hooked).
23 - projection_kernel: Basis-invariant subspace overlap and TransformerBridge
24 attention-head OQ/OK/OV affinity.
25"""
27from transformer_lens.tools.analysis.attribution_patching import (
28 AttributionResult,
29 EdgeAttributionConfig,
30 Node,
31 attribution_patch,
32)
33from transformer_lens.tools.analysis.backward_lens import (
34 BackwardLens,
35 BackwardLensLayerResult,
36 BackwardLensMatrixResult,
37 BackwardLensResult,
38 LinearGradientFactors,
39 ProjectedFactor,
40 VocabularyRanking,
41 WeightLayout,
42)
43from transformer_lens.tools.analysis.direct_logit_attribution import (
44 DirectLogitAttribution,
45 direct_logit_attribution,
46)
47from transformer_lens.tools.analysis.direct_path_patching import (
48 get_act_patch_direct_path,
49 get_act_patch_direct_path_all_sources,
50)
51from transformer_lens.tools.analysis.jacobian_lens import (
52 JacobianLens,
53 JacobianLensReadout,
54)
55from transformer_lens.tools.analysis.jacobian_lens_coordinate_patch import (
56 CoordinatePatch,
57 solve_coordinate_patch,
58 solve_coordinate_patch_positions,
59)
60from transformer_lens.tools.analysis.jacobian_lens_decomposition import (
61 JSpaceDecomposition,
62 JSpaceOccupancy,
63 JSpaceVarianceProfile,
64 estimate_occupancy,
65 get_sparse_decomposition,
66)
67from transformer_lens.tools.analysis.projection_kernel import (
68 AttentionHeadRef,
69 HeadAffinityPair,
70 HeadAffinityResult,
71 ProjectionKernelResult,
72 RandomSubspaceReference,
73 SubspaceBasis,
74 attention_head_subspace_affinity,
75 orthonormal_subspace,
76 projection_kernel,
77 random_projection_kernel_moments,
78)
80__all__ = [
81 "AttentionHeadRef",
82 "AttributionResult",
83 "BackwardLens",
84 "BackwardLensLayerResult",
85 "BackwardLensMatrixResult",
86 "BackwardLensResult",
87 "CoordinatePatch",
88 "DirectLogitAttribution",
89 "EdgeAttributionConfig",
90 "HeadAffinityPair",
91 "HeadAffinityResult",
92 "JSpaceDecomposition",
93 "JSpaceOccupancy",
94 "JSpaceVarianceProfile",
95 "JacobianLens",
96 "JacobianLensReadout",
97 "LinearGradientFactors",
98 "Node",
99 "ProjectedFactor",
100 "ProjectionKernelResult",
101 "RandomSubspaceReference",
102 "SubspaceBasis",
103 "VocabularyRanking",
104 "WeightLayout",
105 "attention_head_subspace_affinity",
106 "attribution_patch",
107 "direct_logit_attribution",
108 "estimate_occupancy",
109 "get_act_patch_direct_path",
110 "get_act_patch_direct_path_all_sources",
111 "get_sparse_decomposition",
112 "orthonormal_subspace",
113 "projection_kernel",
114 "random_projection_kernel_moments",
115 "solve_coordinate_patch",
116 "solve_coordinate_patch_positions",
117]