Skip to content

Commit 5b1edd8

Browse files
authored
[Compiler Inductor Query Improvement] Move compiler query to use QueryBuilder (#7464)
# Overview onvert compiler query to queryBuilder for dynamically build the query # Details The fetch performance slows down due to the where statement to filter benchmark_extra.output Investigated, the noisy output end with ".csv" only affect rocm and cuda a100. Add the addtional filter where statement only for situation for rocm and A100 # Tested tested with notification, the api does not break the regression summary report, since it also accept single word fields
1 parent 0cecaa5 commit 5b1edd8

File tree

8 files changed

+293
-97
lines changed

8 files changed

+293
-97
lines changed

torchci/components/benchmark_v3/configs/teams/compilers/config.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,21 @@ const RENDER_MAPPING_BOOK = {
140140
},
141141
};
142142

143+
export function toQueryArch(device: string, arch: string) {
144+
if (arch === undefined) return [];
145+
if (!device) return [];
146+
switch (device) {
147+
case "rocm":
148+
if (arch === "mi300x" || arch == "") return ["mi300x", "mi325x"];
149+
return [arch];
150+
default:
151+
if (arch === "") {
152+
return [];
153+
}
154+
return [arch];
155+
}
156+
}
157+
143158
export const compilerQueryParameterConverter: QueryParameterConverter = (
144159
inputs: QueryParameterConverterInputs
145160
) => {
@@ -154,16 +169,21 @@ export const compilerQueryParameterConverter: QueryParameterConverter = (
154169
}
155170

156171
let models = getModels(f.model);
172+
173+
const device = DISPLAY_NAMES_TO_DEVICE_NAMES[f.deviceName];
174+
const arch = DISPLAY_NAMES_TO_ARCH_NAMES[f.deviceName];
175+
const arches = toQueryArch(device, arch);
176+
157177
const params = {
158178
commits: i.commits ?? [],
159179
branches: i.branches ?? [],
160180
workflows: workflows,
161181
compilers: compilerList,
162-
arch: DISPLAY_NAMES_TO_ARCH_NAMES[f.deviceName],
163-
device: DISPLAY_NAMES_TO_DEVICE_NAMES[f.deviceName],
164-
dtype: f.dtype === "none" ? "" : f.dtype,
182+
arches: arches,
183+
devices: [device],
184+
dtypes: f.dtype === "none" ? [] : [f.dtype],
165185
granularity: "hour",
166-
mode: f.mode,
186+
modes: [f.mode],
167187
models: models,
168188
startTime: dayjs.utc(i.timeRange.start).format("YYYY-MM-DDTHH:mm:ss"),
169189
stopTime: dayjs.utc(i.timeRange.end).format("YYYY-MM-DDTHH:mm:ss"),

torchci/lib/benchmark/api_helper/backend/common/type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export const defaultCompilerGetBenchmarkDataInputs: any = {
3737

3838
export const defaultListCommitsInputs: any = {
3939
branches: [],
40-
device: "",
40+
devices: [],
4141
arch: [],
42-
dtype: "",
43-
mode: "",
42+
dtypes: [],
43+
modes: [],
4444
startTime: "",
4545
stopTime: "",
4646
suites: [],

torchci/lib/benchmark/api_helper/backend/common/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Utility to extract params from either GET or POST
22
import dayjs from "dayjs";
3-
import { queryClickhouseSaved } from "lib/clickhouse";
43
import { NextApiRequest } from "next";
4+
import { BenchmarkCompilerListCommitQueryBuilder } from "../dataFetchers/queryBuilderUtils/compilerQueryBuilder";
55
import { CommitResult } from "./type";
66

77
/**
@@ -380,11 +380,19 @@ function subsampleCommitsByDate(data: any[], maxCount: number | undefined) {
380380
};
381381
}
382382

383+
async function listCommitsFromDb(queryParams: any) {
384+
// fetch metadata from db
385+
const fetcher = new BenchmarkCompilerListCommitQueryBuilder();
386+
const data = await fetcher.applyQuery(queryParams);
387+
const result = fetcher.postProcess(data);
388+
return result;
389+
}
390+
383391
export async function getCommitsWithSampling(
384392
tableName: string,
385393
queryParams: any
386394
): Promise<CommitResult> {
387-
const commit_results = await queryClickhouseSaved(tableName, queryParams);
395+
const commit_results = await listCommitsFromDb(queryParams);
388396
let maxCount = undefined;
389397
// if subsampling is specified, use it
390398
if (queryParams.sampling) {

torchci/lib/benchmark/api_helper/backend/compilers/compiler_benchmark_data.ts

Lines changed: 8 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import { queryClickhouseSaved } from "lib/clickhouse";
21
import {
32
CommitResult,
43
CompilerQueryType,
5-
defaultCompilerGetBenchmarkDataInputs,
64
defaultCompilerGetTimeSeriesInputs,
7-
defaultListCommitsInputs,
85
} from "../common/type";
96
import {
107
emptyTimeSeriesResponse,
118
getCommitsWithSampling,
129
} from "../common/utils";
13-
import {
14-
extractBackendSqlStyle,
15-
toApiArch,
16-
toQueryArch,
17-
} from "./helpers/common";
10+
import { BenchmarkCompilerBenchmarkDataQueryBuilder } from "../dataFetchers/queryBuilderUtils/compilerQueryBuilder";
11+
import { extractBackendSqlStyle, toApiArch } from "./helpers/common";
1812
import { toGeneralCompilerData } from "./helpers/general";
1913
import { toPrecomputeCompilerData } from "./helpers/precompute";
2014

@@ -23,26 +17,6 @@ const COMPILER_BENCHMARK_TABLE_NAME = "compilers_benchmark_api_query";
2317
const COMPILER_BENCHMARK_COMMITS_TABLE_NAME =
2418
"compilers_benchmark_api_commit_query";
2519

26-
// TODO(ELAINEWY): add GET BENCHMARK DATA API
27-
/**
28-
* backend method to get single compiler benchmark data
29-
* must provide workflow and branch in inputParams
30-
*/
31-
export async function getSingleCompilerBenchmarkData(
32-
request_name: string,
33-
inputParams: any,
34-
formats: string[] = ["raw"]
35-
) {
36-
const queryParams = await getSingleCompilerBenchmarkDataQueryParams(
37-
inputParams
38-
);
39-
const rows = await fetchCompilerDataFromDb(queryParams);
40-
if (rows.length === 0) {
41-
return emptyTimeSeriesResponse();
42-
}
43-
return toCompilerResponseFormat(rows, formats, request_name);
44-
}
45-
4620
/**
4721
* backend method to get time series data
4822
*/
@@ -84,47 +58,15 @@ export function toCompilerResponseFormat(
8458
}
8559

8660
export async function getCompilerCommits(
87-
inputparams: any
61+
inputParams: any
8862
): Promise<CommitResult> {
89-
if (!inputparams.startTime || !inputparams.stopTime) {
63+
if (!inputParams.startTime || !inputParams.stopTime) {
9064
throw new Error("no start/end time provided in request");
9165
}
92-
const queryParams = {
93-
...defaultListCommitsInputs, // base defaults
94-
...inputparams, // override with caller's values
95-
};
96-
97-
const arch_list = toQueryArch(inputparams.device, inputparams.arch);
98-
queryParams["arch"] = arch_list;
9966
return await getCommitsWithSampling(
10067
COMPILER_BENCHMARK_COMMITS_TABLE_NAME,
101-
queryParams
102-
);
103-
}
104-
105-
// TODO(ELAINEWY): add GET BENCHMARK DATA API
106-
async function getSingleCompilerBenchmarkDataQueryParams(
107-
inputparams: any
108-
): Promise<any> {
109-
const queryParams = {
110-
...defaultCompilerGetBenchmarkDataInputs, // base defaults
111-
...inputparams, // override with caller's values
112-
};
113-
const arch_list = toQueryArch(queryParams.device, queryParams.arch);
114-
queryParams["arch"] = arch_list;
115-
116-
if (!queryParams.workflow || !queryParams.branch) {
117-
throw new Error(
118-
"no workflow or branch provided in request for single data fetch"
119-
);
120-
}
121-
queryParams["workflows"] = [queryParams.workflow];
122-
queryParams["branches"] = [queryParams.branch];
123-
console.log(
124-
"(getSingleCompilerBenchmarkDataQueryParams) workflows provided in request",
125-
queryParams.workflows
68+
inputParams
12669
);
127-
return queryParams;
12870
}
12971

13072
/**
@@ -140,10 +82,6 @@ export async function getCompilerBenchmarkTimeRangeQueryParams(
14082
...defaultCompilerGetTimeSeriesInputs, // base defaults
14183
...inputparams, // override with caller's values
14284
};
143-
144-
const arch_list = toQueryArch(queryParams.device, queryParams.arch);
145-
queryParams["arch"] = arch_list;
146-
14785
// todo(elainewy): support lworkfow and rworkflow in the future for time range query
14886

14987
// use the startTime and endTime to fetch commits from clickhouse if commits field is not provided
@@ -152,7 +90,6 @@ export async function getCompilerBenchmarkTimeRangeQueryParams(
15290
"(getCompilerBenchmarkTimeRangeQueryParams) no start/end time provided in request"
15391
);
15492
}
155-
15693
if (!queryParams.workflows || queryParams.workflows.length == 0) {
15794
const { data: commit_results } = await getCommitsWithSampling(
15895
COMPILER_BENCHMARK_COMMITS_TABLE_NAME,
@@ -188,10 +125,9 @@ async function fetchCompilerDataFromDb(queryParams: any): Promise<any[]> {
188125
const start = Date.now();
189126
let rows: any[] = [];
190127
try {
191-
rows = await queryClickhouseSaved(
192-
COMPILER_BENCHMARK_TABLE_NAME,
193-
queryParams
194-
);
128+
const fetcher = new BenchmarkCompilerBenchmarkDataQueryBuilder();
129+
const data = await fetcher.applyQuery(queryParams);
130+
rows = fetcher.postProcess(data);
195131
} catch (err: any) {
196132
throw Error(
197133
`${COMPILER_BENCHMARK_TABLE_NAME}(clickhouse query issue) ${err.message}`

torchci/lib/benchmark/api_helper/backend/compilers/helpers/common.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,6 @@ export function extractBackendSqlStyle(
1414
return m ? m[1] : null;
1515
}
1616

17-
export function toQueryArch(device: string, arch: string) {
18-
if (arch === undefined) return [];
19-
if (!device) return [];
20-
switch (device) {
21-
case "rocm":
22-
if (arch === "mi300x" || arch == "") return ["mi300x", "mi325x"];
23-
return [arch];
24-
default:
25-
if (arch === "") {
26-
return [];
27-
}
28-
return [arch];
29-
}
30-
}
31-
3217
export function toApiArch(device: string, arch: string): string {
3318
const norm = arch.toLowerCase();
3419
switch (device) {

0 commit comments

Comments
 (0)