joelniklaus HF Staff commited on
Commit
6af5a04
·
1 Parent(s): 12e3370

refactor inference throughput visualization more

Browse files
app/src/content/embeds/inference-throughput-compare.html CHANGED
@@ -697,7 +697,11 @@
697
  el.className = 'dataset-item';
698
  el.innerHTML = '<span class="ds-check">\u23f3</span><span class="ds-name">' + ds.name + '</span><span class="ds-time">-</span><span class="ds-size">(' + formatNumInt(ds.tokens) + ' toks)</span><div class="ds-tip">' + ds.desc + '</div>';
699
  datasetBarsEl.appendChild(el);
700
- return el;
 
 
 
 
701
  });
702
 
703
  function resizeCanvas() {
@@ -733,7 +737,11 @@
733
  spawnAccum = 0;
734
  hwDirty = true;
735
  dsDone = DATASETS.map(() => false);
736
- dsEls.forEach(el => { el.classList.remove('done'); el.querySelector('.ds-check').textContent = '\u23f3'; el.querySelector('.ds-time').textContent = '-'; });
 
 
 
 
737
  }
738
 
739
  gpuSlider.addEventListener('input', () => { reset(); });
@@ -1084,11 +1092,11 @@
1084
  const remaining = DATASETS[i].tokens - totalTokens;
1085
  if (remaining <= 0) {
1086
  dsDone[i] = true;
1087
- dsEls[i].classList.add('done');
1088
- dsEls[i].querySelector('.ds-check').textContent = '\u2705';
1089
- dsEls[i].querySelector('.ds-time').textContent = 'done';
1090
  } else {
1091
- dsEls[i].querySelector('.ds-time').textContent = formatDuration(remaining / tps);
1092
  }
1093
  }
1094
  }
@@ -1096,25 +1104,44 @@
1096
  return { frame, updateMetrics, reset, getTps };
1097
  }
1098
 
1099
- const instA = createInstance('cA', 'modelA', 'datasetBarsA', {
1100
- booksRate: $('booksRateA'),
1101
- tpsInline: $('tpsInlineA'),
1102
- totalTokensNum: $('totalTokensNumA'),
1103
- totalItemNum: $('totalItemNumA'),
1104
- totalItemUnit: $('totalItemUnitA'),
1105
- });
1106
-
1107
- const instances = [instA];
1108
- let instB = null;
1109
  if (isCompareMode) {
1110
- instB = createInstance('cB', 'modelB', 'datasetBarsB', {
1111
- booksRate: $('booksRateB'),
1112
- tpsInline: $('tpsInlineB'),
1113
- totalTokensNum: $('totalTokensNumB'),
1114
- totalItemNum: $('totalItemNumB'),
1115
- totalItemUnit: $('totalItemUnitB'),
 
 
 
 
 
1116
  });
1117
- instances.push(instB);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1118
  }
1119
 
1120
  let lastTime = performance.now(), lastMetricUpdate = 0;
@@ -1133,21 +1160,7 @@
1133
 
1134
  if (instB) {
1135
  instB.updateMetrics(now);
1136
-
1137
- const tpsA = instA.getTps();
1138
- const tpsB = instB.getTps();
1139
- if (tpsA === tpsB) {
1140
- speedupRatioEl.textContent = 'Same throughput';
1141
- speedupRatioEl.className = 'ratio';
1142
- } else if (tpsA > tpsB) {
1143
- const ratio = tpsA / tpsB;
1144
- speedupRatioEl.textContent = 'Model A is ' + ratio.toFixed(1) + '\u00d7 faster';
1145
- speedupRatioEl.className = 'ratio a-faster';
1146
- } else {
1147
- const ratio = tpsB / tpsA;
1148
- speedupRatioEl.textContent = 'Model B is ' + ratio.toFixed(1) + '\u00d7 faster';
1149
- speedupRatioEl.className = 'ratio b-faster';
1150
- }
1151
  }
1152
  }
1153
 
 
697
  el.className = 'dataset-item';
