joelniklaus HF Staff commited on
Commit
02df370
ยท
1 Parent(s): 0b70925

various improvements to the inference throughput visualization

Browse files
app/src/content/embeds/inference-throughput.html CHANGED
@@ -47,8 +47,8 @@
47
  --slider-end: #facc15;
48
  --slider-rest: #334155;
49
  }
50
- .throughput-strip { color: #e2e8f0; }
51
- .throughput-strip .tps { color: #cbd5e1; }
52
  }
53
 
54
  * { margin: 0; padding: 0; box-sizing: border-box; }
@@ -96,6 +96,14 @@
96
  background: transparent;
97
  }
98
  .slider-area { position: relative; width: 100%; margin-bottom: 8px; z-index: 9999; }
 
 
 
 
 
 
 
 
99
  .slider-area input[type=range] { position: relative; z-index: 3; width: 100%; margin: 0; display: block; -webkit-appearance: none; appearance: none; height: 8px; border-radius: 4px; outline: none; cursor: pointer; }
100
  .slider-area input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 2px solid var(--brand); cursor: pointer; margin-top: -5px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
101
  .slider-area input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 2px solid var(--brand); cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
@@ -152,19 +160,25 @@
152
  .landmark-row:has(.landmark:hover) { z-index: 99999; position: relative; }
153
  .landmark:hover .tooltip { display: block; }
154
 
155
- .throughput-strip {
156
  position: absolute;
157
  bottom: 4px;
158
  left: 10px;
159
- width: calc(32% - 10px);
160
- min-width: 160px;
161
- padding: 0;
162
- text-align: center;
163
  font-size: 11px;
164
- color: #1f2937;
165
  font-weight: 700;
166
  font-variant-numeric: tabular-nums;
167
  line-height: 1.2;
 
 
 
 
 
 
 
168
  }
169
  .throughput-strip .tps {
170
  color: var(--text-muted);
@@ -172,61 +186,32 @@
172
  }
173
 
174
  .output-panel {
175
- position: absolute;
176
- right: 10px;
177
- top: calc(50%);
178
- transform: translateY(-50%);
179
- z-index: 4;
180
- pointer-events: none;
181
  display: flex;
182
- flex-direction: column;
183
- gap: 2px;
184
- padding: 7px 8px;
185
- border-radius: 8px;
186
- border: 1px solid var(--border);
187
- background: color-mix(in srgb, var(--surface) 88%, transparent);
188
- box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
189
  }
190
  .output-heading {
191
- text-align: left;
192
- font-size: 10px;
193
  color: var(--text-muted);
194
  text-transform: uppercase;
195
- letter-spacing: 0.6px;
196
  font-weight: 700;
197
- margin-bottom: 1px;
198
- }
199
- .output-stats {
200
- display: grid;
201
- grid-template-columns: minmax(0, 1fr) auto;
202
- column-gap: 9px;
203
- row-gap: 2px;
204
- align-items: center;
205
- white-space: nowrap;
206
- }
207
- .output-line {
208
- display: contents;
209
  }
210
  .output-num {
211
- text-align: right;
212
- font-size: 32px;
213
- line-height: 1;
214
  font-weight: 700;
215
  color: var(--brand);
216
  font-variant-numeric: tabular-nums;
217
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
 
218
  }
219
  .output-unit {
220
- display: block;
221
- min-width: 3.2ch;
222
- text-align: left;
223
- font-size: 12px;
224
  color: var(--text-muted);
225
  font-weight: 700;
226
- letter-spacing: 0.2px;
227
  }
228
  .output-unit-emoji {
229
- font-size: 17px;
230
  line-height: 1;
231
  }
232
 
@@ -249,25 +234,15 @@
249
  .canvas-row { flex-direction: column; }
250
  .canvas-row .side-panel { align-items: flex-start; }
251
  .landmark .name { font-size: 9px; }
