analytical-viz: roofline formula table shows substituted numeric form
Each row in the 'Formulas & interpretation' table now shows both the
symbolic form AND the actual numbers plugged in, on a second line in
the Formula column. Row height bumped to fit two lines. Rendering:
AI: C / W
= 8.00e+12 / 2.56e+11
= 31.25 FLOPs/byte
L*: 2 · N_active · W / (C · kv_bpt)
= 2 · 6.98e+09 · 2.56e+11 / (8.00e+12 · 131,072)
= 3,407 tokens
B_knee: B* / (1 - S_kv/L*)
= 31 / (1 - 8,192/3,407)
= 31 / (1 - 2.404) [<= 0 -> no knee]
Makes the derivation traceable at a glance without needing to plug the
numbers back into the abstract formula. Purely a display change; no
runtime behavior shifts, all 57 tests still pass.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2320,33 +2320,68 @@ with tab_roofline:
|
||||
|
||||
# ── Interpretation table ───────────────────────────────────────
|
||||
st.markdown("**Formulas & interpretation**")
|
||||
# Pre-compute substituted-value strings so each row shows both the
|
||||
# symbolic form and the actual numbers plugged in.
|
||||
_C = _default_machine.peak_flops # FLOPs / s
|
||||
_W = _default_machine.bw_hbm # bytes / s
|
||||
_b_elem = model.bytes_per_elem # bytes / weight
|
||||
_kv_bpt_full = 2 * model.h_kv * model.d_head * model.bytes_per_elem * model.layers
|
||||
|
||||
_sub_ai = (
|
||||
f"= {_C:.2e} / {_W:.2e}\n= {_ai:.2f} FLOPs/byte"
|
||||
)
|
||||
_sub_bstar = (
|
||||
f"= {_C:.2e} · {_b_elem} / (2 · {_W:.2e})\n= {_b_star:.2f}"
|
||||
)
|
||||
if _is_moe:
|
||||
_sub_bmoe = f"= {_b_star:.0f} · 8 (k=8 example)\n= {_b_star * 8:.0f}"
|
||||
else:
|
||||
_sub_bmoe = "N/A (dense preset — sparsity = 1)"
|
||||
_sub_lstar = (
|
||||
f"= 2 · {_n_active:.2e} · {_W:.2e} / ({_C:.2e} · {_kv_bpt_full:,})\n"
|
||||
f"= {_l_star:,.0f} tokens"
|
||||
)
|
||||
_knee_now = knee_batch(_default_machine, model, s_kv)
|
||||
if _knee_now is None:
|
||||
_sub_bknee = (
|
||||
f"= {_b_star:.0f} / (1 − {s_kv:,}/{_l_star:,.0f})\n"
|
||||
f"= {_b_star:.0f} / (1 − {s_kv/_l_star:.3f}) [<= 0 → no knee]"
|
||||
)
|
||||
_bknee_val = "no knee (S_kv ≥ L*)"
|
||||
else:
|
||||
_sub_bknee = (
|
||||
f"= {_b_star:.0f} / (1 − {s_kv:,}/{_l_star:,.0f})\n"
|
||||
f"= {_b_star:.0f} / {1 - s_kv/_l_star:.3f}\n"
|
||||
f"= {_knee_now:.0f}"
|
||||
)
|
||||
_bknee_val = f"{_knee_now:.0f}"
|
||||
|
||||
_formula_rows = [
|
||||
{"Symbol": "AI",
|
||||
"Formula": "C / W",
|
||||
"Formula": "C / W\n" + _sub_ai,
|
||||
"Meaning": "FLOPs per byte of HBM bandwidth. Chip-only.",
|
||||
"Your chip": f"{_ai:.1f}"},
|
||||
{"Symbol": "B*",
|
||||
"Formula": "C · b / (2 · W)",
|
||||
"Formula": "C · b / (2 · W)\n" + _sub_bstar,
|
||||
"Meaning": ("Batch size where weight-fetch time = compute time. "
|
||||
"Below: memory-bound. Above: amortized."),
|
||||
"Your chip": f"{_b_star:.0f}"},
|
||||
{"Symbol": "B*_moe",
|
||||
"Formula": "B* · (N_total / N_active)",
|
||||
"Formula": "B* · (N_total / N_active)\n" + _sub_bmoe,
|
||||
"Meaning": "MoE fetches all experts but computes on active only.",
|
||||
"Your chip": ("N/A (dense preset)" if not _is_moe
|
||||
else f"{_b_star * 8:.0f} (k=8 example)")},
|
||||
{"Symbol": "L*",
|
||||
"Formula": "2 · N_active · W / (C · kv_bpt)",
|
||||
"Formula": "2 · N_active · W / (C · kv_bpt)\n" + _sub_lstar,
|
||||
"Meaning": ("Context where KV-read time = compute time. "
|
||||
"Above: KV-bound regardless of B."),
|
||||
"Your chip": f"{_l_star:,.0f} tok"},
|
||||
{"Symbol": "B_knee",
|
||||
"Formula": "B* / (1 − S_kv/L*)",
|
||||
"Formula": "B* / (1 − S_kv/L*)\n" + _sub_bknee,
|
||||
"Meaning": ("Batch size where cost curve bends onto its floor. "
|
||||
"Diverges at S_kv = L*."),
|
||||
"Your chip": (f"{knee_batch(_default_machine, model, s_kv):.0f}"
|
||||
if knee_batch(_default_machine, model, s_kv) is not None
|
||||
else "no knee (S_kv >= L*)")},
|
||||
"Your chip": _bknee_val},
|
||||
]
|
||||
st.dataframe(pd.DataFrame(_formula_rows),
|
||||
width='stretch', hide_index=True)
|
||||
width='stretch', hide_index=True,
|
||||
row_height=90)
|
||||
|
||||
Reference in New Issue
Block a user