698
  el.innerHTML = '<span class="ds-check">\u23f3</span><span class="ds-name">' + ds.name + '</span><span class="ds-time">-</span><span class="ds-size">(' + formatNumInt(ds.tokens) + ' toks)</span><div class="ds-tip">' + ds.desc + '</div>';
699
  datasetBarsEl.appendChild(el);
700
+ return {
701
+ root: el,
702
+ check: el.querySelector('.ds-check'),
703
+ time: el.querySelector('.ds-time'),
704
+ };
705
  });
706
 
707
  function resizeCanvas() {
 
737
  spawnAccum = 0;
738
  hwDirty = true;
739
  dsDone = DATASETS.map(() => false);
740
+ dsEls.forEach((dsEl) => {
741
+ dsEl.root.classList.remove('done');
742
+ dsEl.check.textContent = '\u23f3';
743
+ dsEl.time.textContent = '-';
744
+ });
745
  }
746
 
747
  gpuSlider.addEventListener('input', () => { reset(); });
 
1092
  const remaining = DATASETS[i].tokens - totalTokens;
1093
  if (remaining <= 0) {
1094
  dsDone[i] = true;
1095
+ dsEls[i].root.classList.add('done');
1096
+ dsEls[i].check.textContent = '\u2705';
1097
+ dsEls[i].time.textContent = 'done';
1098
  } else {
1099
+ dsEls[i].time.textContent = formatDuration(remaining / tps);
1100
  }
1101
  }
1102
  }
 
1104
  return { frame, updateMetrics, reset, getTps };
1105
  }
1106
 
1107
+ const instanceConfigs = [
1108
+ { key: 'A', canvasRole: 'cA', modelRole: 'modelA', datasetBarsRole: 'datasetBarsA' },
1109
+ ];
 
 
 
 
 
 
 
1110
  if (isCompareMode) {
1111
+ instanceConfigs.push({ key: 'B', canvasRole: 'cB', modelRole: 'modelB', datasetBarsRole: 'datasetBarsB' });
1112
+ }
1113
+
1114
+ const instancesByKey = {};
1115
+ const instances = instanceConfigs.map((cfg) => {
1116
+ const instance = createInstance(cfg.canvasRole, cfg.modelRole, cfg.datasetBarsRole, {
1117
+ booksRate: $('booksRate' + cfg.key),
1118
+ tpsInline: $('tpsInline' + cfg.key),
1119
+ totalTokensNum: $('totalTokensNum' + cfg.key),
1120
+ totalItemNum: $('totalItemNum' + cfg.key),
1121
+ totalItemUnit: $('totalItemUnit' + cfg.key),
1122
  });
1123
+ instancesByKey[cfg.key] = instance;
1124
+ return instance;
1125
+ });
1126
+
1127
+ const instA = instancesByKey.A;
1128
+ const instB = instancesByKey.B || null;
1129
+
1130
+ function updateSpeedupBadge(tpsA, tpsB) {
1131
+ if (tpsA === tpsB) {
1132
+ speedupRatioEl.textContent = 'Same throughput';
1133
+ speedupRatioEl.className = 'ratio';
1134
+ return;
1135
+ }
1136
+ if (tpsA > tpsB) {
1137
+ const ratio = tpsA / tpsB;
1138
+ speedupRatioEl.textContent = 'Model A is ' + ratio.toFixed(1) + '\u00d7 faster';
1139
+ speedupRatioEl.className = 'ratio a-faster';
1140
+ return;
1141
+ }
1142
+ const ratio = tpsB / tpsA;
1143
+ speedupRatioEl.textContent = 'Model B is ' + ratio.toFixed(1) + '\u00d7 faster';
1144
+ speedupRatioEl.className = 'ratio b-faster';
1145
  }
1146
 
1147
  let lastTime = performance.now(), lastMetricUpdate = 0;
 
1160
 
1161
  if (instB) {
1162
  instB.updateMetrics(now);
1163
+ updateSpeedupBadge(instA.getTps(), instB.getTps());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1164
  }
1165
  }
1166