252
- .throughput-strip {
253
- width: auto;
254
- min-width: 0;
255
- left: 8px;
256
- font-size: 10px;
257
- text-align: center;
258
- }
259
- .output-panel {
260
  right: 6px;
261
- top: auto;
262
- bottom: 6px;
263
- transform: none;
264
- padding: 8px 10px;
265
- gap: 6px;
266
  }
267
- .output-num { font-size: 30px; }
268
- .output-unit { font-size: 11px; min-width: 3ch; }
269
- .output-unit-emoji { font-size: 16px; }
270
- .output-heading { font-size: 10px; }
271
  .datasets { max-width: 100%; min-width: 0; }
272
  .dataset-bars { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; }
273
  .dataset-item { font-size: 12px; }
@@ -277,6 +252,7 @@
277
  <body>
278
  <div class="viz">
279
  <div class="slider-area">
 
280
  <div class="landmark-row top" id="row-a2"></div>
281
  <div class="landmark-row top" id="row-a1"></div>
282
  <input type="range" id="gpus" min="0" max="1" step="0.001" value="0">
@@ -301,22 +277,18 @@
301
  <div class="canvas-stage">
302
  <canvas id="c"></canvas>
303
  </div>
304
- <div class="output-panel">
305
- <div class="output-heading">Generated</div>
306
- <div class="output-stats">
307
- <div class="output-line">
308
- <span class="output-num" id="totalTokensNum">0</span>
309
- <span class="output-unit output-unit-text">toks</span>
310
- </div>
311
- <div class="output-line">
312
- <span class="output-num" id="totalItemNum">0</span>
313
- <span class="output-unit output-unit-emoji" id="totalItemUnit">๐Ÿ“„</span>
314
- </div>
315
  </div>
316
- </div>
317
- <div class="throughput-strip">
318
- <span id="booksRate">0 books/sec</span>
319
- <span class="tps" id="tpsInline">(0 TPS)</span>
320
  </div>
321
  </div>
322
  <div class="datasets">
@@ -421,6 +393,7 @@
421
 
422
  const modelSelect = document.getElementById('model');
423
  const gpuSlider = document.getElementById('gpus');
 
424
  const booksRateEl = document.getElementById('booksRate');
425
  const tpsInlineEl = document.getElementById('tpsInline');
426
  const totalTokensNumEl = document.getElementById('totalTokensNum');
@@ -460,25 +433,13 @@
460
  + themeTokens.sliderRest + ' ' + val + '%)';
461
  }
462
  updateSliderGradient();
463
- gpuSlider.addEventListener('input', updateSliderGradient);
 
464
 
465
  function formatGpuLabel(gpus) {
466
- const formatCompactCount = (count) => {
467
- if (count >= 1_000_000) {
468
- return (count / 1_000_000).toFixed(count >= 10_000_000 ? 0 : 1) + 'M';
469
- }
470
- if (count >= 1000) {
471
- return (count / 1000).toFixed(count >= 10000 ? 0 : 1) + 'K';
472
- }
473
- return count.toLocaleString();
474
- };
475
-
476
- if (gpus < GPUS_PER_NODE) return gpus + ' GPU' + (gpus > 1 ? 's' : '');
477
- const nodes = Math.round(gpus / GPUS_PER_NODE);
478
- const gpuStr = formatCompactCount(gpus);
479
- if (nodes === 1) return '1 node (' + gpuStr + ' GPUs)';
480
- const nodeStr = formatCompactCount(nodes);
481
- return nodeStr + ' nodes (' + gpuStr + ' GPUs)';
482
  }
483
 
484
  const rowEls = { a2: document.getElementById('row-a2'), a1: document.getElementById('row-a1'),
@@ -498,7 +459,7 @@
498
  el.innerHTML = isAbove
499
  ? '<div class="name">' + lm.name + '</div><div class="tick"></div>' + tip
500
  : '<div class="tick"></div><div class="name">' + lm.name + '</div>' + tip;
501
- el.addEventListener('click', () => { gpuSlider.value = gpusToSlider(lm.gpus); updateSliderGradient(); resetCountdown(); });
502
  rowEls[lm.row].appendChild(el);
503
  }
