lietzsche;perron

updated 2026-11-26·6 min read

Overview

Context-budgeted AST subgraph slicing, specificity-damped spectral diffusion, and local Gemma 4 defect localization.

Perron started as a competition entry chasing a graph retrieval trick for small 2B and 4B open-weights code models (Gemma 4 E2B and E4B), until the first clean benchmarks came back and hit the same wall: turns out, graphs don’t help small models. A negative result is a valid finish line, albeit an unsatisfying one, so I kept pushing the draft through ablations to see why graph expansion chokes under 4-bit NF4 VRAM budgets (6698.9 MB on E2B, 9648.4 MB resident on E4B due to unquantized Per-Layer Embeddings).

Pairing memory-mapped CSR diffusion with specificity hub-damping and candidate horizon pruning turns that autopsy into a fast local retriever across 344 held-out SWE-bench Verified tasks (named after Perron-Frobenius / Oskar Perron mostly just for nice math flavor, I guess).

Why Code Graphs Kept Breaking on Small Models

On paper, walking a repository’s call graph sounds like free recall. In practice, running random walks over real Python repos on a single GPU kept breaking in four specific ways:

  • Disconnected components: Real codebases aren’t clean, irreducible Markov chains. Dangling sinks and 14 disconnected components mean the second eigenvalue sits at ∣λ2(M)∣=β=0.85|\lambda_2(M)| = \beta = 0.85 (not 0.450.45, as an early draft assumed), forcing ~86 power iterations to converge. I also tried an Ihara-Bass non-backtracking operator to fix edge bounce, then dropped it pretty fast when it broke probability conservation (sum = 0.6545) on directed graphs and ran 50 to 100x slower.
  • The logging.getLogger sink: Unweighted Personalized PageRank pours probability mass straight into shared utilities (logging.getLogger, utils.check_type), eating up to 90% of top-10 slots and leaving a 0.0% Hub Suppression Index.
  • The class-method shortcut: A lot of what looked like “multi-hop reasoning” was actually (class, method) containment edges, which accounted for 72.99% of 1-hop additions (26.59% of all graph edges) and pointed inside the exact same file 90.74% of the time.
  • Small-model ceilings: Unassisted 2B models lose discrimination once you leave obvious lexical seeds (AUC drops from 0.7966 to 0.6596, below Bamber’s 0.830 break-even line for a 25-item pool). Asking Gemma 4 for listwise JSON rankings didn’t save it either, for JSON syntax collapsed on 90.8% (119/131) of tasks.
Perron architectural overview showing offline CSR multigraph compilation, online specificity-damped sparse power iteration, and Gemma 4 provenance serialization
offline zero-copy csr multigraph compilation and online specificity-damped spectral diffusion feeding gemma 4 localization.

How the Retriever Works

To keep memory under 3 MB and stop utility hubs from flooding the context window, Perron runs five steps straight over memory-mapped .npy arrays:

  1. Memory-Mapped CSR Matrices

    Compile call (0.50), inherit (0.25), import (0.15), and caller (0.10) layers into uncompressed .npy CSR arrays loaded via mmap_mode="r" in under 1.0 ms.

  2. Sharp Softmax Seed Prior

    Map candidate cosine similarities with temperature tau = 0.15 using float64 log-sum-exp normalization to build a sharp query teleport vector p_0.

  3. Sparse Personalized PageRank

    Iterate power-method steps with damping beta = 0.85 for 86+ iterations until L1 residual drops below 1e-6.

  4. Specificity Hub-Damping

    Divide query stationary mass by (pi_global(v) + eps)^0.70 while masking test nodes, reaching 99.5% HSI@10 without hard blocklists.

  5. Token-Budgeted AST Packing

    Partition budgets across connected components (up to 3,480 prompt tokens) and pack target-first AST breadcrumbs.

Diffusion & Specificity Equations

Given multiplex edge weights Wuv=0.50Auv(call)+0.25Auv(inherit)+0.15Auv(import)+0.10Auv(caller)W_{uv} = 0.50 A^{(\text{call})}_{uv} + 0.25 A^{(\text{inherit})}_{uv} + 0.15 A^{(\text{import})}_{uv} + 0.10 A^{(\text{caller})}_{uv} and row sums Du=∑vWuvD_u = \sum_v W_{uv}, the sparse iteration and post-walk specificity score are:

π(t+1)=β⋅(π(t)T)+(β⋅(π(t)d)+1−β)⋅p0\boldsymbol{\pi}^{(t+1)} = \beta \cdot (\boldsymbol{\pi}^{(t)} T) + \left(\beta \cdot (\boldsymbol{\pi}^{(t)} \mathbf{d}) + 1 - \beta\right) \cdot \mathbf{p}_0Specificity(v)=πquery(v)(πglobal(v)+ϵ)γ,γ=0.70,  ϵ=10−8\text{Specificity}(v) = \frac{\pi_{\text{query}}(v)}{(\pi_{\text{global}}(v) + \epsilon)^\gamma}, \quad \gamma = 0.70, \; \epsilon = 10^{-8}

Quickstart and MCP Integration

Python API

import perron

result = perron.diffuse_with_provenance(
    query="Fix username validation regex boundary condition",
    repo_path="./my_repo",
    top_k=5,
)
for candidate in result:
    print(f"[{candidate.score:.4f}] {candidate.identifier} ({candidate.call_path})")

MCP Stdio Server

{
  "mcpServers": {
    "perron": {
      "command": "perron-mcp",
      "args": ["--repo", "${workspaceFolder}"]
    }
  }
}

perron/mcp_server.py exposes three JSON-RPC tools: retrieve_context, inspect_symbol_breadcrumbs, and build_code_graph. Cold-starting perron-mcp takes 2.38 s, after which warm CSR queries settle into 1.89 to 5.10 ms.

Hardware Regimes (Where Things Actually Landed)

Across 344 Verified tasks, the hardware ceiling determines which interventions are worth running:

TierHardware EnvelopeKey InterventionEmpirical Outcome
CPU Pre-Filter1.89 to 5.10 ms warm, under 3 MB RAMCSR diffusion (γ=0.70\gamma = 0.70) + selective routing99.5% HSI@10; cuts LLM candidate budget 31.4% at 58.4% recall
Edge (2B)gemma-4-e2b-it (6698.9 MB / 6.7 GB VRAM)Inline provenance comments (E1, thinking off)Lifts reachable Top-1 from 12.07% to 25.86% (p=0.0386p = 0.0386; thinking hurts 2B)
Workstation (4B)gemma-4-e4b-it (9648.4 MB VRAM)Pointwise log-odds on A4[:15] (M=15M=15)22.90% Acc@5, 12.21% Top-1, MRR 0.1740 (beats listwise C1 at 15.27%, p=0.0129p = 0.0129; matches depth BM25 23.66%)
Cluster MoEgemma-4-26b-a4b-it (52.0 GB FP16)Fused 3D expert tensors bypass 2D NF4 hooksExceeds Dual T4 (29.1 GB); sets the commodity GPU boundary
First page of the Perron research monograph showing title, abstract, and empirical summary
monograph page 1 summarizing the empirical audit across 344 swe-bench verified tasks and 27,411 gemma 4 evaluations.

Specification Map

Continue to Repository Map & Modules, Evaluation Metrics, or Hub-Gold & SWE-bench Benchmarks. For dataset provenance and what happened to the preregistered tests, see Dataset Datasheet, Preregistration v1 (Lite), and Preregistration v2 (Verified).

Search wiki and portfolio

type to search across all entries.