Skip to content

Commit

Permalink
Cleanup Rockset on ET benchmark dashboards (#5761)
Browse files Browse the repository at this point in the history
  • Loading branch information
huydhn authored Oct 14, 2024
1 parent 701c772 commit e76c422
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 152 deletions.
30 changes: 8 additions & 22 deletions torchci/components/benchmark/llms/ModelGraphPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
} from "components/metrics/panels/TimeSeriesPanel";
import dayjs from "dayjs";
import { useBenchmark } from "lib/benchmark/llmUtils";
import { RocksetParam } from "lib/rockset";
import { BranchAndCommit } from "lib/types";

const GRAPH_ROW_HEIGHT = 245;
Expand All @@ -33,17 +32,15 @@ export function GraphPanel({
metricNames,
lBranchAndCommit,
rBranchAndCommit,
useClickHouse,
}: {
queryParams: RocksetParam[] | {};
queryParams: { [key: string]: any };
granularity: Granularity;
modelName: string;
dtypeName: string;
deviceName: string;
metricNames: string[];
lBranchAndCommit: BranchAndCommit;
rBranchAndCommit: BranchAndCommit;
useClickHouse: boolean;
}) {
// Do not set the commit here to query all the records in the time range to
// draw a chart
Expand All @@ -55,8 +52,7 @@ export function GraphPanel({
{
branch: rBranchAndCommit.branch,
commit: "",
},
useClickHouse
}
);

if (data === undefined || data.length === 0) {
Expand All @@ -75,22 +71,12 @@ export function GraphPanel({

// Clamp to the nearest granularity (e.g. nearest hour) so that the times will
// align with the data we get from the database
const startTime = useClickHouse
? dayjs((queryParams as { [key: string]: any })["startTime"]).startOf(
granularity
)
: dayjs(
(queryParams as RocksetParam[]).find((p) => p.name === "startTime")
?.value
).startOf(granularity);
const stopTime = useClickHouse
? dayjs((queryParams as { [key: string]: any })["stopTime"]).startOf(
granularity
)
: dayjs(
(queryParams as RocksetParam[]).find((p) => p.name === "stopTime")
?.value
).startOf(granularity);
const startTime = dayjs(
(queryParams as { [key: string]: any })["startTime"]
).startOf(granularity);
const stopTime = dayjs(
(queryParams as { [key: string]: any })["stopTime"]
).startOf(granularity);

// Only show records between these twos
const lWorkflowId = COMMIT_TO_WORKFLOW_ID[lBranchAndCommit.commit];
Expand Down
63 changes: 13 additions & 50 deletions torchci/lib/benchmark/llmUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,34 @@ import {
LLMsBenchmarkData,
} from "components/benchmark/llms/common";
import { fetcher } from "lib/GeneralUtils";
import { RocksetParam } from "lib/rockset";
import { BranchAndCommit } from "lib/types";
import useSWR from "swr";

export function useBenchmark(
queryParams: RocksetParam[] | {},
queryParams: { [key: string]: any },
modelName: string,
dtypeName: string,
deviceName: string,
branchAndCommit: BranchAndCommit,
useClickHouse: boolean = false,
getJobId: boolean = false
) {
const queryCollection = "benchmarks";
const queryName = "oss_ci_benchmark_llms";

const queryParamsWithBranchAndCommit:
| RocksetParam[]
| { [key: string]: any } = useClickHouse
? {
getJobId: getJobId,
...queryParams,
}
: [
{
name: "getJobId",
type: "bool",
value: getJobId,
},
...(queryParams as RocksetParam[]),
];

if (useClickHouse) {
(queryParamsWithBranchAndCommit as { [key: string]: any })["branches"] =
branchAndCommit.branch ? [branchAndCommit.branch] : [];
} else {
if (branchAndCommit.branch) {
queryParamsWithBranchAndCommit.push({
name: "branches",
type: "string",
value: branchAndCommit.branch,
});
}
}
const queryParamsWithBranchAndCommit: { [key: string]: any } = {
getJobId: getJobId,
...queryParams,
};

if (useClickHouse) {
(queryParamsWithBranchAndCommit as { [key: string]: any })["commits"] =
branchAndCommit.commit ? [branchAndCommit.commit] : [];
} else {
if (branchAndCommit.commit) {
queryParamsWithBranchAndCommit.push({
name: "commits",
type: "string",
value: branchAndCommit.commit,
});
}
}
(queryParamsWithBranchAndCommit as { [key: string]: any })["branches"] =
branchAndCommit.branch ? [branchAndCommit.branch] : [];

(queryParamsWithBranchAndCommit as { [key: string]: any })["commits"] =
branchAndCommit.commit ? [branchAndCommit.commit] : [];

const url = useClickHouse
? `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParamsWithBranchAndCommit)
)}`
: `/api/query/${queryCollection}/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParamsWithBranchAndCommit)
)}`;
const url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParamsWithBranchAndCommit)
)}`;

return useSWR(url, fetcher, {
refreshInterval: 60 * 60 * 1000, // refresh every hour
Expand Down
93 changes: 13 additions & 80 deletions torchci/pages/benchmark/llms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ import { DTypePicker } from "components/benchmark/ModeAndDTypePicker";
import CopyLink from "components/CopyLink";
import GranularityPicker from "components/GranularityPicker";
import { Granularity } from "components/metrics/panels/TimeSeriesPanel";
import { useCHContext } from "components/UseClickhouseProvider";
import dayjs from "dayjs";
import { useBenchmark } from "lib/benchmark/llmUtils";
import { fetcher } from "lib/GeneralUtils";
import { RocksetParam } from "lib/rockset";
import { BranchAndCommit } from "lib/types";
import _ from "lodash";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import useSWR from "swr";
import { RStoCHTimeParams, TimeRangePicker } from "../metrics";
import { TimeRangePicker } from "../metrics";

function Report({
queryParams,
Expand All @@ -43,9 +41,8 @@ function Report({
metricNames,
lBranchAndCommit,
rBranchAndCommit,
useClickHouse,
}: {
queryParams: RocksetParam[] | {};
queryParams: { [key: string]: any };
startTime: dayjs.Dayjs;
stopTime: dayjs.Dayjs;
granularity: Granularity;
Expand All @@ -56,15 +53,13 @@ function Report({
metricNames: string[];
lBranchAndCommit: BranchAndCommit;
rBranchAndCommit: BranchAndCommit;
useClickHouse: boolean;
}) {
const { data: lData, error: _lError } = useBenchmark(
queryParams,
modelName,
dtypeName,
deviceName,
lBranchAndCommit,
useClickHouse,
true
);
const { data: rData, error: _rError } = useBenchmark(
Expand All @@ -73,7 +68,6 @@ function Report({
dtypeName,
deviceName,
rBranchAndCommit,
useClickHouse,
true
);

Expand Down Expand Up @@ -123,7 +117,6 @@ function Report({
metricNames={metricNames}
lBranchAndCommit={lBranchAndCommit}
rBranchAndCommit={rBranchAndCommit}
useClickHouse={useClickHouse}
/>
<SummaryPanel
startTime={startTime}
Expand Down Expand Up @@ -164,9 +157,6 @@ export default function Page() {
const [dtypeName, setDTypeName] = useState<string>(DEFAULT_DTYPE_NAME);
const [deviceName, setDeviceName] = useState<string>(DEFAULT_DEVICE_NAME);

// TODO (huydhn): Clean this up once ClickHouse migration finishes
const { useCH: useClickHouse } = useCHContext();

// Set the dropdown value what is in the param
useEffect(() => {
const startTime: string = (router.query.startTime as string) ?? undefined;
Expand Down Expand Up @@ -242,77 +232,21 @@ export default function Page() {

const queryCollection = "benchmarks";
const queryName = "oss_ci_benchmark_names";

const timeParams: RocksetParam[] = [
{
name: "startTime",
type: "string",
value: startTime,
},
{
name: "stopTime",
type: "string",
value: stopTime,
},
];
const timeParamsClickHouse = RStoCHTimeParams(timeParams);

const queryParams: RocksetParam[] = [
{
name: "deviceArch",
type: "string",
value: deviceName === DEFAULT_DEVICE_NAME ? "" : deviceName,
},
{
name: "dtypes",
type: "string",
value: dtypeName === DEFAULT_DTYPE_NAME ? "" : dtypeName,
},
{
name: "excludedMetrics",
type: "string",
value: EXCLUDED_METRICS.join(","),
},
{
name: "filenames",
type: "string",
value: REPO_TO_BENCHMARKS[repoName].join(","),
},
{
name: "granularity",
type: "string",
value: granularity,
},
{
name: "names",
type: "string",
value: modelName === DEFAULT_MODEL_NAME ? "" : modelName,
},
{
name: "repo",
type: "string",
value: repoName,
},
...timeParams,
];
const queryParamsClickHouse = {
const queryParams = {
deviceArch: deviceName === DEFAULT_DEVICE_NAME ? "" : deviceName,
dtypes: dtypeName === DEFAULT_DTYPE_NAME ? [] : [dtypeName],
excludedMetrics: EXCLUDED_METRICS,
filenames: REPO_TO_BENCHMARKS[repoName],
granularity: granularity,
names: modelName === DEFAULT_MODEL_NAME ? [] : [modelName],
repo: repoName,
...timeParamsClickHouse,
startTime: dayjs(startTime).utc().format("YYYY-MM-DDTHH:mm:ss.SSS"),
stopTime: dayjs(stopTime).utc().format("YYYY-MM-DDTHH:mm:ss.SSS"),
};

const url = useClickHouse
? `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParamsClickHouse)
)}`
: `/api/query/${queryCollection}/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParams)
)}`;
const url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParams)
)}`;