504
  TRAINING_RUNS.forEach(addLandmark);
@@ -600,16 +561,8 @@
600
  const aw = hwCanvas.width - 2 * pad, ax = pad;
601
  const level = getHardwareLevel(gpus);
602
 
603
- // GPU count label pinned to top
604
- ctx.fillStyle = themeTokens.brand;
605
- ctx.font = 'bold 22px system-ui, sans-serif';
606
- ctx.textAlign = 'center'; ctx.textBaseline = 'top';
607
- ctx.fillText(formatGpuLabel(gpus), ax + aw / 2, 6);
608
-
609
- // Hardware illustration centered vertically in remaining space (shifted down)
610
- const labelBottom = 32;
611
- const ah = hwCanvas.height * 0.65;
612
- const ay = labelBottom + (hwCanvas.height - labelBottom - ah) / 2 + hwCanvas.height * 0.04;
613
  ctx.textAlign = 'start'; ctx.textBaseline = 'alphabetic';
614
 
615
  if (level === 'gpu') drawGpuGrid(gpus, ax, ay, aw, ah);
@@ -822,7 +775,6 @@
822
 
823
  const EMOJI = { page: '\u{1F4C4}', book: '\u{1F4D6}', shelf: '\u{1F4DA}' };
824
  const EMOJI_SIZE = { page: 28, book: 34, shelf: 40 };
825
- const MAX_FLOATING = 150;
826
 
827
  // Pre-render emojis at multiple scales to offscreen canvases
828
  const emojiCache = {};
@@ -840,19 +792,22 @@
840
  return off;
841
  }
842
 
843
- function drawItem(p, now, W) {
844
- const fadeStart = W * 0.9;
845
- const alpha = p.x > fadeStart ? 1 - (p.x - fadeStart) / (W - fadeStart) : 1;
846
  const off = getEmojiCanvas(p.type, p.scale);
847
  const bobY = p.y + Math.sin(now / 600 + p.bobPhase) * p.bobAmp;
848
  const angle = Math.sin(now / 400 + p.wobblePhase) * p.wobbleAmp;
849
- ctx.globalAlpha = alpha;
850
- ctx.save();
851
- ctx.translate(p.x + off.width / 2, bobY + off.height / 2);
852
- ctx.rotate(angle);
853
- ctx.drawImage(off, -off.width / 2, -off.height / 2);
854
- ctx.restore();
855
- ctx.globalAlpha = 1;
 
 
 
 
 
856
  }
857
 
858
  function spawnItem() {
@@ -869,12 +824,13 @@
869
  const scale = 0.85 + Math.random() * 0.3;
870
  const bobAmp = 3 + Math.random() * 5;
871
  const bobPhase = Math.random() * Math.PI * 2;
872
- const wobbleAmp = mode === 'page' ? 0.08 + Math.random() * 0.12 : 0.04 + Math.random() * 0.06;
873
  const wobblePhase = Math.random() * Math.PI * 2;
874
  const depthSpeed = (bs + Math.random() * bs) * (0.7 + scale * 0.6);
 
875
  floatingItems.push({
876
  x: spawnX + Math.random() * 20, y, speed: depthSpeed,
877
- type: mode, tokens, scale, bobAmp, bobPhase, wobbleAmp, wobblePhase
878
  });
879
  }
880
 
@@ -902,22 +858,33 @@
902
  const pagesPerShelf = PAGES_PER_BOOK * BOOKS_PER_SHELF;
903
  const spawnRate = mode === 'shelf' ? Math.min(pps / pagesPerShelf, 60) : mode === 'book' ? Math.min(pps / PAGES_PER_BOOK, 120) : Math.min(pps, 400);
904
  spawnAccum += spawnRate * dt;
905
- while (spawnAccum >= 1 && floatingItems.length < MAX_FLOATING) { spawnItem(); spawnAccum -= 1; }
906
- if (floatingItems.length >= MAX_FLOATING) spawnAccum = 0;
 
 
 
