joelniklaus HF Staff commited on
Commit
66772b0
Β·
1 Parent(s): bdefa11

add first version of throughput optimization visualization

Browse files
app/src/content/chapters/infrastructure.mdx CHANGED
@@ -1,4 +1,5 @@
1
  import Image from "../../components/Image.astro";
 
2
  import SyDLepVveg_2f81384e_bcac_806f_acb7_fd65c71dd9df from "../assets/image/SyDLepVveg_2f81384e-bcac-806f-acb7-fd65c71dd9df.jpg";
3
  import Screenshot_2026_01_20_at_09_42_21_2f81384e_bcac_80e6_b3fa_d06567e56b15 from "../assets/image/Screenshot_2026-01-20_at_09_42_21_2f81384e-bcac-80e6-b3fa-d06567e56b15.png";
4
 
@@ -484,11 +485,14 @@ The fundamental insight is that **optimization gains depend on identifying the b
484
 
485
  The Flash-Attn vLLM backend is more than 50% faster than FlashInfer [@flashinfer] across setups. This aligns with vLLM's [backend priority](https://docs.vllm.ai/en/latest/design/attention_backends/#backend-priority-cuda): on Ampere/Hopper (SM 8.x–9.x) Flash Attention is tried first, whereas on Blackwell (SM 10.x) FlashInfer has priority and may be faster there.
486
 
487
- #### Pre-training
488
 
489
- For pre-training, we know that 1B models are enough, so we are not interested in testing different sizes, but more about optimizing the setup for specific dataset-prompt-model combinations we know work well.
 
 
 
 
 
490
 
491
- We also experimented with different values of `gpu-memory-utilization` , but they didn't make a substantial difference so we don't report them here and exclude them from the main benchmarking code for simplicity.
492
 
