Changelog¶
Known issue in releases before 0.2.2¶
Releases 0.1.0 to 0.2.1 computed the layer-level spectrum
(SpectralAnalyzer.compute_eigendecomposition, used by
GSPDiagnosticsFramework) with scipy.linalg.eigh (eigsh on the sparse
path) for every normalization. Under normalization="rw", the default until
0.3.0, the Laplacian I − D⁻¹W is not symmetric: eigh reads only one
triangle of it, so it returned the spectrum of a different, symmetric
matrix, and negative eigenvalues were then clipped to 0. The Fiedler value
and the other metrics computed from that eigendecomposition were wrong,
mostly too low: recomputing the 0.1.2 construction on Phi-3-mini-4k-instruct
gave Fiedler values up to 0.36 below the correct ones (and up to 0.07
above). normalization="sym" and "none" were not affected. 0.2.2
diagonalises non-symmetric Laplacians with a general solver, and 0.3.0 made
"sym" the default. Results computed with 0.1.x, 0.2.0 or 0.2.1 under
normalization="rw" should be recomputed with a current release. The
per-head functions, added in 0.3.0, had a related issue with "rw" that
0.4.0 fixed (see v0.4.0).
v0.5.3 (2026-11-17)¶
Controls and generators for follow-up studies of numerical in-context learning. No result changes for existing calls.
spectral_trust.numeric.dynamics: seeded generators of the sequence families of Bao et al. (2026),periodic(period p),logistic(the logistic map at r, with burn-in) andlorenz(one chosen coordinate, RK4), and of smooth families,sine(a chosen frequency),damped_oscillator(closed form) andpendulum(Stormer-Verlet, symplectic; the energy drift is reported). Each returns aTrajectorywith the raw values and the integers of the000-999format;generate(name, ...)andFAMILIESname them.numeric.token_preserving_shuffle(values, seed): the values in a random order, with the exact multiset of tokens kept.numeric.inventory_covariates: the number of distinct values, the share of values seen before, the entropy of the value distribution and, with a tokenizer, the number of distinct token ids, per sequence, ready as covariates ofst.confound_audit.numeric.rollout(model, tokenizer, values, n_steps, target=...): multi-step extrapolation that feeds back the mode ofnext_value_distribution(or its rounded mean) and reports the absolute and cumulative error per step against the true continuation. The prompt runs once and each step extends its key-value cache, so an edit ofst.edit_with_controlsreaches every step;numeric.RolloutReadoutmakes a rollout that function's readout.- Value-weighted graphs in the numeric diagnostics:
profile_from_outputs(..., edge_weights="value" | "value_per_head", edges=...)builds the graph fromst.value_weighted_attention(the same edges ascompute_spectraunderGSPConfig.edge_weights), andnumeric.profile(model, ids, edge_weights=...)runs the forward pass and the value capture. λ2, HFER and SE matchcompute_spectraon the same inputs;giniandsink_massstill read the attention. profile_from_outputs(..., center=True, center_positions=...): subtracts each layer's mean hidden state (over the value tokens, or every node) before the graph Fourier transform, removing the DC component; an ablation of the authors' updated paper, to be aligned with their code once it is public. Off by default.st.interventions.sink_bias(model, layers, b, hub=0)andIntervention.sink_bias: add the logitbto every query's attention score toward the hub key (default the first real token) at the chosen layers, through eager attention, on the additive mask, so it holds under cached generation and left padding;b = 0installs nothing. Undone on exit like the other interventions.next_value_distribution: the hierarchical readout can start from an existing key-value cache (internal; the same numbers).
v0.5.2 (2026-11-16)¶
A fix for recent transformers releases. No result changes.
numerichierarchical next-value readout: the key-value cache is cropped with a negative length, which everytransformersrelease accepts; recent releases refused the positive length 0.5.1 passed.- Tests: across platforms, the 0.5.0 regression test skips the outputs that depend on the eigenvector basis (Fiedler vector, spectral masses), and the sparse Geometry of Reason case allows for ARPACK's platform differences. Bit-identity is still asserted in the environment that wrote the fixtures.
v0.5.1 (2026-11-16)¶
Directed and value-weighted attention graphs, measure-aware operator spectra, Forman curvature and an LM-Polygraph bridge. No result changes for existing calls: with the new options at their defaults, and without naming the new opt-in metrics, every result is bit-identical to 0.5.0.
- Value-weighted edges (
spectral_trust.value_weighted): the attention output at token i splits into one vector per key token plus the output bias,c_ij = Σ_h a^h_ij W_O^h (g^h_i ⊙ v^h_j), and the edge from j to i is‖c_ij‖(Kobayashi et al. 2020), or one norm per head. New names:value_weighted_attention,capture_attention_values,AttentionValues(contributions,edge_weights,reconstruct),ValueCapture,value_weighted_edgesandattention_contributions. Grouped-query attention, fused projections (GPT-2, Phi-3, GPT-NeoX), value and output biases (the output bias is in no contribution) and the output gates of Qwen3.5 and Qwen3-Next are covered; on hybrid models only the full-attention layers have a graph. The contributions rebuild the attention output to a float32 relative error below 1e-4 on ten layouts. - Directed graphs (
spectral_trust.directed):directed_operator(P = D_out⁻¹ A),directed_total_variation(‖x − P x‖² / ‖x‖², per column withper_column=True), the magnetic Laplacian (magnetic_laplacian,magnetic_spectrum,magnetic_hfer,magnetic_phase), flow-imbalance clustering (hermitian_clustering,flow_imbalance,FlowClusters) andanalyze_directed_layer. The magnetic HFER of a real signal is identical for a graph and its transpose; the directed total variation is not. per_column_metrics(..., operator=P)adds adirected_tvcolumn.GSPConfiggainsedge_weights("attention","value","value_per_head"),graph_direction("symmetric","directed") andmagnetic_q(default 0.25).GraphConstructorgainslayer_graph,directed_operatorandmagnetic_laplacian;EDGE_WEIGHTS,GRAPH_DIRECTIONSandDIRECTED_GRAPH_METRIC_NAMESare exported.SpectralModel.run_with_spectraandcompute_spectra(new argumentedges=) build thegraphnamespace from the options. Directed graphs are measured on the magnetic Laplacian and addgraph.directed_tvand the arraygraph.phase.GSPDiagnosticsFramework, the graph filters and frequency-resolved patching refuse the new options.- New page: Directed and value-weighted graphs.
- Operator spectra (
spectral_trust.operator_spectra): the attention as a mapL²(μ) → L²(π)and its self-adjoint operatorD = Ω_μ⁻¹ Aᵀ Ω_π A, under the pullback measure (πuniform,μ = Aᵀπ;λ₁ = 1on the constant function) or the counting measure (AᵀA), or any pair of measures. New names:attention_operator,operator_spectrum,operator_measures,operator_metrics,participation_ratio(and its centred variant),OperatorSpectrum,OPERATOR_METRIC_NAMES. A key no query attends to has zero mass;Ω_μ⁻¹is then read as a pseudo-inverse, which gives it the eigenvalue 0. Implemented from the equations of Viganò, Melzi and Ovsjanikov (NeurIPS 2026); not checked against official code, which is not released. - The opt-in
operatornamespace ofrun_with_spectraandcompute_spectra(computed only when named inmetrics=):participation_ratio,participation_ratio_centered,contraction(√λ₂) andeigenvalues, per head or per layer, on attention or on the row-normalised value-weighted attention.GSPConfiggainsoperator_measure,operator_headsandoperator_edges;compute_spectragainsoperator_edges=. - Forman curvature (
spectral_trust.forman):forman_curvatureper edge, directed or undirected, with negative-log, attention or unit edge weights;forman_quantilesandforman_node_curvaturesummarise it over tokens or spans. The opt-ingraph.forman_curvature_mean(with the arraygraph.forman_quantiles) measures the layer graph of the graph options;GSPConfiggainsforman_weights. Implemented from the equations of Kim, Lutzeyer and Guo (2026); not checked against official code. - LM-Polygraph bridge (
spectral_trust.integrations.lm_polygraph, optional extrapolygraph):SpectralTrustEstimatorscores any attention metric as a sequence-level LM-Polygraph estimator. The core package never imports lm-polygraph. Tested end to end with lm-polygraph 0.7.0 (its manager, stat calculators and metrics) on GPT-2 and CoQA items. - Fixed: with value-weighted edges, the graph view and the animations
rebuilt the plain attention graph and mixed its eigenpairs with the value
graph's Fiedler vector. A symmetric value-weighted layer graph is now
stored as
graph.adjacencywhen the patterns are kept, and the views use it; a directed layer graph raises a clear error there. - Fixed: headless Chrome, which the animations use for video, refuses to
start its sandbox as root (Colab, most containers). The launcher now
passes
--no-sandboxwhen running as root, or as the environment variableSPECTRAL_TRUST_BROWSER_NO_SANDBOX(1or0) says. GraphConstructor.construct_laplaciandocuments that negative weights are set to zero (signed graphs are not supported yet).- New pages: Operator spectra in the attention geometry; LM-Polygraph bridge. The directed-graphs page gains a Forman curvature section.
Numerical in-context learning, a confound audit and edits with matched controls. No result changes for existing calls.
spectral_trust.numeric: the serialisation of Bao et al. (2026), value token spans, the next-value distribution (restricted softmax or hierarchical digit-wise) and the paper's layer diagnostics with its non-graph controls (profile_from_outputs).st.confound_audit: raw and covariate-adjusted effects of spectral readouts with bootstrap intervals.st.edit_with_controls: a graph filter or band patch next to norm-matched permuted-graph, path-graph, random-subspace and scaling controls.- Use case "Numerical ICL" and notebook
05_numerical_icl.ipynb.
Measures that answer the critiques of spectral attention diagnostics. No
result changes: every 0.5.0 call is bit-identical
(tests/test_regression_050.py).
GSPConfig.subgraph_renormalize: the nodes kept bysubgraph_indicesortoken_spanare renormalised per row before the graph is built (BOS drop as in Bao et al.);graph.drop_and_renormalize.spectral_trust.features:sink_mass,value_norms,value_weighted_sink,effective_rank,attention_covariates; the asymmetryGand conductanceφ̂of Dahlem et al. (asymmetry,capacity_phi,transport_sigma2,transport_operator; from their equations, no released code);geometry_of_reason, the paper's features on the symmetric normalised Laplacian by default;normalization="rw"reproduces its first released run bit for bit.spectral_trust.pseudospectra:sigma_min,pseudospectrum,pseudospectral_radius,pseudospectral_abscissa,kreiss_constant,departure_from_normality,numerical_range,depth_propagator,nonnormality.- Docs: "What a symmetrised spectrum cannot see" and "Baselines".
v0.5.0 (2026-11-15)¶
Interventions: the TransformerLens basics (patching, ablation, steering) on Hugging Face models, and interventions in the graph-spectral domain. No result changes for existing calls.
- New subpackage
spectral_trust.interventionsand context managerst.intervene(model): hook-based edits, all undone on exit (hooks removed, weights restored bit for bit, the attention implementation and any wrappedtransformersfunction put back). It takes aSpectralModelor a plaintransformerscausal LM (GPT-2, Llama, Qwen, Mistral, Gemma, GPT-NeoX and OPT layouts). Interventions on one model may be nested and closed in any order. Positions are absolute, so position-dependent edits agree between cached generation and recomputation. - Public names of
spectral_trust.interventions: - edits:
intervene(alsost.intervene),Intervention(resid,attention,weights,hook,close),ResidSite(add,graph_filter),AttentionSite(ablate,head_outputs,edit_pattern,remove_edges),WeightSite(svd_scale,snr,weight),Edit(remove) andremove_edges_from_pattern; - graph filters:
graph_filter(alsost.graph_filter),FilterSpec,filter_coefficients,filter_response,ideal_response,attention_adjacency,path_adjacency,laplacian,laplacian64,compute_placement,FILTER_KINDS,GRAPH_NAMES,PRECISIONS; - patching:
patch,Patcher,PatchSpec,equal_count_bands(all four also top-level),select_modes,haar_basis,BASES,SITES; - weights:
weight_snr,weight_svd_full(both also top-level),matrix_snr,lowrank_snr,svd_scale_matrix; - warning thresholds:
KEEP_SINK_WARN_FACTOR(10) andGRAPH_FILTER_WARN_RELATIVE_EDIT(0.5). - Graph-frequency steering:
iv.resid(layer).graph_filter(kind, cutoff= | band=, strength=, graph=, causal=)filters the residual stream along the token axis on that layer's head-averaged attention graph (built as the measurements build it), the chain graph, or a given graph:X' = X + s (g(L) X − X). Low-pass, high-pass, band-pass and band-stop responses use the Jackson-damped Chebyshev machinery ofband_energies(no eigendecomposition), computed in float64 by default (on the CPU when the model is on Apple MPS) or in float32 withprecision="float32", faster on GPUs;method="dense"applies the ideal band indicator.causal=Truefilters each position on the graph of its prefix, a lower-triangular operator, so generation with a KV cache matches recomputation, beam search included; a cached step under the symmetric filter raises. - Head ablation (
ablate("zero" | "mean" | "resample")on the per-head outputs; mean and resample take a reference, and resample draws its items once per input, shared by its beams), activation steering (resid(l).add), custom hooks (iv.hook(site, layer, fn)) and attention-pattern edits (edit_pattern; these need transformers 4.48 or later and say so at run time, while the package keeps requiring 4.30). remove_edges(key_mask, keep_sink=True)removes attention edges and renormalises each edited row over its remaining non-sink keys with the first token's entry held fixed;keep_sink=Falserenormalises over every remaining key, the first token included, andrenormalize=Falseonly zeroes. None of the three is a pure edge ablation when the removed edges carry most of a row: holding the sink fixed then multiplies the edges left by a large factor (13 to 181 for the GPT-2 name movers in the IOI use case).- Weight-spectrum steering:
iv.weights(layer, module).svd_scale(alpha, k=)applies the spectral-steering rescalingσ' = σ (1 + α (σ − mean) / std)and warns when a factor turns non-positive. The rebuilt matrix equals spectral-steering's reference code bit for bit; the two give the same model for bias-freenn.Linearprojections (the Llama-familymlp.down_proj), since the reference swaps in a bias-free layer whilesvd_scaleedits the weight in place, keeps the bias and also handles GPT-2'sConv1D. Edits of one matrix stack and can be removed in any order. st.weight_snr(model, layer, module)isσ₁ / median(σ)over the full spectrum (layer=None: every layer).st.weight_snr(W, k)on a tensor and the newst.weight_svd_full(W)are the two functions of the unreleased 0.2.3 branch that spectral-steering's scripts import, so they run on this release.- Activation patching:
st.patch(model, clean, corrupt, site=, layer=, head=, positions=)andst.Patcher, which runs the clean and corrupt inputs once, captures activations as patches need them, batches many patches, and raises if the model changed since the capture. Frequency-resolved patching (band=,basis="clean_attention" | "corrupt_attention" | "path" | "random") takes one band of a token-axis eigenbasis from the clean run; the full band equals plain patching.st.equal_count_bandssplits the modes into equal-count bands. - Warnings:
remove_edgeswithkeep_sink=Truewarns, once per call, when it multiplies the kept non-sink attention of any edited row by more than 10;graph_filteron the residual stream warns, once per call, when its edit exceeds half the residual norm of the edited positions (‖X' − X‖ / ‖X‖ > 0.5).svd_scalewarns when a singular value's factor turns non-positive. - New tutorial: Interventions.
- Use cases (
docs/use-cases/, with scripts and outputs inexamples/use_cases/): edge ablation and the attention sink on GPT-2 IOI, graph-frequency steering against matched controls, frequency-resolved patching on IOI, which words split Phi-3-mini's attention graph, the side effects ofgraph_filteron GPT-2 and Phi-3-mini, and the design of a band-stop injection defence, which has not been run.
v0.4.2¶
Animated views. One call writes a video, a GIF or an interactive page of a
SpectralCache. No computed value changes.
- New
SpectralCache.animate(kind, out, ...)andst.viz.animate(cache, kind, out, ...). The file suffix picks the format:.mp4(H.264),.webm(VP9),.gif, or.html(interactive). - Kinds:
flow: each token is a tube through depth, from layer 0 to the last. Its position at each layer is the attention graph's Fiedler vector (sign-matched from layer to layer) and third eigenvector, its colour is the Fiedler side, and its thickness is the attention it receives.other=outlines the tokens missing from a second prompt, for example an injected instruction. Drawn with three.js; videos are captured frame by frame from the same page in headless Chrome, with no new Python dependency, and fall back to matplotlib when no browser is found.waterfall: the energy share of each graph-frequency mode as 3D ridgelines through depth, with the HFER band marked.compare: two prompts on shared token positions, with the tokens present in only one outlined, and the Fiedler value and HFER of both traced through depth.graph_movie: the circular attention graph morphing through the layers.head_atlas: every head of a layer as small multiples sorted by a per-head metric, sweeping over the layers.embedding3d: tokens in 3D by Laplacian eigenvectors 2 to 4.- Okabe–Ito palette, light and dark themes, and deterministic output for a
fixed
seed. Rendering runs on the CPU, and ffmpeg uses two threads by default (threads=). - The
vizextra adds imageio and imageio-ffmpeg. Interactive plotly pages embed plotly.js when theplotlypackage is installed, and load a pinned CDN copy otherwise. Flow pages embed three.js r160 (MIT; its licence ships with the package). - Docs: an animated gallery page.
v0.4.1¶
A new licence, a per-column metric, parallel layers for the per-head functions, an explicit device for them, and a corrected tolerance statement. No result changes for existing calls.
- (licence change) spectral-trust is released under the Apache License 2.0 from this version, instead of AGPL-3.0-or-later, so it can be used in academic and commercial work, open or closed source. Versions up to 0.4.0 remain under AGPL-3.0-or-later.
- New
per_column_metrics(signals, laplacian, config): energy, smoothness index, spectral entropy and HFER of every column of a signal matrix (one SAE feature, neuron or probe projection per column) from one eigendecomposition. Columnjgets whatanalyze_layerreports forsignals[:, j:j+1]alone. Returns aColumnDiagnostics. per_head_metrics_all_layersandper_head_hybrid_metrics_all_layerstakenum_workers: layers are decomposed at once, each on one CPU thread, with identical results in layer order. At 28 layers, 16 heads and 256 tokens on a 24-thread CPU, 8 workers took the attention metrics from 0.55 s to 0.15 s (3.7x) and the hybrid metrics from 1.30 s to 0.38 s (3.4x).per_head_metricsandper_head_hybrid_metrics(and their_all_layersversions) takedevice. The default stays the CPU, which is faster for many small eigenproblems;"cuda"decomposes on the GPU. They never readGSPConfig.device, and the docstrings now say so (it defaults to"cuda"when one is available, which suggested otherwise).- Per-head calls change only their own thread's count. Each call runs its
eigendecomposition on one intra-op thread and restores the count after.
torch.set_num_threadsalso sets the count that threads created later start with, so in 0.4.0 a thread created during a per-head call started with one thread and kept it, and could leave one thread as the default for the rest of the process. The calls now put that default back at once, from a short-lived helper thread, so threads created meanwhile (including thenum_workersworkers) start at the process default, and the default is unchanged afterwards. The cost is about 0.4 ms per call. - The
per_head_hybrid_metricsdocstring said its values matchanalyze_layeron each head. They agree to float32 rounding: energy and smoothness index to about 1e-6 relative, HFER and spectral entropy, which depend on eigenvectors computed by different float32 solvers (torch and scipy), up to 8e-5 and 1.2e-3 absolute on Qwen3.5-2B attention with one-column signals. Both are equally close to a float64 solve.
v0.4.0¶
A TransformerLens-style API (SpectralModel, SpectralCache), adapters
for TransformerLens, nnsight and Hugging Face outputs, interactive views,
fast diagnostics, a per-head rw fix, and a dense default
solver. Four changes alter results for existing callers; they are marked
(behaviour change). With normalization="sym" and eigen_solver="dense",
and for the per-head attention metrics, 0.4.0 reproduces 0.3.0 to float32
rounding (benchmarks/reproduce_v030.md).
- (behaviour change) Default
eigen_solver"sparse"→"dense", inGSPConfigand in the CLI. Above 50 tokens the sparse default kept 50 of the S modes, sohfer,spectral_entropy,spectral_masses, theeig_*metrics and the length ofeigenvaluescame from a truncated basis (its HFER was 4x to 30x smaller than the full-basis value in the benchmark);fiedler_value,spectral_radiusandconnectivityagree up to the ARPACK tolerance. The sparse solve was also slower than the dense one at every size measured. Callers at 50 tokens or fewer, or who already passedeigen_solver="dense", get the same results. Passeigen_solver="sparse"to reproduce the old default; it still logs the truncation warning. - (behaviour change) The CLI's
--normalizationdefault"rw"→"sym", matchingGSPConfigsince 0.3.0. Pass--normalization rwfor the old CLI results. - (behaviour change)
connectivityis true when the second-smallest Laplacian eigenvalue is at leastmax(1e-6, 16 * sqrt(S) * eps * lambda_max), throughSpectralAnalyzer.zero_eigenvalue_toleranceandis_connected. 0.3.0 counted eigenvalues below a fixed 1e-6 and required exactly one, so float32 noise on the zero mode (1.07e-6 on gpt2 layer 5, and larger on unnormalised"none"graphs) reported connected graphs as disconnected. Float64 results change only where the zero mode itself exceeded 1e-6. For float32 normalised graphs the threshold is at most about 2e-4 at 2048 tokens. - (behaviour change) Hybrid models such as Qwen3.5, which return attention
for their full-attention layers only:
analyze_textnow pairs each attention tensor with the output of its own layer and reports the true layer index, read fromlayer_typesin the model config. 0.3.0 numbered the returned tensors 0, 1, 2, ... and paired tensor i withhidden_states[i + 1], so the hybrid metrics (energy,smoothness_index,spectral_entropy,hfer) used another layer's hidden states. New:GSPConfig.attention_layer_mapandattention_layer_indices. Models that return attention for every layer are unchanged. - High-level API (
model.py,cache.py):SpectralModel.from_pretrainedloads a Hugging Face causal LM with eager attention, or wraps a loaded one (switching it to eager attention), andrun_with_spectra(text_or_list, metrics, layers, heads, token_span, hybrid)returns aSpectralCache. Its keys follow TransformerLens:blocks.{l}.attn.{metric}(one value per head,per_head_metrics),blocks.{l}.resid.{metric}(per-head hybrid metrics) andblocks.{l}.graph.{metric}(analyze_layeron the head-averaged graph ofanalyze_text, which it reproduces exactly). Layer indices are the model's own on hybrid models. Lists of texts run as right-padded batches and equal one-text runs to float32 rounding. The per-head eigendecompositions of several layers share one batched call. The cache haslayer(l).head(h)views,tokens,layers,metric_names,families,to_dataframe()in long format, andsave/SpectralCache.loadto one.npzfile with JSON metadata (no pickle).compute_spectraruns the same computation on any tensors. - Adapters (
interop.py):from_transformer_lensreadsblocks.{l}.attn.hook_patternandblocks.{l}.hook_resid_postfrom anActivationCache(TransformerBridgeorHookedTransformer),from_nnsighttakes attention weights and optionally hidden states saved in an nnsight trace, andfrom_hf_outputsa Hugging Face output; each crops a right-padded batch withattention_mask=. On gpt2 the nnsight and Hugging Face paths equalrun_with_spectra, andTransformerBridge, which computes attention itself, agrees to 1e-4 relative (tests/test_interop.py). New extras[tl]and[nnsight]; the core install imports neither. - Views (
viz.py):graph,heatmapandspectrumrender a cache as self-contained SVG with tooltips and node highlighting, inline in Jupyter and saved as standalone HTML that opens offline;heatmap(..., backend="matplotlib")returns a figure. Alsocache.graph,cache.heatmap,cache.spectrum. New extra[viz]. per_head_metrics(keep_eigenvalues=True)keeps each head's spectrum inPerHeadDiagnostics.eigenvalues.- Documentation site (mkdocs-material, mkdocstrings) with getting started,
concepts, three tutorials and the API reference, built on pull requests and
deployed from
main. Extras[docs]and[dev]. - README: a static hero in light and dark themes and an SVG wordmark, both
generated by
docs/make_assets.py; the animated GIF is removed. - CI: a model-matrix job runs
run_with_spectraon tiny random checkpoints of several architectures, and an interop job runs the adapter tests. - The CLI's
data/probes.jsonis now in the wheel and the sdist (package_dataandMANIFEST.in), sogsp-cli diagnoseworks after a pip install. It was missing from 0.3.0. - Row-anchored energies (
fast.py):row_dirichlet_energy(W, X, rows)androw_value_spread(A, V, rows), batched over heads, in torch on CPU or GPU, with no eigendecomposition. - Exact top-band HFER:
top_band_hfer(L, X)returns the full-basis HFER of a symmetric Laplacian from the topnum_high_modes(S, cutoff_ratio)eigenpairs, equal to the dense path. - Random projection:
GSPConfig.project_dim(defaultNone) andproject_seedapply a seeded Gaussian Johnson-Lindenstrauss map to the signals before the hybrid metrics;gaussian_projectionandjl_projectare public. - Chebyshev band energies:
band_energies(L, X, edges, order)with Jackson-damped filters (ormethod="dense"),band_entropy, andband_filter_responseto read the filters off a spectrum. - Head subsets:
heads=inper_head_metricsandper_head_metrics_all_layers(indices,(layer, head)pairs, or boolean masks),heads_from_scoresfor user-supplied scores, andPerHeadDiagnostics.heads. - Per-head hybrid metrics:
per_head_hybrid_metricsandper_head_hybrid_metrics_all_layers(energy, smoothness, spectral entropy, HFER on each head's full eigenbasis; family "hybrid"), withheads=andproject_dim. - (fix)
per_head_metricswithnormalization="rw"symmetrizedI - D^{-1}Wbefore the eigensolve and so reported the spectrum of a different matrix (λ_max 2.42 against the true 1.58 on a sink-dominated graph). It now reports the rw operator's spectrum. Results with the defaultsymnormalization are unchanged. - (fix) One HFER mode-count rule everywhere:
num_high_modes(n, r) = n - int((1 - r) n), the rulecompute_hferhas always used (it differs fromceil(r n)only by floating-point rounding, never at the default 0.1 below n = 5000).compute_hfer,top_band_hferand the per-head hybrid path all call it, and acutoff_ratiooutside [0, 1] now raisesValueError;compute_hferused to slice with a negative index and return a wrong value. - (fix) Every scalar metric of
SpectralDiagnosticsis a plain Pythonfloat(fiedler_value,spectral_radiusandsmoothness_indexwere numpy scalars), so the fields serialise withjsondirectly. - (fix)
analyze_layeraccepts a one-token graph (itssqueeze()turned a 1 x 1 Laplacian into a 0-d array). - (fix)
band_energiesraisesValueErrorfor a non-symmetric (rw) operator instead of symmetrizing it, and handles an all-zero Laplacian. - (performance) The Dirichlet energy and the smoothness index are
trace-only sums, O(S²d), accumulated in float64; they no longer form the
d x d matrix
X^T L X(O(S d²) time, d² memory) or evaluate the energy twice.analyze_layerprojects the signals onto the eigenbasis once instead of three times (compute_spectral_masses). Energy and smoothness move only by float32 rounding (at most 1.6e-7 relative in the reproduction check). Under each version's defaults,analyze_layeris 2.4x to 25x faster than in 0.3.0 at S = 128 to 2048, and per-head hybrid metrics 6.0x to 67x faster than a 0.3.0 loop over heads (benchmarks/end_to_end.py). - Benchmarks:
benchmarks/fast_vs_dense.py,end_to_end.pyandreproduce_v030.py, with results inbenchmarks/results.mdandbenchmarks/reproduce_v030.md.
v0.3.0¶
First release since 0.2.2. Three of these changes alter results for existing callers; they are marked (behaviour change).
- Per-head spectral diagnostics (
per_head.py):per_head_metrics,per_head_metrics_all_layers,stack_feature_vector,layer_delta_features. One Laplacian per head, five eigenvalue-only metrics from a single batched eigendecomposition, optional token-span restriction, and probe-ready feature vectors plus cross-layer dynamics. - Metric provenance (
METRIC_FAMILIES,SpectralDiagnostics.families): every metric declares whether it is computed from attention weights alone ("attention") or from residual-stream states projected onto the attention eigenbasis ("hybrid"). The energy / smoothness / entropy / HFER metrics are hybrid and must not be reported as attention-only. - New attention-only metrics:
eig_energy,eig_spectral_entropy,eig_hfer— eigenvalue-only counterparts of the hybrid trio. - (behaviour change) Default Laplacian normalization
rw→sym: spectrum in [0, 2] independent of sequence length, and always the deterministic symmetric solver path. Passnormalization="rw"to reproduce pre-0.3.0 numbers. - (behaviour change)
get_fiedler_value: exact dense solve for graphs up to 512 nodes, seeded and null-deflated Lanczos above. Removes an unseeded random Lanczos start (non-deterministic results) and a>1e-6eigenvalue filter that discarded exactly the near-zero λ₂ regime the diagnostic is meant to detect. - (behaviour change) Non-finite attention tensors now raise
NonFiniteAttentionErrorinstead of propagating NaNs. - Documentation rewritten around the metric-family contract; informal terminology removed from CLI output and the demo notebook.
v0.2.x¶
Directed topology metrics, spectral velocity, subgraph isolation, GPU Lanczos, sparse solver optimizations.