907
 
 
908
  let writeIdx = 0;
909
  for (let i = 0; i < floatingItems.length; i++) {
910
  const p = floatingItems[i];
911
  p.x += p.speed;
912
- if (p.x > W + 40) {
913
- totalTokens += p.tokens;
914
- continue;
915
- }
916
- drawItem(p, now, W);
917
  floatingItems[writeIdx++] = p;
918
  }
919
  floatingItems.length = writeIdx;
920
 
 
 
 
 
 
 
 
 
 
 
 
921
  drawHardware();
922
 
923
  // Throttle DOM metric updates to ~4 Hz to prevent flickering
 
47
  --slider-end: #facc15;
48
  --slider-rest: #334155;
49
  }
50
+ .bottom-strip { color: #e2e8f0; }
51
+ .bottom-strip .tps { color: #cbd5e1; }
52
  }
53
 
54
  * { margin: 0; padding: 0; box-sizing: border-box; }
 
96
  background: transparent;
97
  }
98
  .slider-area { position: relative; width: 100%; margin-bottom: 8px; z-index: 9999; }
99
+ .gpu-label {
100
+ text-align: center;
101
+ font-size: 14px;
102
+ font-weight: 700;
103
+ color: var(--brand);
104
+ margin-bottom: 2px;
105
+ font-variant-numeric: tabular-nums;
106
+ }
107
  .slider-area input[type=range] { position: relative; z-index: 3; width: 100%; margin: 0; display: block; -webkit-appearance: none; appearance: none; height: 8px; border-radius: 4px; outline: none; cursor: pointer; }
108
  .slider-area input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 2px solid var(--brand); cursor: pointer; margin-top: -5px; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
109
  .slider-area input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--bg); border: 2px solid var(--brand); cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.3); }
 
160
  .landmark-row:has(.landmark:hover) { z-index: 99999; position: relative; }
161
  .landmark:hover .tooltip { display: block; }
162
 
163
+ .bottom-strip {
164
  position: absolute;
165
  bottom: 4px;
166
  left: 10px;
167
+ right: 10px;
168
+ display: flex;
169
+ align-items: center;
170
+ justify-content: space-between;
171
  font-size: 11px;
 
172
  font-weight: 700;
173
  font-variant-numeric: tabular-nums;
174
  line-height: 1.2;
175
+ color: #1f2937;
176
+ pointer-events: none;
177
+ z-index: 4;
178
+ }
179
+ .throughput-strip {
180
+ padding: 0;
181
+ text-align: center;
182
  }
183
  .throughput-strip .tps {
184
  color: var(--text-muted);
 
186
  }
187
 
188
  .output-panel {
 
 
 
 
 
 
189
  display: flex;
190
+ align-items: center;
191
+ gap: 6px;
192
+ text-align: center;
 
 
 
 
193
  }
194
  .output-heading {
 
 
195
  color: var(--text-muted);
196
  text-transform: uppercase;
197
+ letter-spacing: 0.4px;
198
  font-weight: 700;
199
+ font-size: 10px;
 
 
 
 
 
 
 
 
 
 
 
200
  }
201
  .output-num {
 
 
 
202
  font-weight: 700;
203
  color: var(--brand);
204
  font-variant-numeric: tabular-nums;
205
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
206
+ font-size: 11px;
207
  }
208
  .output-unit {
209
+ font-size: 11px;
 
 
 
210
  color: var(--text-muted);
211
  font-weight: 700;
 
212
  }
213
  .output-unit-emoji {
214
+ font-size: 13px;
215
  line-height: 1;
216
  }
217
 
 
234
  .canvas-row { flex-direction: column; }
235
  .canvas-row .side-panel { align-items: flex-start; }
236
  .landmark .name { font-size: 9px; }
237
+ .bottom-strip {
238
+ left: 6px;
 
 
 
 
 
 
239
  right: 6px;
240
+ font-size: 10px;
 
 
 
 
241
  }