493
  Similar to [prior experiments](https://github.com/vllm-project/vllm/issues/6868), we also did not find significant throughput differences with non-standard block sizes (not 16).
494
 
 
1
  import Image from "../../components/Image.astro";
2
+ import HtmlEmbed from "../../components/HtmlEmbed.astro";
3
  import SyDLepVveg_2f81384e_bcac_806f_acb7_fd65c71dd9df from "../assets/image/SyDLepVveg_2f81384e-bcac-806f-acb7-fd65c71dd9df.jpg";
4
  import Screenshot_2026_01_20_at_09_42_21_2f81384e_bcac_80e6_b3fa_d06567e56b15 from "../assets/image/Screenshot_2026-01-20_at_09_42_21_2f81384e-bcac-80e6-b3fa-d06567e56b15.png";
5
 
 
485
 
486
  The Flash-Attn vLLM backend is more than 50% faster than FlashInfer [@flashinfer] across setups. This aligns with vLLM's [backend priority](https://docs.vllm.ai/en/latest/design/attention_backends/#backend-priority-cuda): on Ampere/Hopper (SM 8.x–9.x) Flash Attention is tried first, whereas on Blackwell (SM 10.x) FlashInfer has priority and may be faster there.
487
 
 
488
 
489
+ <HtmlEmbed
490
+ id="optimization-sweep"
491
+ src="d3-optimization-sweep.html"
492
+ title="Pre-training Throughput Optimization Sweep"
493
+ desc="Throughput optimization across 18 models in two tiers. Tier 0 tunes serving parameters (tp, mns, mnbt). Tier 1 adds gpu-memory-utilization and speculative decoding. Shape encodes tier, color encodes model family."
494
+ />
495
 
 
496
 
497
  Similar to [prior experiments](https://github.com/vllm-project/vllm/issues/6868), we also did not find significant throughput differences with non-standard block sizes (not 16).
498
 
app/src/content/embeds/d3-optimization-sweep.html ADDED
@@ -0,0 +1,543 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="d3-optimization-sweep"></div>
2
+ <style>
3
+ .d3-optimization-sweep { position: relative; }
4
+ .d3-optimization-sweep .controls {
5
+ display: flex;
6
+ gap: 16px;
7
+ align-items: flex-end;
8
+ justify-content: flex-end;
9
+ flex-wrap: wrap;
10
+ margin: 10px 0 0 0;
11
+ }
12
+ .d3-optimization-sweep .controls .control-group {
13
+ display: flex;
14
+ flex-direction: column;
15
+ align-items: flex-start;
16
+ gap: 6px;
17
+ }
18
+ .d3-optimization-sweep .controls label {
19
+ font-size: 12px;
20
+ font-weight: 700;
21
+ color: var(--text-color);
22
+ }
23
+ .d3-optimization-sweep .controls select {
24
+ appearance: none;
25
+ -webkit-appearance: none;
26
+ -moz-appearance: none;
27
+ border: 1px solid var(--border-color);
28
+ border-radius: 8px;
29
+ padding: 6px 28px 6px 10px;
30
+ background-color: var(--surface-bg);
31
+ color: var(--text-color);
32
+ font-size: 13px;
33
+ line-height: 1.2;
34
+ background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1.41 1.59L6 6.17l4.59-4.58L12 3 6 9 0 3z' fill='%23999'/%3E%3C/svg%3E");
35
+ background-repeat: no-repeat;
36
+ background-position: right 8px center;
37
+ }
38
+ .d3-optimization-sweep .controls select:focus-visible {
39
+ outline: 2px solid var(--primary-color);
40
+ outline-offset: 2px;
41
+ }
42
+ .d3-optimization-sweep .legend {
43
+ display: flex;
44
+ flex-direction: column;
45
+ align-items: flex-start;
46
+ gap: 6px;
47
+ margin: 8px 0 0 0;
48
+ }
49
+ .d3-optimization-sweep .legend .legend-title {
50
+ font-size: 12px;
51
+ font-weight: 700;
52
+ color: var(--text-color);
53
+ }
54
+ .d3-optimization-sweep .legend .legend-section {
55
+ display: flex;
56
+ flex-wrap: wrap;
57
+ gap: 8px 14px;
58
+ }
59
+ .d3-optimization-sweep .legend .item {
60
+ display: inline-flex;
61
+ align-items: center;
62
+ gap: 6px;
63
+ white-space: nowrap;
64
+ font-size: 12px;
65
+ color: var(--text-color);
66
+ }
67
+ .d3-optimization-sweep .legend .swatch {
68
+ width: 14px;
69
+ height: 14px;
70
+ border-radius: 3px;
71
+ border: 1px solid var(--border-color);
72
+ flex-shrink: 0;
73
+ }
74
+ .d3-optimization-sweep .legend .shape-swatch {
75
+ width: 14px;
76
+ height: 14px;
77
+ flex-shrink: 0;
78
+ }
79
+ .d3-optimization-sweep .d3-tooltip {
80
+ position: absolute;
81
+ top: 0px;
82
+ left: 0px;
83
+ transform: translate(-9999px, -9999px);
84
+ pointer-events: none;
85
+ padding: 8px 10px;
86
+ border-radius: 8px;
87
+ font-size: 12px;
88
+ line-height: 1.35;
89
+ border: 1px solid var(--border-color);
90
+ background: var(--surface-bg);
91
+ color: var(--text-color);
92
+ box-shadow: 0 4px 24px rgba(0,0,0,.18);
93
+ opacity: 0;
94
+ transition: opacity .12s ease;
95
+ text-align: left;
96
+ max-width: 320px;
97
+ z-index: 10;
98
+ }
99
+ .d3-optimization-sweep .d3-tooltip .tip-label { color: var(--muted-color); }
100
+ .d3-optimization-sweep .d3-tooltip .tip-val { font-weight: 600; }
101
+ .d3-optimization-sweep .d3-tooltip .tip-best { color: var(--primary-color); font-weight: 700; }
102
+ .d3-optimization-sweep .d3-tooltip .tip-regression { color: #e05252; }
103
+ .d3-optimization-sweep .y-label-text {
104
+ font-size: 11px;
105
+ cursor: default;
106
+ }
107
+ .d3-optimization-sweep .speedup-label {
108
+ font-size: 10px;
109
+ font-weight: 600;
110
+ }
111
+ </style>
112
+ <script>
113
+ (() => {
114
+ const ensureD3 = (cb) => {
115
+ if (window.d3 && typeof window.d3.select === 'function') return cb();
116
+ let s = document.getElementById('d3-cdn-script');
117
+ if (!s) {
118
+ s = document.createElement('script');
119
+ s.id = 'd3-cdn-script';
120
+ s.src = 'https://cdn.jsdelivr.net/npm/d3@7/dist/d3.min.js';
121
+ document.head.appendChild(s);
122
+ }
123
+ const onReady = () => { if (window.d3 && typeof window.d3.select === 'function') cb(); };
124
+ s.addEventListener('load', onReady, { once: true });
125
+ if (window.d3) onReady();
126
+ };
127
+
128
+ const bootstrap = () => {
129
+ const scriptEl = document.currentScript;
130
+ let container = scriptEl ? scriptEl.previousElementSibling : null;
131
+ if (!(container && container.classList && container.classList.contains('d3-optimization-sweep'))) {
132
+ const cs = Array.from(document.querySelectorAll('.d3-optimization-sweep'))
133
+ .filter(el => !(el.dataset && el.dataset.mounted === 'true'));
134
+ container = cs[cs.length - 1] || null;
135
+ }
136
+ if (!container) return;
137
+ if (container.dataset) {
138
+ if (container.dataset.mounted === 'true') return;
139
+ container.dataset.mounted = 'true';
140
+ }
141
+ container.style.position = container.style.position || 'relative';
142
+
143
+ // ── Data ──
144
+ const DATA = [
145
+ { model: 'Qwen3-0.6B', family: 'Qwen3', baseTp: 1, baseTps: 13527, t0Tps: 14069, t0Speedup: 1.04, t0Params: 'mns=512', t1Tps: 12330, t1Speedup: 0.91, t1Params: 'mns=512, gmu=95', bestTps: 14069, bestSpeedup: 1.04, bestParams: 'mns=512' },
146
+ { model: 'Qwen3-1.7B', family: 'Qwen3', baseTp: 1, baseTps: 11710, t0Tps: 12313, t0Speedup: 1.05, t0Params: 'mnbt=32768', t1Tps: 11262, t1Speedup: 0.96, t1Params: 'mnbt=32768, gmu=95', bestTps: 12313, bestSpeedup: 1.05, bestParams: 'mnbt=32768' },
147
+ { model: 'Qwen3-14B', family: 'Qwen3', baseTp: 1, baseTps: 4414, t0Tps: 4549, t0Speedup: 1.03, t0Params: 'tp=2', t1Tps: 4158, t1Speedup: 0.94, t1Params: 'tp=2', bestTps: 4549, bestSpeedup: 1.03, bestParams: 'tp=2' },
148
+ { model: 'Qwen3-30B-A3B', family: 'Qwen3', baseTp: 1, baseTps: 2977, t0Tps: 5310, t0Speedup: 1.78, t0Params: 'tp=2, mns=512, mnbt=32768', t1Tps: 5064, t1Speedup: 1.70, t1Params: 'tp=2, mns=512, mnbt=32768, gmu=95', bestTps: 5310, bestSpeedup: 1.78, bestParams: 'tp=2, mns=512, mnbt=32768' },
149
+ { model: 'Qwen3-32B', family: 'Qwen3', baseTp: 4, baseTps: 1987, t0Tps: 2072, t0Speedup: 1.04, t0Params: 'mns=512, mnbt=16384', t1Tps: 2078, t1Speedup: 1.05, t1Params: 'mns=512, mnbt=16384, gmu=95', bestTps: 2078, bestSpeedup: 1.05, bestParams: 'mns=512, mnbt=16384, gmu=95' },
150
+ { model: 'Qwen3-4B', family: 'Qwen3', baseTp: 1, baseTps: 7919, t0Tps: 8086, t0Speedup: 1.02, t0Params: 'mnbt=32768', t1Tps: 7751, t1Speedup: 0.98, t1Params: 'mnbt=32768, gmu=95', bestTps: 8086, bestSpeedup: 1.02, bestParams: 'mnbt=32768' },
151
+ { model: 'Qwen3-8B', family: 'Qwen3', baseTp: 1, baseTps: 6338, t0Tps: 6338, t0Speedup: 1.00, t0Params: '(baseline)', t1Tps: 6443, t1Speedup: 1.02, t1Params: 'gmu=95', bestTps: 6443, bestSpeedup: 1.02, bestParams: 'gmu=95' },
152
+ { model: 'Qwen3-Next-80B-A3B', family: 'Qwen3', baseTp: 4, baseTps: 2034, t0Tps: 2678, t0Speedup: 1.32, t0Params: 'mns=512', t1Tps: 2481, t1Speedup: 1.22, t1Params: 'mns=512', bestTps: 2678, bestSpeedup: 1.32, bestParams: 'mns=512' },
153
+ { model: 'SmolLM2-1.7B', family: 'SmolLM2', baseTp: 1, baseTps: 5255, t0Tps: 5437, t0Speedup: 1.03, t0Params: 'mns=2048, mnbt=32768', t1Tps: 9220, t1Speedup: 1.75, t1Params: 'mns=2048, mnbt=32768, gmu=95, spec=suffix_32', bestTps: 9220, bestSpeedup: 1.75, bestParams: 'mns=2048, mnbt=32768, gmu=95, spec=suffix_32' },
154
+ { model: 'SmolLM2-135M', family: 'SmolLM2', baseTp: 1, baseTps: 28391, t0Tps: 31186, t0Speedup: 1.10, t0Params: 'mns=512, mnbt=32768', t1Tps: 45540, t1Speedup: 1.60, t1Params: 'mns=512, mnbt=32768, spec=ngram_6', bestTps: 45540, bestSpeedup: 1.60, bestParams: 'mns=512, mnbt=32768, spec=ngram_6' },
155
+ { model: 'SmolLM2-360M', family: 'SmolLM2', baseTp: 1, baseTps: 17887, t0Tps: 18844, t0Speedup: 1.05, t0Params: 'mns=512', t1Tps: 23996, t1Speedup: 1.34, t1Params: 'mns=512, spec=ngram_6', bestTps: 23996, bestSpeedup: 1.34, bestParams: 'mns=512, spec=ngram_6' },
156
+ { model: 'Gemma-3-12B', family: 'Gemma3', baseTp: 1, baseTps: 2999, t0Tps: 2999, t0Speedup: 1.00, t0Params: '(baseline)', t1Tps: 3046, t1Speedup: 1.02, t1Params: 'gmu=95', bestTps: 3046, bestSpeedup: 1.02, bestParams: 'gmu=95' },
157
+ { model: 'Gemma-3-1B', family: 'Gemma3', baseTp: 1, baseTps: 14838, t0Tps: 16762, t0Speedup: 1.13, t0Params: 'mns=4096, mnbt=32768', t1Tps: 13832, t1Speedup: 0.93, t1Params: 'mns=4096, mnbt=32768, gmu=95', bestTps: 16762, bestSpeedup: 1.13, bestParams: 'mns=4096, mnbt=32768' },
158
+ { model: 'Gemma-3-270M', family: 'Gemma3', baseTp: 1, baseTps: 22996, t0Tps: 23585, t0Speedup: 1.03, t0Params: 'mnbt=32768', t1Tps: 21030, t1Speedup: 0.91, t1Params: 'mnbt=32768', bestTps: 23585, bestSpeedup: 1.03, bestParams: 'mnbt=32768' },
159
+ { model: 'Gemma-3-27B', family: 'Gemma3', baseTp: 2, baseTps: 1724, t0Tps: 1724, t0Speedup: 1.00, t0Params: '(baseline)', t1Tps: 1671, t1Speedup: 0.97, t1Params: 'gmu=95', bestTps: 1724, bestSpeedup: 1.00, bestParams: '(baseline)' },
160
+ { model: 'Gemma-3-4B', family: 'Gemma3', baseTp: 1, baseTps: 8501, t0Tps: 9253, t0Speedup: 1.09, t0Params: 'mns=1024, mnbt=32768', t1Tps: 8361, t1Speedup: 0.98, t1Params: 'mns=1024, mnbt=32768', bestTps: 9253, bestSpeedup: 1.09, bestParams: 'mns=1024, mnbt=32768' },
161
+ { model: 'GPT-OSS-120B', family: 'GPT-OSS', baseTp: 1, baseTps: 3138, t0Tps: 6117, t0Speedup: 1.95, t0Params: 'tp=2, mns=1024, mnbt=32768', t1Tps: 5450, t1Speedup: 1.74, t1Params: 'tp=2, mns=1024, mnbt=32768', bestTps: 6117, bestSpeedup: 1.95, bestParams: 'tp=2, mns=1024, mnbt=32768' },
162
+ { model: 'GPT-OSS-20B', family: 'GPT-OSS', baseTp: 1, baseTps: 12432, t0Tps: 14671, t0Speedup: 1.18, t0Params: 'mns=512, mnbt=16384', t1Tps: 13004, t1Speedup: 1.05, t1Params: 'mns=512, mnbt=16384', bestTps: 14671, bestSpeedup: 1.18, bestParams: 'mns=512, mnbt=16384' },
163
+ ];
164
+
165
+ const FAMILIES = ['Qwen3', 'SmolLM2', 'Gemma3', 'GPT-OSS'];
166
+ const TIERS = ['Baseline', 'Tier 0', 'Tier 1'];
167
+
168
+ // ── Colors & shapes ──
169
+ function getFamilyColors() {
170
+ try {
171
+ if (window.ColorPalettes && typeof window.ColorPalettes.getColors === 'function') {
172
+ return window.ColorPalettes.getColors('categorical', FAMILIES.length);
173
+ }
174
+ } catch (e) {}
175
+ return ['var(--primary-color)', '#e377c2', '#17becf', '#bcbd22'];
176
+ }
177
+
178
+ const familyPalette = getFamilyColors();
179
+ const familyColor = (family) => familyPalette[FAMILIES.indexOf(family)] || 'var(--primary-color)';
180
+ const BEST_COLOR = '#ee8a2a';
181
+
182
+ // D3 symbol generators for each tier
183
+ const SHAPE_SIZE = 48;
184
+ const SHAPE_SIZE_BEST = 80;
185
+ const shapeGenerators = {
186
+ 'Baseline': d3.symbol().type(d3.symbolCircle),
187
+ 'Tier 0': d3.symbol().type(d3.symbolDiamond),
188
+ 'Tier 1': d3.symbol().type(d3.symbolTriangle),
189
+ };
190
+
191
+ // ── Tooltip ──
192
+ let tip = container.querySelector('.d3-tooltip');
193
+ let tipInner;
194
+ if (!tip) {
195
+ tip = document.createElement('div'); tip.className = 'd3-tooltip';
196
+ tipInner = document.createElement('div'); tipInner.className = 'd3-tooltip__inner'; tipInner.style.textAlign = 'left';
197
+ tip.appendChild(tipInner); container.appendChild(tip);
198
+ } else { tipInner = tip.querySelector('.d3-tooltip__inner') || tip; }
199
+
200
+ function showTip(html, mx, my) {
201
+ tipInner.innerHTML = html;
202
+ const tipW = tip.offsetWidth || 200;
203
+ const tipH = tip.offsetHeight || 100;
204
+ const cw = container.clientWidth;
205
+ let tx = mx + 14, ty = my - 10;
206
+ if (tx + tipW > cw - 8) tx = mx - tipW - 14;
207
+ if (ty + tipH > container.clientHeight) ty = container.clientHeight - tipH - 4;
208
+ if (ty < 0) ty = 4;
209
+ tip.style.transform = `translate(${tx}px, ${ty}px)`;
210
+ tip.style.opacity = '1';
211
+ }
212
+ function hideTip() {
213
+ tip.style.opacity = '0';
214
+ tip.style.transform = 'translate(-9999px, -9999px)';
215
+ }
216
+
217
+ // ── SVG ──
218
+ const svg = d3.select(container).append('svg').attr('width', '100%').style('display', 'block');
219
+ const gRoot = svg.append('g');
220
+
221
+ // ── State ──
222
+ const state = { metric: 'throughput', sort: 'speedup' };
223
+
224
+ function sortedData() {
225
+ const d = [...DATA];
226
+ if (state.sort === 'speedup') d.sort((a, b) => b.bestSpeedup - a.bestSpeedup);
227
+ else if (state.sort === 'baseline') d.sort((a, b) => b.baseTps - a.baseTps);
228
+ else if (state.sort === 'family') {
229
+ d.sort((a, b) => {
230
+ const fi = FAMILIES.indexOf(a.family) - FAMILIES.indexOf(b.family);
231
+ return fi !== 0 ? fi : b.bestSpeedup - a.bestSpeedup;
232
+ });
233
+ }
234
+ return d;
235
+ }
236
+
237
+ // ── Layout ──
238
+ const margin = { top: 10, right: 62, bottom: 42, left: 148 };
239
+ let width = 800, height = 500;
240
+
241
+ function updateSize() {
242
+ width = container.clientWidth || 800;
243
+ height = Math.max(400, DATA.length * 28 + margin.top + margin.bottom);
244
+ svg.attr('width', width).attr('height', height);
245
+ gRoot.attr('transform', `translate(${margin.left},${margin.top})`);
246
+ return { iw: width - margin.left - margin.right, ih: height - margin.top - margin.bottom };
247
+ }
248
+
249
+ // ── Render ──
250
+ function render() {
251
+ const { iw, ih } = updateSize();
252
+ const data = sortedData();
253
+ const modelNames = data.map(d => d.model);
254
+
255
+ const yScale = d3.scaleBand().domain(modelNames).range([0, ih]).padding(0.35);
256
+ const bandH = yScale.bandwidth();
257
+
258
+ // X scale depends on metric
259
+ let xScale;
260
+ if (state.metric === 'throughput') {
261
+ const maxTps = d3.max(data, d => Math.max(d.baseTps, d.t0Tps, d.t1Tps));
262
+ xScale = d3.scaleLinear().domain([0, maxTps * 1.08]).range([0, iw]).nice();
263
+ } else {
264
+ const maxSpd = d3.max(data, d => Math.max(d.t0Speedup, d.t1Speedup));
265
+ const minSpd = d3.min(data, d => Math.min(d.t0Speedup, d.t1Speedup));
266
+ xScale = d3.scaleLinear().domain([Math.min(0.85, minSpd - 0.05), Math.max(2.05, maxSpd + 0.1)]).range([0, iw]).nice();
267
+ }
268
+
269
+ // ── Grid ──
270
+ const gridTicks = xScale.ticks(8);
271
+ gRoot.selectAll('.grid').data([0]).join('g').attr('class', 'grid')
272
+ .call(g => {
273
+ const lines = g.selectAll('line').data(gridTicks, d => d);
274
+ lines.join('line')
275
+ .attr('x1', d => xScale(d)).attr('x2', d => xScale(d))
276
+ .attr('y1', 0).attr('y2', ih)
277
+ .attr('stroke', 'var(--grid-color)').attr('stroke-width', 1);
278
+ });
279
+
280
+ // ── X axis ──
281
+ const xAxisGen = state.metric === 'throughput'
282
+ ? d3.axisBottom(xScale).ticks(8).tickFormat(d => d >= 1000 ? (d / 1000) + 'k' : d)
283
+ : d3.axisBottom(xScale).ticks(8).tickFormat(d => d.toFixed(1) + 'x');
284
+ gRoot.selectAll('.axis-x').data([0]).join('g').attr('class', 'axis-x')
285
+ .attr('transform', `translate(0,${ih})`)
286
+ .call(xAxisGen)
287
+ .call(g => {
288
+ g.selectAll('path, line').attr('stroke', 'var(--axis-color)');
289
+ g.selectAll('text').attr('fill', 'var(--tick-color)').style('font-size', '11px');
290
+ });
291
+
292
+ // ── X axis label ──
293
+ const xLabel = state.metric === 'throughput' ? 'Tokens per second per GPU' : 'Speedup vs baseline';
294
+ gRoot.selectAll('.x-label').data([0]).join('text').attr('class', 'x-label')
295
+ .attr('x', iw / 2).attr('y', ih + margin.bottom - 4)
296
+ .attr('text-anchor', 'middle').attr('fill', 'var(--muted-color)')
297
+ .attr('font-size', 11).text(xLabel);
298
+
299
+ // ── Y axis (model names) ──
300
+ gRoot.selectAll('.axis-y').data([0]).join('g').attr('class', 'axis-y')
301
+ .call(g => {
302
+ const labels = g.selectAll('text.y-label-text').data(data, d => d.model);
303
+ labels.join(
304
+ enter => enter.append('text').attr('class', 'y-label-text')
305
+ .attr('x', -8).attr('dy', '0.35em')
306
+ .attr('text-anchor', 'end'),
307
+ update => update,
308
+ exit => exit.remove()
309
+ )
310
+ .attr('y', d => yScale(d.model) + bandH / 2)
311
+ .attr('fill', d => familyColor(d.family))
312
+ .text(d => d.model);
313
+ });
314
+
315
+ // ── Reference line at 1.0x in speedup mode ──
316
+ gRoot.selectAll('.ref-line').data(state.metric === 'speedup' ? [1.0] : []).join('line')
317
+ .attr('class', 'ref-line')
318
+ .attr('x1', d => xScale(d)).attr('x2', d => xScale(d))
319
+ .attr('y1', 0).attr('y2', ih)
320
+ .attr('stroke', 'var(--text-color)').attr('stroke-width', 1.5)
321
+ .attr('stroke-dasharray', '4,3').attr('opacity', 0.5);
322
+
323
+ // ── Dumbbell rows ──
324
+ if (state.metric === 'throughput') {
325
+ renderThroughput(data, xScale, yScale, bandH, iw);
326
+ } else {
327
+ renderSpeedup(data, xScale, yScale, bandH, iw);
328
+ }
329
+ }
330
+
331
+ function renderThroughput(data, xScale, yScale, bandH, iw) {
332
+ // Remove speedup bars
333
+ gRoot.selectAll('.speedup-bar').remove();
334
+
335
+ // Connecting lines (baseline to rightmost point)
336
+ const lineData = data.map(d => ({
337
+ ...d,
338
+ x1: xScale(Math.min(d.baseTps, d.t0Tps, d.t1Tps)),
339
+ x2: xScale(Math.max(d.baseTps, d.t0Tps, d.t1Tps)),
340
+ cy: yScale(d.model) + bandH / 2,
341
+ }));
342
+ gRoot.selectAll('.conn-line').data(lineData, d => d.model).join('line')
343
+ .attr('class', 'conn-line')
344
+ .attr('x1', d => d.x1).attr('x2', d => d.x2)
345
+ .attr('y1', d => d.cy).attr('y2', d => d.cy)
346
+ .attr('stroke', d => familyColor(d.family))
347
+ .attr('stroke-width', 2).attr('opacity', 0.4);
348
+
349
+ // Dots: 3 per model (baseline, tier0, tier1)
350
+ const dots = [];
351
+ data.forEach(d => {
352
+ const cy = yScale(d.model) + bandH / 2;
353
+ dots.push({ ...d, tier: 'Baseline', val: d.baseTps, cx: xScale(d.baseTps), cy, isBest: d.bestTps === d.baseTps });
354
+ dots.push({ ...d, tier: 'Tier 0', val: d.t0Tps, cx: xScale(d.t0Tps), cy, isBest: d.bestTps === d.t0Tps && d.t0Tps !== d.baseTps });
355
+ dots.push({ ...d, tier: 'Tier 1', val: d.t1Tps, cx: xScale(d.t1Tps), cy, isBest: d.bestTps === d.t1Tps && d.t1Tps !== d.t0Tps && d.t1Tps !== d.baseTps });
356
+ });
357
+
358
+ gRoot.selectAll('.dot').data(dots, d => d.model + '-' + d.tier).join('path')
359
+ .attr('class', 'dot')
360
+ .attr('d', d => shapeGenerators[d.tier].size(d.isBest ? SHAPE_SIZE_BEST : SHAPE_SIZE)())
361
+ .attr('transform', d => `translate(${d.cx},${d.cy})`)
362
+ .attr('fill', d => d.isBest ? BEST_COLOR : familyColor(d.family))
363
+ .attr('stroke', d => d.isBest ? 'var(--text-color)' : 'none')
364
+ .attr('stroke-width', d => d.isBest ? 1.5 : 0)
365
+ .attr('opacity', 0.9)
366
+ .attr('cursor', 'pointer')
367
+ .on('mouseenter', function (event, d) {
368
+ d3.select(this).attr('opacity', 1);
369
+ const [mx, my] = d3.pointer(event, container);
370
+ showTip(buildTooltip(d), mx, my);
371
+ })
372
+ .on('mousemove', function (event) {
373
+ const [mx, my] = d3.pointer(event, container);
374
+ tip.style.transform = `translate(${mx + 14}px, ${my - 10}px)`;
375
+ })
376
+ .on('mouseleave', function () {
377
+ d3.select(this).attr('opacity', 0.9);
378
+ hideTip();
379
+ });
380
+
381
+ // Speedup annotation on right
382
+ gRoot.selectAll('.speedup-label').data(data, d => d.model).join('text')
383
+ .attr('class', 'speedup-label')
384
+ .attr('x', iw + 6)
385
+ .attr('y', d => yScale(d.model) + bandH / 2)
386
+ .attr('dy', '0.35em')
387
+ .attr('fill', d => d.bestSpeedup >= 1.3 ? BEST_COLOR : 'var(--muted-color)')
388
+ .attr('font-weight', d => d.bestSpeedup >= 1.3 ? 700 : 400)
389
+ .text(d => d.bestSpeedup.toFixed(2) + 'x');
390
+ }
391
+
392
+ function renderSpeedup(data, xScale, yScale, bandH, iw) {
393
+ // Remove throughput elements
394
+ gRoot.selectAll('.conn-line').remove();
395
+ gRoot.selectAll('.dot').remove();
396
+
397
+ // Two bars per model: Tier 0 speedup, Tier 1 speedup
398
+ const barH = bandH * 0.38;
399
+ const barData = [];
400
+ data.forEach(d => {
401
+ const baseY = yScale(d.model);
402
+ barData.push({ ...d, tier: 'Tier 0', val: d.t0Speedup, y: baseY + bandH * 0.12, h: barH });
403
+ barData.push({ ...d, tier: 'Tier 1', val: d.t1Speedup, y: baseY + bandH * 0.5, h: barH });
404
+ });
405
+
406
+ const oneX = xScale(1.0);
407
+ gRoot.selectAll('.speedup-bar').data(barData, d => d.model + '-' + d.tier).join('rect')
408
+ .attr('class', 'speedup-bar')
409
+ .attr('x', d => d.val >= 1.0 ? oneX : xScale(d.val))
410
+ .attr('y', d => d.y)
411
+ .attr('width', d => Math.abs(xScale(d.val) - oneX))
412
+ .attr('height', d => d.h)
413
+ .attr('rx', 2)
414
+ .attr('fill', d => familyColor(d.family))
415
+ .attr('opacity', d => d.tier === 'Tier 0' ? 0.9 : 0.55)
416
+ .attr('stroke', d => d.val < 1.0 ? '#e05252' : 'none')
417
+ .attr('stroke-width', d => d.val < 1.0 ? 1 : 0)
418
+ .attr('cursor', 'pointer')
419
+ .on('mouseenter', function (event, d) {
420
+ d3.select(this).attr('opacity', 1);
421
+ const [mx, my] = d3.pointer(event, container);
422
+ showTip(buildTooltip(d), mx, my);
423
+ })
424
+ .on('mousemove', function (event) {
425
+ const [mx, my] = d3.pointer(event, container);
426
+ tip.style.transform = `translate(${mx + 14}px, ${my - 10}px)`;
427
+ })
428
+ .on('mouseleave', function (event, d) {
429
+ d3.select(this).attr('opacity', d.tier === 'Tier 0' ? 0.9 : 0.55);
430
+ hideTip();
431
+ });
432
+
433
+ // Speedup annotation on right
434
+ gRoot.selectAll('.speedup-label').data(data, d => d.model).join('text')
435
+ .attr('class', 'speedup-label')
436
+ .attr('x', iw + 6)
437
+ .attr('y', d => yScale(d.model) + bandH / 2)
438
+ .attr('dy', '0.35em')
439
+ .attr('fill', d => d.bestSpeedup >= 1.3 ? BEST_COLOR : 'var(--muted-color)')
440
+ .attr('font-weight', d => d.bestSpeedup >= 1.3 ? 700 : 400)
441
+ .text(d => d.bestSpeedup.toFixed(2) + 'x');
442
+ }
443
+
444
+ function buildTooltip(d) {
445
+ const fmt = (v) => v.toLocaleString();
446
+ const spd = (v) => v.toFixed(2) + 'x';
447
+ const cls = (v) => v < 1.0 ? 'tip-regression' : (v >= 1.3 ? 'tip-best' : 'tip-val');
448
+ return `<div style="margin-bottom:4px"><strong>${d.model}</strong> <span class="tip-label">(${d.family})</span></div>`
449
+ + `<div><span class="tip-label">Baseline:</span> <span class="tip-val">${fmt(d.baseTps)}</span> tps/gpu <span class="tip-label">(tp=${d.baseTp})</span></div>`
450
+ + `<div><span class="tip-label">Tier 0:</span> <span class="${cls(d.t0Speedup)}">${fmt(d.t0Tps)}</span> tps/gpu <span class="${cls(d.t0Speedup)}">${spd(d.t0Speedup)}</span></div>`
451
+ + `<div style="font-size:10px;color:var(--muted-color);margin-left:8px">${d.t0Params}</div>`
452
+ + `<div><span class="tip-label">Tier 1:</span> <span class="${cls(d.t1Speedup)}">${fmt(d.t1Tps)}</span> tps/gpu <span class="${cls(d.t1Speedup)}">${spd(d.t1Speedup)}</span></div>`
453
+ + `<div style="font-size:10px;color:var(--muted-color);margin-left:8px">${d.t1Params}</div>`
454
+ + `<div style="margin-top:4px;border-top:1px solid var(--border-color);padding-top:4px"><span class="tip-label">Best:</span> <span class="tip-best">${fmt(d.bestTps)} tps/gpu (${spd(d.bestSpeedup)})</span></div>`
455
+ + `<div style="font-size:10px;color:var(--muted-color);margin-left:8px">${d.bestParams}</div>`;
456
+ }
457
+
458
+ // ── Controls ──
459
+ const controls = document.createElement('div'); controls.className = 'controls';
460
+
461
+ // Metric select
462
+ const metricGroup = document.createElement('div'); metricGroup.className = 'control-group';
463
+ const metricLabel = document.createElement('label'); metricLabel.textContent = 'Metric'; metricLabel.setAttribute('for', 'metric-sel-optsweep');
464
+ const metricSel = document.createElement('select'); metricSel.id = 'metric-sel-optsweep';
465
+ [['throughput', 'Throughput (tps/gpu)'], ['speedup', 'Speedup']].forEach(([v, t]) => {
466
+ const o = document.createElement('option'); o.value = v; o.textContent = t; metricSel.appendChild(o);
467
+ });
468
+ metricSel.value = state.metric;
469
+ metricSel.addEventListener('change', () => { state.metric = metricSel.value; render(); });
470
+ metricGroup.appendChild(metricLabel); metricGroup.appendChild(metricSel);
471
+
472
+ // Sort select
473
+ const sortGroup = document.createElement('div'); sortGroup.className = 'control-group';
474
+ const sortLabel = document.createElement('label'); sortLabel.textContent = 'Sort'; sortLabel.setAttribute('for', 'sort-sel-optsweep');
475
+ const sortSel = document.createElement('select'); sortSel.id = 'sort-sel-optsweep';
476
+ [['speedup', 'By Best Speedup'], ['baseline', 'By Baseline Throughput'], ['family', 'By Model Family']].forEach(([v, t]) => {
477
+ const o = document.createElement('option'); o.value = v; o.textContent = t; sortSel.appendChild(o);
478
+ });
479
+ sortSel.value = state.sort;
480
+ sortSel.addEventListener('change', () => { state.sort = sortSel.value; render(); });
481
+ sortGroup.appendChild(sortLabel); sortGroup.appendChild(sortSel);
482
+
483
+ controls.appendChild(metricGroup); controls.appendChild(sortGroup);
484
+ container.appendChild(controls);
485
+
486
+ // ── Legend ──
487
+ const legend = document.createElement('div'); legend.className = 'legend';
488
+
489
+ // Tier shapes section
490
+ const tierTitle = document.createElement('div'); tierTitle.className = 'legend-title'; tierTitle.textContent = 'Legend';
491
+ legend.appendChild(tierTitle);
492
+ const tierSection = document.createElement('div'); tierSection.className = 'legend-section';
493
+ TIERS.forEach(tier => {
494
+ const item = document.createElement('span'); item.className = 'item';
495
+ // SVG swatch for shape
496
+ const svgNS = 'http://www.w3.org/2000/svg';
497
+ const shapeSvg = document.createElementNS(svgNS, 'svg');
498
+ shapeSvg.setAttribute('width', '14'); shapeSvg.setAttribute('height', '14');
499
+ shapeSvg.setAttribute('viewBox', '-8 -8 16 16');
500
+ shapeSvg.style.display = 'block';
501
+ const path = document.createElementNS(svgNS, 'path');
502
+ path.setAttribute('d', shapeGenerators[tier].size(SHAPE_SIZE)());
503
+ path.setAttribute('fill', 'var(--text-color)');
504
+ shapeSvg.appendChild(path);
505
+ const swWrap = document.createElement('span'); swWrap.className = 'shape-swatch'; swWrap.appendChild(shapeSvg);
506
+ const txt = document.createElement('span'); txt.textContent = tier;
507
+ item.appendChild(swWrap); item.appendChild(txt); tierSection.appendChild(item);
508
+ });
509
+ // "Best" indicator
510
+ const bestItem = document.createElement('span'); bestItem.className = 'item';
511
+ const bestSw = document.createElement('span'); bestSw.className = 'swatch';
512
+ bestSw.style.background = BEST_COLOR; bestSw.style.border = '1.5px solid var(--text-color)';
513
+ const bestTxt = document.createElement('span'); bestTxt.textContent = 'Best';
514
+ bestItem.appendChild(bestSw); bestItem.appendChild(bestTxt); tierSection.appendChild(bestItem);
515
+ legend.appendChild(tierSection);
516
+
517
+ // Family colors section
518
+ const famSection = document.createElement('div'); famSection.className = 'legend-section'; famSection.style.marginTop = '4px';
519
+ FAMILIES.forEach((fam, i) => {
520
+ const item = document.createElement('span'); item.className = 'item';
521
+ const sw = document.createElement('span'); sw.className = 'swatch'; sw.style.background = familyPalette[i];
522
+ const txt = document.createElement('span'); txt.textContent = fam;
523
+ item.appendChild(sw); item.appendChild(txt); famSection.appendChild(item);
524
+ });
525
+ legend.appendChild(famSection);
526
+ container.appendChild(legend);
527
+
528
+ // ── Initial render + resize ──
529
+ render();
530
+ if (window.ResizeObserver) {
531
+ new ResizeObserver(() => render()).observe(container);
532
+ } else {
533
+ window.addEventListener('resize', render);
534
+ }
535
+ };
536
+
537
+ if (document.readyState === 'loading') {
538
+ document.addEventListener('DOMContentLoaded', () => ensureD3(bootstrap), { once: true });
539
+ } else {
540
+ ensureD3(bootstrap);
541
+ }
542
+ })();
543
+ </script>