Skip to content

Commit

Permalink
Fix visual chart bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova committed Mar 12, 2024
1 parent ba21199 commit 9371df8
Showing 1 changed file with 36 additions and 34 deletions.
70 changes: 36 additions & 34 deletions examples/webgpu-embedding-benchmark/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,42 @@ const NUM_WARMUP_STEPS = 3;
const MODEL_CACHE = new Map();

// Chart configuration
const config = {
type: 'line',
data: {
labels: [],
datasets: [],
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top',
},
const initChart = () => {
const config = {
type: 'line',
data: {
labels: [],
datasets: [],
},
scales: {
x: {
title: {
display: true,
text: 'Batch size',
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
position: 'top',
},
min: 1,
},
y: {
title: {
display: true,
text: 'Time (ms)',
scales: {
x: {
title: {
display: true,
text: 'Batch size',
},
min: 1,
},
y: {
title: {
display: true,
text: 'Time (ms)',
},
}
}
}
},
};
const chart = new Chart(ctx, config);

},
};
const chart = new Chart(ctx, config);
return chart;
}
let chart = initChart();
const toggleScale = (axis, enabled) => {
chart.options.scales[axis].type = enabled ? 'logarithmic' : 'linear';
chart.update();
Expand Down Expand Up @@ -142,18 +145,16 @@ start.addEventListener('click', async () => {
}));

// Reset
chart.data.labels = [];
for (let i = 0; i < chart.data.datasets; ++i) {
chart.data.datasets[i].data.length = 0;
}
chart.update();
chart.destroy();
chart = initChart();
updateDatasets();

// NOTE: Models must be loaded sequentially (otherwise it will fail due to multiple calls to initWasm())
const testsToRun = new Map();
for (const test of selectedTests) {
const { label, dtype, device, quantized } = test;

const key = `${model_id}///${label}`
const key = `${model_id}///${label}`;

const cached = MODEL_CACHE.get(key);
if (cached) {
Expand Down Expand Up @@ -242,6 +243,7 @@ start.addEventListener('click', async () => {
const paramsStr = params.toString();
status.innerHTML = `⚡ Done! ${testNames.at(minMaxIndices[0])} is <strong>${roundedSpeedup}x</strong> faster than ${testNames.at(minMaxIndices[1])}! ⚡<br><a href="https://huggingface.co/spaces/Xenova/webgpu-embedding-benchmark/discussions/new?${paramsStr}" target="_blank">Share results</a>`;
start.disabled = false;
stop.disabled = true;
batchSizes.disabled = false;
sequenceLength.disabled = false;
modelID.disabled = false;
Expand Down

0 comments on commit 9371df8

Please sign in to comment.