242
+ .output-num { font-size: 10px; }
243
+ .output-unit { font-size: 10px; }
244
+ .output-unit-emoji { font-size: 12px; }
245
+ .output-heading { font-size: 9px; }
246
  .datasets { max-width: 100%; min-width: 0; }
247
  .dataset-bars { flex-direction: row; flex-wrap: wrap; gap: 4px 12px; }
248
  .dataset-item { font-size: 12px; }
 
252
  <body>
253
  <div class="viz">
254
  <div class="slider-area">
255
+ <div class="gpu-label" id="gpuLabel">1 GPU</div>
256
  <div class="landmark-row top" id="row-a2"></div>
257
  <div class="landmark-row top" id="row-a1"></div>
258
  <input type="range" id="gpus" min="0" max="1" step="0.001" value="0">
 
277
  <div class="canvas-stage">
278
  <canvas id="c"></canvas>
279
  </div>
280
+ <div class="bottom-strip">
281
+ <div class="throughput-strip">
282
+ <span id="booksRate">0 books/sec</span>
283
+ <span class="tps" id="tpsInline">(0 TPS)</span>
284
+ </div>
285
+ <div class="output-panel">
286
+ <span class="output-heading">Generated</span>
287
+ <span class="output-num" id="totalTokensNum">0</span>
288
+ <span class="output-unit output-unit-text">toks</span>
289
+ <span class="output-num" id="totalItemNum">0</span>
290
+ <span class="output-unit output-unit-emoji" id="totalItemUnit">๐Ÿ“„</span>
291
  </div>
 
 
 
 
292
  </div>
293
  </div>
294
  <div class="datasets">
 
393
 
394
  const modelSelect = document.getElementById('model');
395
  const gpuSlider = document.getElementById('gpus');
396
+ const gpuLabelEl = document.getElementById('gpuLabel');
397
  const booksRateEl = document.getElementById('booksRate');
398
  const tpsInlineEl = document.getElementById('tpsInline');
399
  const totalTokensNumEl = document.getElementById('totalTokensNum');
 
433
  + themeTokens.sliderRest + ' ' + val + '%)';
434
  }
435
  updateSliderGradient();
436
+ function updateGpuLabel() { gpuLabelEl.textContent = formatGpuLabel(getGpuCount()); }
437
+ gpuSlider.addEventListener('input', () => { updateSliderGradient(); updateGpuLabel(); });
438
 
439
  function formatGpuLabel(gpus) {
440
+ if (gpus >= 1_000_000) return (gpus / 1_000_000).toFixed(gpus >= 10_000_000 ? 0 : 1) + 'M GPUs';
441
+ if (gpus >= 1000) return (gpus / 1000).toFixed(gpus >= 10000 ? 0 : 1) + 'K GPUs';
442
+ return gpus + ' GPU' + (gpus > 1 ? 's' : '');
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  }
444
 
445
  const rowEls = { a2: document.getElementById('row-a2'), a1: document.getElementById('row-a1'),
 
459
  el.innerHTML = isAbove
460
  ? '<div class="name">' + lm.name + '</div><div class="tick"></div>' + tip
461
  : '<div class="tick"></div><div class="name">' + lm.name + '</div>' + tip;
462
+ el.addEventListener('click', () => { gpuSlider.value = gpusToSlider(lm.gpus); updateSliderGradient(); updateGpuLabel(); resetCountdown(); });
463
  rowEls[lm.row].appendChild(el);
464
  }
465
  TRAINING_RUNS.forEach(addLandmark);
 
561
  const aw = hwCanvas.width - 2 * pad, ax = pad;
562
  const level = getHardwareLevel(gpus);
563
 
564
+ const ah = hwCanvas.height * 0.75;
565
+ const ay = (hwCanvas.height - ah) / 2;
 
 
 
 
 
 
 
 
566
  ctx.textAlign = 'start'; ctx.textBaseline = 'alphabetic';
567
 
568
  if (level === 'gpu') drawGpuGrid(gpus, ax, ay, aw, ah);
 
