Coverage for transformer_lens/tools/analysis/__init__.py: 100%

6 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2026-09-01 16:23 +0000

1"""Analysis tools for TransformerLens. 

2 

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. 

6 

7Tools: 

8 - direct_logit_attribution: Direct Logit Attribution (DLA) over components, 

9 layers, or attention heads. 

10 - direct_path_patching: Direct path patching for head-to-head circuit 

11 analysis. 

12 - jacobian_lens: The Jacobian lens (J-lens) — per-layer causal transport to 

13 the output vocabulary basis, with loading of published lens artifacts, 

14 native fitting, readouts, interventions, and J-space sparse decomposition. 

15 - projection_kernel: Basis-invariant subspace overlap and TransformerBridge 

16 attention-head OQ/OK/OV affinity. 

17""" 

18 

19from transformer_lens.tools.analysis.direct_logit_attribution import ( 

20 DirectLogitAttribution, 

21 direct_logit_attribution, 

22) 

23from transformer_lens.tools.analysis.direct_path_patching import ( 

24 get_act_patch_direct_path, 

25 get_act_patch_direct_path_all_sources, 

26) 

27from transformer_lens.tools.analysis.jacobian_lens import ( 

28 JacobianLens, 

29 JacobianLensReadout, 

30) 

31from transformer_lens.tools.analysis.jacobian_lens_decomposition import ( 

32 JSpaceDecomposition, 

33 JSpaceOccupancy, 

34 JSpaceVarianceProfile, 

35 estimate_occupancy, 

36 get_sparse_decomposition, 

37) 

38from transformer_lens.tools.analysis.projection_kernel import ( 

39 AttentionHeadRef, 

40 HeadAffinityPair, 

41 HeadAffinityResult, 

42 ProjectionKernelResult, 

43 RandomSubspaceReference, 

44 SubspaceBasis, 

45 attention_head_subspace_affinity, 

46 orthonormal_subspace, 

47 projection_kernel, 

48 random_projection_kernel_moments, 

49) 

50 

51__all__ = [ 

52 "AttentionHeadRef", 

53 "DirectLogitAttribution", 

54 "HeadAffinityPair", 

55 "HeadAffinityResult", 

56 "JSpaceDecomposition", 

57 "JSpaceOccupancy", 

58 "JSpaceVarianceProfile", 

59 "JacobianLens", 

60 "JacobianLensReadout", 

61 "ProjectionKernelResult", 

62 "RandomSubspaceReference", 

63 "SubspaceBasis", 

64 "attention_head_subspace_affinity", 

65 "direct_logit_attribution", 

66 "estimate_occupancy", 

67 "get_act_patch_direct_path", 

68 "get_act_patch_direct_path_all_sources", 

69 "get_sparse_decomposition", 

70 "orthonormal_subspace", 

71 "projection_kernel", 

72 "random_projection_kernel_moments", 

73]