Skip to main content

Module ttn_profile

Module ttn_profile 

Source
Expand description

TTN (Test-Time Naturalization) analysis pipeline for model layer profiling.

Provides per-layer LoRA rank allocation. Uses a tiered approach:

  • Tier 1: Embedded profiles for known models (zero-cost const lookup) — ranks from ablation perplexity delta (the gold standard).
  • Tier 2: Cached profiles from disk (~1ms file read).
  • Tier 3: Computed profiles — layer type detected from weight-key geometry, every layer assigned a flat unvalidated rank (see [UNVALIDATED_RANK_CAP] / [GDN_LORA_RANK]) that the runtime utilization oracle narrows from. There is no per-layer spectral analysis; a data-calibrated allocator is gated on the rank-proxy spike (#842).

Ported from tnn-transformer-1/src/entropy.py and attention_analysis.py.

Structs§

LayerAnalysis
LayerProfile
RankUtilizationTracker
Rolling-window rank utilization tracker.
UtilizationSummary
Summary statistics for a key’s utilization history.

Enums§

LayerType
RankSignal
Signal for rank adaptation.

Functions§

attention_entropy
Compute Shannon entropy of attention distributions.
attention_sparsity
Compute top-k attention mass fraction (sparsity measure).
compute_layer_profile
Compute a layer profile from weight-key geometry (Tier 3).
delta_rank_utilization
Compute delta rank utilization: how much of allocated rank is actually used.
find_embedded_profile
Registry lookup for embedded profiles. Returns None for unknown models.
get_layer_profile
Get or compute the layer profile for a model.
load_cached_profile
Load cached profile from model directory.
qwen3_5_0_8b_profile
Embedded Tier-1 layer profile for the single ablated hybrid (full-attention
save_cached_profile
Save computed profile to model directory (atomic: tmpfile + rename).