775
 
776
  const EMOJI = { page: '\u{1F4C4}', book: '\u{1F4D6}', shelf: '\u{1F4DA}' };
777
  const EMOJI_SIZE = { page: 28, book: 34, shelf: 40 };
 
778
 
779
  // Pre-render emojis at multiple scales to offscreen canvases
780
  const emojiCache = {};
 
792
  return off;
793
  }
794
 
795
+ function drawItem(p, now, fadeStart, fadeRange) {
 
 
796
  const off = getEmojiCanvas(p.type, p.scale);
797
  const bobY = p.y + Math.sin(now / 600 + p.bobPhase) * p.bobAmp;
798
  const angle = Math.sin(now / 400 + p.wobblePhase) * p.wobbleAmp;
799
+ const needsAlpha = p.x > fadeStart;
800
+ if (needsAlpha) ctx.globalAlpha = 1 - (p.x - fadeStart) / fadeRange;
801
+ if (Math.abs(angle) < 0.01) {
802
+ ctx.drawImage(off, p.x, bobY);
803
+ } else {
804
+ ctx.save();
805
+ ctx.translate(p.x + off.width / 2, bobY + off.height / 2);
806
+ ctx.rotate(angle);
807
+ ctx.drawImage(off, -off.width / 2, -off.height / 2);
808
+ ctx.restore();
809
+ }
810
+ if (needsAlpha) ctx.globalAlpha = 1;
811
  }
812
 
813
  function spawnItem() {
 
824
  const scale = 0.85 + Math.random() * 0.3;
825
  const bobAmp = 3 + Math.random() * 5;
826
  const bobPhase = Math.random() * Math.PI * 2;
827
+ const wobbleAmp = mode === 'page' ? 0.15 + Math.random() * 0.25 : 0.08 + Math.random() * 0.15;
828
  const wobblePhase = Math.random() * Math.PI * 2;
829
  const depthSpeed = (bs + Math.random() * bs) * (0.7 + scale * 0.6);
830
+ totalTokens += tokens;
831
  floatingItems.push({
832
  x: spawnX + Math.random() * 20, y, speed: depthSpeed,
833
+ type: mode, scale, bobAmp, bobPhase, wobbleAmp, wobblePhase
834
  });
835
  }
836
 
 
858
  const pagesPerShelf = PAGES_PER_BOOK * BOOKS_PER_SHELF;
859
  const spawnRate = mode === 'shelf' ? Math.min(pps / pagesPerShelf, 60) : mode === 'book' ? Math.min(pps / PAGES_PER_BOOK, 120) : Math.min(pps, 400);
860
  spawnAccum += spawnRate * dt;
861
+ while (spawnAccum >= 1) { spawnItem(); spawnAccum -= 1; }
862
+
863
+ const fadeStart = W * 0.9;
864
+ const fadeRange = W - fadeStart;
865
+ const cullX = W + 40;
866
 
867
+ // Update positions and cull off-screen items
868
  let writeIdx = 0;
869
  for (let i = 0; i < floatingItems.length; i++) {
870
  const p = floatingItems[i];
871
  p.x += p.speed;
872
+ if (p.x > cullX) continue;
 
 
 
 
873
  floatingItems[writeIdx++] = p;
874
  }
875
  floatingItems.length = writeIdx;
876
 
877
+ // Sort by cache key so repeated drawImage calls hit the same source texture
878
+ floatingItems.sort((a, b) => {
879
+ const ka = EMOJI_SIZE[a.type] * 100 + Math.round(a.scale * 30);
880
+ const kb = EMOJI_SIZE[b.type] * 100 + Math.round(b.scale * 30);
881
+ return ka - kb;
882
+ });
883
+
884
+ for (let i = 0; i < floatingItems.length; i++) {
885
+ drawItem(floatingItems[i], now, fadeStart, fadeRange);
886
+ }
887
+
888
  drawHardware();
889
 
890
  // Throttle DOM metric updates to ~4 Hz to prevent flickering