Spaces:
Running
feat(v0.4.1): integrate Hagedorn safety + phase class + nearest-constant in profile_model
Browse filesprofile_model() now returns a `v04_diagnostics` block with:
- hagedorn_safety: red/orange/green badge + message + panel-fraction
(paper 2 §4.2 finding F12 — 36% LLMs in critical zone)
- bimodal_phase_class: Phase A / boundary / Hagedorn zone label
(paper 2 §4 finding F11 — bimodal γ_text density)
- nearest_famous_constants: hits within ±0.02 of γ
(paper 2 §6 finding F13 — discrete attractors, e.g. 1−1/φ)
- imprint_predicted_shift: γ_random predicted via ν=−1/(2π)
- compute_invariant K + in-distribution flag
key_numbers block also adds:
- gamma_random_predicted (X-21 prediction)
- compute_invariant_K (X-22 calculation)
- K_in_distribution flag
New helper functions:
- hagedorn_safety_alert(gamma) — categorize γ into safety zones
- bimodal_phase_class(gamma) — Phase A / boundary / Hagedorn label
- nearest_famous_constant(gamma, ...) — convenience wrapper
These power the upcoming v0.5 phase-diagram visual + Hagedorn red-badge UI.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- python/taf_browser.py +106 -0
|
@@ -951,6 +951,94 @@ def _phase_label(g):
|
|
| 951 |
return "Phase B / catastrophic (negative γ — T too large for θ)"
|
| 952 |
|
| 953 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 954 |
# ════════════════════════════════════════════════════════════════════════════
|
| 955 |
# Recipe registry
|
| 956 |
# ════════════════════════════════════════════════════════════════════════════
|
|
@@ -1211,6 +1299,14 @@ def profile_model(theta, T_train, n_attention_heads, n_kv_heads, d_head,
|
|
| 1211 |
falsifications.append({"id": "F11", "claim": "SWA Δγ > +0.3 (gemma signature)",
|
| 1212 |
"status": "✅ in scope"})
|
| 1213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1214 |
return {
|
| 1215 |
"model_summary": {
|
| 1216 |
"architecture_class": arch_class,
|
|
@@ -1230,6 +1326,16 @@ def profile_model(theta, T_train, n_attention_heads, n_kv_heads, d_head,
|
|
| 1230 |
"chi_susceptibility": chi,
|
| 1231 |
"kv_memory_per_request_GB": kv_cache_memory(n_layers, n_kv_heads,
|
| 1232 |
d_head, T_eval)["GB"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1233 |
},
|
| 1234 |
"recipes": {
|
| 1235 |
rid: {
|
|
|
|
| 951 |
return "Phase B / catastrophic (negative γ — T too large for θ)"
|
| 952 |
|
| 953 |
|
| 954 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 955 |
+
# §32 — Sesión 29 visual-diagnostic helpers (paper 2 §4 bimodal + Hagedorn)
|
| 956 |
+
# ════════════════════════════════════════════════════════════════════════════
|
| 957 |
+
def hagedorn_safety_alert(gamma: float) -> dict:
|
| 958 |
+
"""§32.1 — Classify γ into safety zones (paper 2 §4.2 finding F12).
|
| 959 |
+
|
| 960 |
+
Empirical n=25 panel: 36% of LLMs operate at γ ≥ 0.95 (Hagedorn-zone risk).
|
| 961 |
+
Models at γ ≥ 1.0 cannot serve long context without NTK extension.
|
| 962 |
+
"""
|
| 963 |
+
if gamma is None or not isinstance(gamma, (int, float)):
|
| 964 |
+
return {"level": "unknown", "color": "gray", "message": "no γ available"}
|
| 965 |
+
if gamma >= 1.0:
|
| 966 |
+
return {
|
| 967 |
+
"level": "critical",
|
| 968 |
+
"color": "red",
|
| 969 |
+
"label": "🔴 HAGEDORN ZONE",
|
| 970 |
+
"message": ("γ ≥ 1.0: attention concentrates locally. Long-context "
|
| 971 |
+
"retrieval will FAIL without NTK extension (α_opt > 1)."),
|
| 972 |
+
"fraction_of_panel": "36% of n=25 LLMs are in this zone",
|
| 973 |
+
}
|
| 974 |
+
if gamma >= 0.95:
|
| 975 |
+
return {
|
| 976 |
+
"level": "warning",
|
| 977 |
+
"color": "orange",
|
| 978 |
+
"label": "🟠 HAGEDORN BOUNDARY",
|
| 979 |
+
"message": ("γ ≥ 0.95: at the edge. Long context above T_train risky. "
|
| 980 |
+
"Run X-2 long-context viability before deploying."),
|
| 981 |
+
"fraction_of_panel": "~24% of n=25 LLMs cluster here",
|
| 982 |
+
}
|
| 983 |
+
if gamma >= 0.65:
|
| 984 |
+
return {
|
| 985 |
+
"level": "ok",
|
| 986 |
+
"color": "green",
|
| 987 |
+
"label": "🟢 PHASE A NORMAL",
|
| 988 |
+
"message": ("γ ∈ [0.65, 0.95]: long-context OK. KV compression via "
|
| 989 |
+
"D_f window applicable in [0.65, 0.85]."),
|
| 990 |
+
"fraction_of_panel": "~40% of n=25 LLMs",
|
| 991 |
+
}
|
| 992 |
+
if gamma > 0:
|
| 993 |
+
return {
|
| 994 |
+
"level": "info",
|
| 995 |
+
"color": "blue",
|
| 996 |
+
"label": "🔵 PHASE A WIDE-FIELD",
|
| 997 |
+
"message": ("γ < 0.65: very long-range attention. Model may be over-"
|
| 998 |
+
"trained on long context, or pre-IH (small model)."),
|
| 999 |
+
"fraction_of_panel": "~12% of n=25 LLMs (mostly small or anomalous)",
|
| 1000 |
+
}
|
| 1001 |
+
return {
|
| 1002 |
+
"level": "catastrophic",
|
| 1003 |
+
"color": "darkred",
|
| 1004 |
+
"label": "❌ NEGATIVE γ",
|
| 1005 |
+
"message": "Negative γ means T_eval >> θ. Bad operating point. Use lower T or higher θ.",
|
| 1006 |
+
"fraction_of_panel": "0% of n=25 (pathological)",
|
| 1007 |
+
}
|
| 1008 |
+
|
| 1009 |
+
|
| 1010 |
+
def bimodal_phase_class(gamma: float) -> str:
|
| 1011 |
+
"""§32.2 — Bimodal classifier (paper 2 §4 finding F11).
|
| 1012 |
+
|
| 1013 |
+
γ_text panel n=25 shows 2 density peaks (~0.75 + ~1.0) with gap 0.85-0.95.
|
| 1014 |
+
Hartigan dip test pending (paper 2 Tier-A E3).
|
| 1015 |
+
"""
|
| 1016 |
+
if gamma is None:
|
| 1017 |
+
return "unknown"
|
| 1018 |
+
if gamma < 0:
|
| 1019 |
+
return "catastrophic"
|
| 1020 |
+
if gamma < 0.85:
|
| 1021 |
+
return "Phase A (long-range)"
|
| 1022 |
+
if gamma < 0.95:
|
| 1023 |
+
return "boundary (gap zone)"
|
| 1024 |
+
if gamma < 1.0:
|
| 1025 |
+
return "Hagedorn boundary"
|
| 1026 |
+
return "Hagedorn zone"
|
| 1027 |
+
|
| 1028 |
+
|
| 1029 |
+
def nearest_famous_constant(gamma: float, max_results: int = 3,
|
| 1030 |
+
tolerance: float = 0.05) -> list:
|
| 1031 |
+
"""§32.3 — Convenience wrapper: find named constants near γ.
|
| 1032 |
+
|
| 1033 |
+
Wraps famous_constant_proximity(); always returns a list (possibly empty).
|
| 1034 |
+
Useful for displaying "your γ is close to <constant>" in UI.
|
| 1035 |
+
"""
|
| 1036 |
+
if gamma is None:
|
| 1037 |
+
return []
|
| 1038 |
+
out = famous_constant_proximity(gamma, tolerance=tolerance)
|
| 1039 |
+
return out.get("hits", [])[:max_results]
|
| 1040 |
+
|
| 1041 |
+
|
| 1042 |
# ════════════════════════════════════════════════════════════════════════════
|
| 1043 |
# Recipe registry
|
| 1044 |
# ════════════════════════════════════════════════════════════════════════════
|
|
|
|
| 1299 |
falsifications.append({"id": "F11", "claim": "SWA Δγ > +0.3 (gemma signature)",
|
| 1300 |
"status": "✅ in scope"})
|
| 1301 |
|
| 1302 |
+
# Sesión 29 / paper 2 visual diagnostics
|
| 1303 |
+
safety = hagedorn_safety_alert(g_corr)
|
| 1304 |
+
phase_cls = bimodal_phase_class(g_corr)
|
| 1305 |
+
constants = nearest_famous_constant(g_corr, max_results=2, tolerance=0.02)
|
| 1306 |
+
n_params_M = n_params / 1e6
|
| 1307 |
+
gamma_random_pred = gamma_random_predict(theta, T_eval, n_params_M)
|
| 1308 |
+
K_inv = compute_invariant_K(g_corr, n_params_M)
|
| 1309 |
+
|
| 1310 |
return {
|
| 1311 |
"model_summary": {
|
| 1312 |
"architecture_class": arch_class,
|
|
|
|
| 1326 |
"chi_susceptibility": chi,
|
| 1327 |
"kv_memory_per_request_GB": kv_cache_memory(n_layers, n_kv_heads,
|
| 1328 |
d_head, T_eval)["GB"],
|
| 1329 |
+
"gamma_random_predicted": gamma_random_pred,
|
| 1330 |
+
"compute_invariant_K": K_inv["K"],
|
| 1331 |
+
"K_in_distribution": K_inv["in_distribution"],
|
| 1332 |
+
},
|
| 1333 |
+
"v04_diagnostics": {
|
| 1334 |
+
"hagedorn_safety": safety,
|
| 1335 |
+
"bimodal_phase_class": phase_cls,
|
| 1336 |
+
"nearest_famous_constants": constants,
|
| 1337 |
+
"imprint_predicted_shift": gamma_random_pred - g_pade,
|
| 1338 |
+
"compute_invariant": K_inv,
|
| 1339 |
},
|
| 1340 |
"recipes": {
|
| 1341 |
rid: {
|