Skip to content

Commit

Permalink
Use CH for userbenchmark.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
kit1980 committed Jan 3, 2025
1 parent 9300dfd commit f187d71
Showing 1 changed file with 26 additions and 48 deletions.
74 changes: 26 additions & 48 deletions torchci/pages/torchbench/userbenchmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import { GridCellParams, GridRenderCellParams } from "@mui/x-data-grid";
import { TablePanelWithData } from "components/metrics/panels/TablePanel";
import dayjs from "dayjs";
import { fetcher } from "lib/GeneralUtils";
import { RocksetParam } from "lib/rockset";
import { useEffect, useState } from "react";
import useSWR from "swr";

const queryCollection = "torchbench";
const ROW_GAP = 30;
const ROW_HEIGHT = 48;
const MIN_ENTRIES = 10;
Expand All @@ -42,8 +40,8 @@ function UserbenchmarkPicker({
setUserbenchmark(e.target.value);
}
const queryName = "torchbench_list_userbenchmarks";
const queryParams: any[] = [];
const list_userbenchmark_url = `/api/query/${queryCollection}/${queryName}?parameters=${encodeURIComponent(
const queryParams = {};
const list_userbenchmark_url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParams)
)}`;

Expand Down Expand Up @@ -118,15 +116,10 @@ function CommitPicker({
}

const queryName = "torchbench_userbenchmark_list_commits";
const queryCollection = "torchbench";
const queryParams: RocksetParam[] = [
{
name: "userbenchmark",
type: "string",
value: userbenchmark,
},
];
const list_commits_url = `/api/query/${queryCollection}/${queryName}?parameters=${encodeURIComponent(
const queryParams: { [key: string]: any } = {
userbenchmark: userbenchmark,
};
const list_commits_url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParams)
)}`;

Expand Down Expand Up @@ -220,8 +213,8 @@ function Report({
return "";
}

function getQueryUrl(params: RocksetParam[]) {
return `/api/query/${queryCollection}/${queryName}?parameters=${encodeURIComponent(
function getQueryUrl(params: { [key: string]: any }) {
return `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(params)
)}`;
}
Expand All @@ -236,10 +229,12 @@ function Report({
// Return a list of metrics that are the union of cMetrics and tMetrics
cMetrics = cMetrics === undefined ? {} : cMetrics;
tMetrics = tMetrics === undefined ? {} : tMetrics;
let cMetricsData = "metrics" in cMetrics ? JSON.parse(cMetrics["metrics"]) : {};
let tMetricsData = "metrics" in tMetrics ? JSON.parse(tMetrics["metrics"]) : {};
let cMetricNames: string[] =
"metrics" in cMetrics ? Array.from(Object.keys(cMetrics["metrics"])) : [];
"metrics" in cMetrics ? Array.from(Object.keys(cMetricsData)) : [];
let tMetricNames: string[] =
"metrics" in tMetrics ? Array.from(Object.keys(tMetrics["metrics"])) : [];
"metrics" in tMetrics ? Array.from(Object.keys(tMetricsData)) : [];
const metricNameSet: Set<string> = new Set([
...cMetricNames,
...tMetricNames,
Expand All @@ -249,16 +244,15 @@ function Report({
const hasL =
cMetrics === undefined || !("metrics" in cMetrics)
? false
: name in cMetrics["metrics"];
: name in cMetricsData;
const hasR =
tMetrics === undefined || !("metrics" in tMetrics)
? false
: name in tMetrics["metrics"];
: name in tMetricsData;

const delta =
hasL && hasR
? (tMetrics["metrics"][name] - cMetrics["metrics"][name]) /
cMetrics["metrics"][name]
? (tMetricsData[name] - cMetricsData[name]) / cMetricsData[name]
: "undefined";
return {
// Keep the name as as the row ID as DataGrid requires it
Expand All @@ -272,13 +266,13 @@ function Report({
// The metrics value on base commit
control: {
name: name,
v: hasL ? cMetrics["metrics"][name] : "undefined",
v: hasL ? cMetricsData[name] : "undefined",
},

// The metrics value on head commit
treatment: {
name: name,
v: hasR ? tMetrics["metrics"][name] : "undefined",
v: hasR ? tMetricsData[name] : "undefined",
},

// The metrics value delta
Expand All @@ -295,37 +289,21 @@ function Report({
const rCommitHash: string = getCommitHash(rCommit);

const queryName = "torchbench_userbenchmark_query_metrics";
const queryCollection = "torchbench";
const queryControlParams: RocksetParam[] = [
{
name: "userbenchmark",
type: "string",
value: userbenchmark,
},
{
name: "commit",
type: "string",
value: lCommitHash,
},
];
const queryTreatmentParams: RocksetParam[] = [
{
name: "userbenchmark",
type: "string",
value: userbenchmark,
},
{
name: "commit",
type: "string",
value: rCommitHash,
},
];
const queryControlParams: { [key: string]: any } = {
userbenchmark: userbenchmark,
commit: lCommitHash,
};
const queryTreatmentParams: { [key: string]: any } = {
userbenchmark: userbenchmark,
commit: rCommitHash,
};
// We only submit the query if both commit IDs are available
if (lCommitHash.length === 0 || rCommitHash.length === 0) {
return <div>Please select both left and right commits.</div>;
}
let cMetrics = QueryMetrics(getQueryUrl(queryControlParams));
cMetrics = cMetrics === undefined ? {} : cMetrics[0];

let tMetrics = QueryMetrics(getQueryUrl(queryTreatmentParams));
tMetrics = tMetrics === undefined ? {} : tMetrics[0];
const metrics: Record<string, any>[] = genABMetrics(cMetrics, tMetrics);
Expand Down

0 comments on commit f187d71

Please sign in to comment.