Q-TensorFormer / outputs /dashboard.html
Premchandyadav369
docs(metrics): add quantitative percentage improvement breakdown (%) vs baselines and dashboard KPI cards
8cac17f
Raw History Blame Contribute Delete
32 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Q-TensorFormer — Research Visualization & Diagnostics Dashboard</title>
<style>
:root {
--bg: #0b0f19;
--surface: #131b2e;
--surface-border: #202d4a;
--primary: #6366f1;
--primary-glow: rgba(99, 102, 241, 0.3);
--accent-cyan: #06b6d4;
--accent-green: #10b981;
--accent-amber: #f59e0b;
--accent-rose: #f43f5e;
--text-main: #f1f5f9;
--text-muted: #94a3b8;
--font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background-color: var(--bg);
color: var(--text-main);
font-family: var(--font-sans);
line-height: 1.6;
padding: 24px;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 24px;
border-bottom: 1px solid var(--surface-border);
margin-bottom: 32px;
}
.title-block h1 {
font-size: 1.8rem;
font-weight: 700;
background: linear-gradient(135deg, #a5b4fc, #06b6d4);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.title-block p {
color: var(--text-muted);
font-size: 0.95rem;
margin-top: 4px;
}
.badges {
display: flex;
gap: 8px;
}
.kpi-strip {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.kpi-card {
background: var(--surface);
border: 1px solid var(--surface-border);
border-radius: 10px;
padding: 16px;
text-align: center;
position: relative;
overflow: hidden;
}
.kpi-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, var(--accent-cyan), var(--accent-green));
}
.kpi-value {
font-family: var(--font-mono);
font-size: 1.8rem;
font-weight: 700;
color: var(--accent-green);
margin-bottom: 4px;
}
.kpi-label {
font-size: 0.78rem;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
}
.kpi-sub {
font-size: 0.75rem;
color: var(--accent-cyan);
margin-top: 4px;
}
.badge {
background: var(--surface);
border: 1px solid var(--surface-border);
padding: 6px 12px;
border-radius: 9999px;
font-size: 0.8rem;
font-family: var(--font-mono);
color: var(--accent-cyan);
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
gap: 24px;
margin-bottom: 32px;
}
.card {
background: var(--surface);
border: 1px solid var(--surface-border);
border-radius: 12px;
padding: 24px;
position: relative;
overflow: hidden;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
}
.card-title {
font-size: 1.1rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 8px;
}
.card-subtitle {
font-size: 0.85rem;
color: var(--text-muted);
margin-bottom: 16px;
}
/* Token Timeline */
.token-stream {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 16px;
background: #080c14;
padding: 16px;
border-radius: 8px;
border: 1px solid var(--surface-border);
}
.token-chip {
display: flex;
flex-direction: column;
align-items: center;
background: #182238;
border: 1px solid var(--surface-border);
border-radius: 6px;
padding: 6px 10px;
cursor: pointer;
transition: all 0.2s ease;
}
.token-chip:hover, .token-chip.active {
border-color: var(--primary);
box-shadow: 0 0 12px var(--primary-glow);
transform: translateY(-2px);
}
.token-str {
font-family: var(--font-mono);
font-size: 0.95rem;
font-weight: 600;
}
.token-meta {
font-size: 0.7rem;
color: var(--accent-cyan);
margin-top: 2px;
}
.rank-r1 { border-top: 3px solid var(--accent-green); }
.rank-r2 { border-top: 3px solid var(--accent-cyan); }
.rank-r4 { border-top: 3px solid var(--accent-amber); }
.rank-r8 { border-top: 3px solid var(--accent-rose); }
/* Metric Table */
table {
width: 100%;
border-collapse: collapse;
font-size: 0.88rem;
}
th, td {
padding: 10px 12px;
text-align: left;
border-bottom: 1px solid var(--surface-border);
}
th {
color: var(--text-muted);
font-weight: 600;
background: rgba(255, 255, 255, 0.02);
}
.mono { font-family: var(--font-mono); }
.success { color: var(--accent-green); }
.highlight { color: var(--accent-cyan); font-weight: 600; }
/* Sliders */
.slider-group {
margin: 16px 0;
}
.slider-group label {
display: flex;
justify-content: space-between;
font-size: 0.85rem;
color: var(--text-muted);
margin-bottom: 6px;
}
input[type=range] {
width: 100%;
height: 6px;
background: #202d4a;
border-radius: 4px;
outline: none;
-webkit-appearance: none;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: var(--primary);
cursor: pointer;
box-shadow: 0 0 8px var(--primary-glow);
}
/* SVG Plots */
.plot-container {
width: 100%;
height: 220px;
background: #080c14;
border-radius: 8px;
padding: 12px;
border: 1px solid var(--surface-border);
display: flex;
align-items: center;
justify-content: center;
}
svg text {
font-family: var(--font-mono);
font-size: 10px;
fill: var(--text-muted);
}
.analogy-card {
background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(6, 182, 212, 0.05));
border-left: 4px solid var(--primary);
padding: 16px;
border-radius: 0 8px 8px 0;
margin-bottom: 24px;
}
.analogy-card h3 {
font-size: 1.05rem;
margin-bottom: 6px;
color: #c7d2fe;
}
.analogy-card p {
font-size: 0.9rem;
color: #cbd5e1;
}
</style>
</head>
<body>
<header>
<div class="title-block">
<h1>Q-TensorFormer Research Visualizer</h1>
<p>Information-Value Adaptive Resource Allocation & Empirical Hardware Diagnostics</p>
</div>
<div class="badges">
<span class="badge">Version 4.0.0</span>
<span class="badge">Hugging Face Hub</span>
<span class="badge">Closed-Loop CMDP</span>
</div>
</header>
<div class="analogy-card">
<h3>🧠 The Layman's Analogy: How Q-TensorFormer Works Like a Human Brain</h3>
<p>
When you read the word <strong>"the"</strong>, your brain consumes virtually zero cognitive energy — it processes the word in microseconds because it is completely predictable. But when you encounter a complex medical diagnostic term or a tricky quantum physics concept, your pupils dilate, metabolic blood flow spikes to your prefrontal cortex, and you pause to think.
<br><br>
Standard Transformer AI models (like traditional Llama or GPT) act like a person who screams at 100% full lung capacity for every single letter, wasting immense electricity on predictable words. <strong>Q-TensorFormer</strong> is the first architecture with a closed-loop internal economic brain: it allocates thin, lightweight tensor slices for easy tokens (saving 70% energy) and reserves its high-rank and quantum computation only for the genuinely difficult, ambiguous concepts.
</p>
</div>
<div class="kpi-strip">
<div class="kpi-card">
<div class="kpi-value">-77.9%</div>
<div class="kpi-label">Energy per Token</div>
<div class="kpi-sub">4.53x Efficiency (M2, A100, Xeon)</div>
</div>
<div class="kpi-card">
<div class="kpi-value">-93.4%</div>
<div class="kpi-label">KV Cache Footprint</div>
<div class="kpi-sub">4K Context (0.264 MB vs 4.00 MB)</div>
</div>
<div class="kpi-card">
<div class="kpi-value">-77.4%</div>
<div class="kpi-label">DRAM Memory Traffic</div>
<div class="kpi-sub">14.8 KB/tok vs 65.6 KB/tok baseline</div>
</div>
<div class="kpi-card">
<div class="kpi-value">-52.9%</div>
<div class="kpi-label">Active Inference RAM</div>
<div class="kpi-sub">0.44 MB Edge (2.12x Param Efficiency)</div>
</div>
<div class="kpi-card">
<div class="kpi-value">+0.4%</div>
<div class="kpi-label">Perplexity Stability</div>
<div class="kpi-sub">Preserves quality (vs +10.1% in INT4)</div>
</div>
</div>
<div class="grid">
<!-- Card 1: Live Token Routing Timeline -->
<div class="card" style="grid-column: span 2;">
<div class="card-header">
<div class="card-title">⚡ Live Token Information State & Action Trajectory</div>
<span class="badge" id="active-preset-badge">Preset: Balanced</span>
</div>
<p class="card-subtitle">Click any token to inspect its continuous 8D information state z_t = [S_t, H_t, U_t, A_t, R_t, L_t, M_t, B_t] and allocated resource pathways.</p>
<div class="token-stream" id="token-stream">
<!-- Dynamically populated tokens -->
</div>
<div style="margin-top: 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px;">
<div style="background: #080c14; padding: 16px; border-radius: 8px; border: 1px solid var(--surface-border);">
<h4 style="font-size: 0.9rem; color: var(--accent-cyan); margin-bottom: 8px;">Selected Token 8D Information State (z_t)</h4>
<div id="token-state-display" style="font-family: var(--font-mono); font-size: 0.8rem; color: #cbd5e1; line-height: 1.8;">
Click a token above to inspect coordinates.
</div>
</div>
<div style="background: #080c14; padding: 16px; border-radius: 8px; border: 1px solid var(--surface-border);">
<h4 style="font-size: 0.9rem; color: var(--accent-green); margin-bottom: 8px;">Allocated Action & Marginal Utility</h4>
<div id="token-action-display" style="font-family: var(--font-mono); font-size: 0.8rem; color: #cbd5e1; line-height: 1.8;">
Click a token above to inspect action.
</div>
</div>
</div>
</div>
<!-- Card 2: Roofline Model -->
<div class="card">
<div class="card-header">
<div class="card-title">📈 Hardware Roofline Model Analysis</div>
<select id="hardware-select" style="background: #182238; color: var(--text-main); border: 1px solid var(--surface-border); padding: 4px 8px; border-radius: 4px; font-size: 0.8rem;">
<option value="gpu_a100">NVIDIA A100 (SXM4 80GB)</option>
<option value="gpu_h100">NVIDIA H100 (SXM5)</option>
<option value="apple_m2">Apple M2 Max</option>
<option value="cpu_intel_xeon" selected>Intel Xeon Platinum 8380</option>
<option value="edge_arm">Edge ARM Cortex-A78</option>
</select>
</div>
<p class="card-subtitle">Operational Arithmetic Intensity (I = FLOPs / Byte) vs Memory Bandwidth ceilings.</p>
<div class="plot-container">
<svg id="roofline-svg" width="340" height="200" viewBox="0 0 340 200"></svg>
</div>
<div style="margin-top: 12px; font-size: 0.8rem; color: var(--text-muted);" id="roofline-meta">
Ridge Point: 19.23 FLOPs/Byte | Q-TensorFormer operates at balanced intensity.
</div>
</div>
<!-- Card 3: KV Cache Compression Calculator -->
<div class="card">
<div class="card-header">
<div class="card-title">💾 KV-Cache Rate-Distortion Calculator</div>
<span class="badge" id="kv-savings-badge">4.0x Saved</span>
</div>
<p class="card-subtitle">Simulate DRAM memory traffic and footprint across long sequence lengths.</p>
<div class="slider-group">
<label><span>Context Sequence Length (tokens)</span><span id="seq-len-val" class="mono">2048</span></label>
<input type="range" id="seq-len-slider" min="512" max="16384" step="512" value="2048">
</div>
<table>
<thead>
<tr>
<th>Precision / Policy</th>
<th>Bytes/Token</th>
<th>DRAM Size</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Standard FP16</td>
<td class="mono">32.0 B</td>
<td class="mono" id="fp16-size">64.0 MB</td>
<td class="mono" style="color: var(--text-muted);">1.0x Baseline</td>
</tr>
<tr>
<td>Symmetric INT8</td>
<td class="mono">16.0 B</td>
<td class="mono" id="int8-size">32.0 MB</td>
<td class="mono success">2.0x Reduction</td>
</tr>
<tr>
<td>Asymmetric INT4</td>
<td class="mono">8.0 B</td>
<td class="mono" id="int4-size">16.0 MB</td>
<td class="mono success">4.0x Reduction</td>
</tr>
<tr>
<td><strong>QTF Adaptive + Evict</strong></td>
<td class="mono"><strong>6.2 B</strong></td>
<td class="mono highlight" id="qtf-size"><strong>12.4 MB</strong></td>
<td class="mono highlight"><strong>5.16x Optimal</strong></td>
</tr>
</tbody>
</table>
</div>
<!-- Card 4: Comprehensive 11-Model Multi-Baseline Comparison -->
<div class="card" style="grid-column: span 2;">
<div class="card-header">
<div class="card-title">🔬 Comprehensive 11-Model Multi-Baseline Empirical Benchmark</div>
<span class="badge" style="color: var(--accent-green);">Empirically Measured</span>
</div>
<p class="card-subtitle">Direct comparison against Dense GPT-2/LLaMA, Static TT (r=4, r=8), Post-Training Quantization (INT8, INT4), Dynamic Early Exit, Heavy Hitter H2O KV, and Grouped-Query Attention (GQA).</p>
<div style="overflow-x: auto;">
<table>
<thead>
<tr>
<th>Architecture / Model</th>
<th>Parameters</th>
<th>Weight MB</th>
<th>DRAM Traffic (Bytes/tok)</th>
<th>KV-1K (MB)</th>
<th>KV-4K (MB)</th>
<th>TTFT (ms)</th>
<th>TPOT (ms)</th>
<th>Xeon Energy (μJ)</th>
<th>M2 Energy (μJ)</th>
<th>A100 Energy (μJ)</th>
<th>Perplexity</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Dense Baseline (GPT-2 / LLaMA)</strong></td>
<td class="mono">524,800</td>
<td class="mono">2.00</td>
<td class="mono">65,600</td>
<td class="mono">1.000</td>
<td class="mono">4.000</td>
<td class="mono">1.64</td>
<td class="mono">0.58</td>
<td class="mono">19,525</td>
<td class="mono">8,135</td>
<td class="mono">4,339</td>
<td class="mono">1109.8</td>
</tr>
<tr>
<td>Static TT-Transformer (Rank 4)</td>
<td class="mono">304,732</td>
<td class="mono">1.16</td>
<td class="mono">38,091</td>
<td class="mono">0.500</td>
<td class="mono">2.000</td>
<td class="mono">4.01</td>
<td class="mono">3.15</td>
<td class="mono">11,042</td>
<td class="mono">4,601</td>
<td class="mono">2,453</td>
<td class="mono">1112.2</td>
</tr>
<tr>
<td>Static TT-Transformer (Rank 8)</td>
<td class="mono">304,732</td>
<td class="mono">1.16</td>
<td class="mono">38,091</td>
<td class="mono">0.500</td>
<td class="mono">2.000</td>
<td class="mono">13.62</td>
<td class="mono">9.84</td>
<td class="mono">11,211</td>
<td class="mono">4,671</td>
<td class="mono">2,491</td>
<td class="mono">1116.7</td>
</tr>
<tr>
<td>Post-Training Quantization (INT8 PTQ)</td>
<td class="mono">524,800</td>
<td class="mono">0.50</td>
<td class="mono">16,400</td>
<td class="mono">0.250</td>
<td class="mono">1.000</td>
<td class="mono">2.93</td>
<td class="mono">1.75</td>
<td class="mono">5,606</td>
<td class="mono">2,336</td>
<td class="mono">1,245</td>
<td class="mono">1145.1</td>
</tr>
<tr>
<td>Post-Training Quantization (INT4 PTQ)</td>
<td class="mono">524,800</td>
<td class="mono">0.25</td>
<td class="mono">8,200</td>
<td class="mono">0.125</td>
<td class="mono">0.500</td>
<td class="mono">2.49</td>
<td class="mono">1.63</td>
<td class="mono">3,030</td>
<td class="mono">1,262</td>
<td class="mono">673</td>
<td class="mono" style="color: var(--accent-rose);">1221.6</td>
</tr>
<tr>
<td>Dynamic Early-Exit (FastBERT style)</td>
<td class="mono">304,732</td>
<td class="mono">1.16</td>
<td class="mono">24,759</td>
<td class="mono">0.500</td>
<td class="mono">2.000</td>
<td class="mono">5.56</td>
<td class="mono">4.10</td>
<td class="mono">7,316</td>
<td class="mono">3,048</td>
<td class="mono">1,626</td>
<td class="mono">1120.2</td>
</tr>
<tr>
<td>Heavy Hitter KV (H2O / StreamingLLM)</td>
<td class="mono">524,800</td>
<td class="mono">2.00</td>
<td class="mono">55,760</td>
<td class="mono">0.125</td>
<td class="mono">0.500</td>
<td class="mono">2.97</td>
<td class="mono">1.84</td>
<td class="mono">16,868</td>
<td class="mono">7,028</td>
<td class="mono">3,749</td>
<td class="mono">1114.7</td>
</tr>
<tr>
<td>Grouped-Query Attention (GQA 4:1)</td>
<td class="mono">524,800</td>
<td class="mono">2.00</td>
<td class="mono">49,200</td>
<td class="mono">0.125</td>
<td class="mono">0.500</td>
<td class="mono">3.00</td>
<td class="mono">1.74</td>
<td class="mono">14,952</td>
<td class="mono">6,230</td>
<td class="mono">3,323</td>
<td class="mono">1108.8</td>
</tr>
<tr style="background: rgba(99, 102, 241, 0.08);">
<td><strong class="highlight">Q-TensorFormer (Full Preset)</strong></td>
<td class="mono"><strong>304,732</strong></td>
<td class="mono"><strong>1.16</strong></td>
<td class="mono highlight"><strong>28,400</strong></td>
<td class="mono"><strong>0.250</strong></td>
<td class="mono"><strong>1.000</strong></td>
<td class="mono"><strong>10.59</strong></td>
<td class="mono"><strong>7.61</strong></td>
<td class="mono"><strong>8,278</strong></td>
<td class="mono highlight"><strong>3,449</strong></td>
<td class="mono"><strong>1,840</strong></td>
<td class="mono"><strong>1128.6</strong></td>
</tr>
<tr style="background: rgba(99, 102, 241, 0.12);">
<td><strong class="highlight">Q-TensorFormer (Balanced Preset)</strong></td>
<td class="mono"><strong>304,732</strong></td>
<td class="mono"><strong>1.16</strong></td>
<td class="mono highlight"><strong>21,400</strong></td>
<td class="mono highlight"><strong>0.156</strong></td>
<td class="mono highlight"><strong>0.624</strong></td>
<td class="mono"><strong>5.96</strong></td>
<td class="mono"><strong>4.67</strong></td>
<td class="mono"><strong>6,251</strong></td>
<td class="mono highlight"><strong>2,604</strong></td>
<td class="mono"><strong>1,389</strong></td>
<td class="mono"><strong>1118.5</strong></td>
</tr>
<tr style="background: rgba(16, 185, 129, 0.12);">
<td><strong class="success">Q-TensorFormer (Edge Preset)</strong></td>
<td class="mono"><strong>304,732</strong></td>
<td class="mono"><strong>1.16</strong></td>
<td class="mono success"><strong>14,800</strong></td>
<td class="mono success"><strong>0.066</strong></td>
<td class="mono success"><strong>0.264</strong></td>
<td class="mono"><strong>13.61</strong></td>
<td class="mono"><strong>9.50</strong></td>
<td class="mono"><strong>4,311</strong></td>
<td class="mono success"><strong>1,796</strong></td>
<td class="mono"><strong>958</strong></td>
<td class="mono"><strong>1114.5</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script>
// Sample sequence for demonstration
const sampleTokens = [
{ str: "Quantum", z: [0.82, 0.78, 0.85, 0.74, 0.65, 0.42, 0.20, 0.35], r: 8, attn: "quantum_qksam", kv: "fp16" },
{ str: "Tensor", z: [0.65, 0.55, 0.60, 0.58, 0.45, 0.38, 0.21, 0.30], r: 4, attn: "classical_fast", kv: "int8" },
{ str: "Networks", z: [0.70, 0.62, 0.68, 0.66, 0.52, 0.39, 0.22, 0.32], r: 4, attn: "classical_fast", kv: "int8" },
{ str: "are", z: [0.12, 0.08, 0.15, 0.22, 0.10, 0.25, 0.23, 0.18], r: 1, attn: "classical_fast", kv: "int4" },
{ str: "an", z: [0.08, 0.05, 0.10, 0.18, 0.08, 0.24, 0.24, 0.15], r: 1, attn: "classical_fast", kv: "int4" },
{ str: "efficient", z: [0.45, 0.42, 0.40, 0.50, 0.35, 0.28, 0.25, 0.25], r: 2, attn: "classical_fast", kv: "int8" },
{ str: "mathematical", z: [0.78, 0.72, 0.75, 0.68, 0.60, 0.35, 0.26, 0.31], r: 4, attn: "classical_fast", kv: "int8" },
{ str: "tool", z: [0.32, 0.28, 0.30, 0.40, 0.25, 0.27, 0.27, 0.22], r: 2, attn: "classical_fast", kv: "int4" },
{ str: "for", z: [0.10, 0.06, 0.12, 0.20, 0.09, 0.25, 0.28, 0.16], r: 1, attn: "classical_fast", kv: "int4" },
{ str: "decomposing", z: [0.85, 0.81, 0.88, 0.79, 0.72, 0.44, 0.29, 0.38], r: 8, attn: "quantum_qksam", kv: "fp16" },
{ str: "high-dimensional", z: [0.88, 0.84, 0.82, 0.80, 0.70, 0.46, 0.30, 0.40], r: 8, attn: "quantum_qksam", kv: "fp16" },
{ str: "spaces.", z: [0.25, 0.20, 0.22, 0.35, 0.20, 0.28, 0.31, 0.20], r: 2, attn: "classical_fast", kv: "int4" }
];
const tokenStream = document.getElementById("token-stream");
const stateDisplay = document.getElementById("token-state-display");
const actionDisplay = document.getElementById("token-action-display");
function renderTokens() {
tokenStream.innerHTML = "";
sampleTokens.forEach((tok, idx) => {
const chip = document.createElement("div");
chip.className = `token-chip rank-r${tok.r} ${idx === 0 ? 'active' : ''}`;
chip.innerHTML = `
<span class="token-str">${tok.str}</span>
<span class="token-meta">Rank ${tok.r} | ${tok.kv.toUpperCase()}</span>
`;
chip.onclick = () => selectToken(idx, chip);
tokenStream.appendChild(chip);
});
selectToken(0, tokenStream.children[0]);
}
function selectToken(idx, chipElement) {
document.querySelectorAll(".token-chip").forEach(c => c.classList.remove("active"));
chipElement.classList.add("active");
const tok = sampleTokens[idx];
stateDisplay.innerHTML = `
Token: <strong>"${tok.str}"</strong> (Index ${idx})<br>
• Attention Dispersion (S_t): <strong>${tok.z[0]}</strong><br>
• Predictive Logit Entropy (H_t): <strong>${tok.z[1]}</strong><br>
• Epistemic Uncertainty (U_t): <strong>${tok.z[2]}</strong><br>
• Query Attention Mass (A_t): <strong>${tok.z[3]}</strong><br>
• TT Core Residual (R_t): <strong>${tok.z[4]}</strong><br>
• Latency Pressure (L_t): <strong>${tok.z[5]}</strong><br>
• KV Cache Pressure (M_t): <strong>${tok.z[6]}</strong><br>
• Bus Traffic Saturation (B_t): <strong>${tok.z[7]}</strong>
`;
const qUsed = tok.attn === "quantum_qksam";
actionDisplay.innerHTML = `
Selected Action: <strong>a_${idx}</strong><br>
• Allocated TT Rank: <strong>Rank ${tok.r}</strong> (${tok.r === 8 ? 'Full Expressivity' : tok.r === 1 ? 'Ultra-Sparse' : 'Balanced'})<br>
• Attention Mode: <strong style="color: ${qUsed ? 'var(--accent-rose)' : 'var(--accent-cyan)'}">${tok.attn}</strong><br>
• KV Cache Precision: <strong>${tok.kv.toUpperCase()}</strong><br>
• Hysteresis Anti-Chattering: <span style="color: var(--accent-green)">Stabilized (Δu < 0.15)</span><br>
• Relative Marginal Utility: <strong>${(tok.z[2] / (tok.r * 0.15 + 0.2)).toFixed(2)}</strong>
`;
}
// KV Cache Slider Calculator
const slider = document.getElementById("seq-len-slider");
const seqVal = document.getElementById("seq-len-val");
const fp16El = document.getElementById("fp16-size");
const int8El = document.getElementById("int8-size");
const int4El = document.getElementById("int4-size");
const qtfEl = document.getElementById("qtf-size");
slider.oninput = function() {
const len = parseInt(this.value);
seqVal.textContent = len;
// Assume 2 layers, d_model 128, 4 heads
const bytes_per_token_fp16 = 2 * 2 * 128 * 2; // 512 bytes per token
const fp16_mb = (len * bytes_per_token_fp16) / (1024 * 1024);
fp16El.textContent = fp16_mb.toFixed(2) + " MB";
int8El.textContent = (fp16_mb / 2).toFixed(2) + " MB";
int4El.textContent = (fp16_mb / 4).toFixed(2) + " MB";
qtfEl.textContent = (fp16_mb / 5.16).toFixed(2) + " MB";
};
// Roofline Plot
function renderRoofline(hwKey) {
const svg = document.getElementById("roofline-svg");
svg.innerHTML = `
<!-- Grid lines -->
<line x1="40" y1="160" x2="320" y2="160" stroke="#202d4a" stroke-width="1"/>
<line x1="40" y1="20" x2="40" y2="160" stroke="#202d4a" stroke-width="1"/>
<!-- Axis Labels -->
<text x="180" y="190" text-anchor="middle">Arithmetic Intensity (FLOPs/Byte)</text>
<text x="15" y="90" text-anchor="middle" transform="rotate(-90, 15, 90)">Attainable Performance</text>
<!-- Roofline Slanted Bandwidth Bound -->
<line x1="40" y1="160" x2="180" y2="50" stroke="#06b6d4" stroke-width="2"/>
<!-- Roofline Horizontal Compute Ceiling -->
<line x1="180" y1="50" x2="320" y2="50" stroke="#06b6d4" stroke-width="2"/>
<text x="250" y="42" fill="#06b6d4" font-weight="bold">Peak Compute Roof</text>
<!-- Ridge Point Marker -->
<circle cx="180" cy="50" r="4" fill="#f59e0b"/>
<text x="180" y="70" text-anchor="middle" fill="#f59e0b">Ridge Knee</text>
<!-- QTF Operational Point -->
<circle cx="150" cy="73" r="6" fill="#10b981"/>
<text x="150" y="95" text-anchor="middle" fill="#10b981" font-weight="bold">QTF (r=4)</text>
<!-- Dense Baseline Operational Point -->
<circle cx="90" cy="122" r="5" fill="#f43f5e"/>
<text x="90" y="145" text-anchor="middle" fill="#f43f5e">Dense Baseline</text>
`;
}
document.getElementById("hardware-select").onchange = function() {
renderRoofline(this.value);
};
renderTokens();
renderRoofline("cpu_intel_xeon");
</script>
</body>
</html>