const { data } = useSWR(url, fetcher, {
refreshInterval: 60 * 60 * 1000, // refresh every hour
Expand Down Expand Up @@ -391,36 +325,36 @@ export default function Page() {
<BranchAndCommitPicker
queryName={"oss_ci_benchmark_branches"}
queryCollection={"benchmarks"}
queryParams={useClickHouse ? queryParamsClickHouse : queryParams}
queryParams={queryParams}
branch={lBranch}
setBranch={setLBranch}
commit={lCommit}
setCommit={setLCommit}
titlePrefix={"Base"}
fallbackIndex={1} // Default to previous commit
timeRange={timeRange}
useClickHouse={useClickHouse}
useClickHouse={true}
/>
<Divider orientation="vertical" flexItem>
&mdash;Diff→
</Divider>
<BranchAndCommitPicker
queryName={"oss_ci_benchmark_branches"}
queryCollection={"benchmarks"}
queryParams={useClickHouse ? queryParamsClickHouse : queryParams}
queryParams={queryParams}
branch={rBranch}
setBranch={setRBranch}
commit={rCommit}
setCommit={setRCommit}
titlePrefix={"New"}
fallbackIndex={0} // Default to the latest commit
timeRange={timeRange}
useClickHouse={useClickHouse}
useClickHouse={true}
/>
</Stack>

<Report
queryParams={useClickHouse ? queryParamsClickHouse : queryParams}
queryParams={queryParams}
startTime={startTime}
stopTime={stopTime}
granularity={granularity}
Expand All @@ -431,7 +365,6 @@ export default function Page() {
metricNames={metricNames}
lBranchAndCommit={{ branch: lBranch, commit: lCommit }}
rBranchAndCommit={{ branch: rBranch, commit: rCommit }}
useClickHouse={useClickHouse}
/>
</div>
);
Expand Down

0 comments on commit e76c422

Please sign in to comment.