Skip to content

Commit 5231499

Browse files
committed
replace api
ghstack-source-id: 4192ac0 Pull-Request: #7112
1 parent 29557d6 commit 5231499

File tree

6 files changed

+130
-29
lines changed

6 files changed

+130
-29
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"params": {
3+
"branches": "Array(String)",
4+
"commits": "Array(String)",
5+
"compilers": "Array(String)",
6+
"device": "String",
7+
"arch": "String",
8+
"dtype": "String",
9+
"granularity": "String",
10+
"mode": "String",
11+
"startTime": "DateTime64(3)",
12+
"stopTime": "DateTime64(3)",
13+
"suites": "Array(String)",
14+
"workflowId": "Int64"
15+
},
16+
"tests": []
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
SELECT
2+
workflow_id,
3+
job_id,
4+
head_sha,
5+
replaceOne(head_branch, 'refs/heads/', '') AS head_branch,
6+
suite,
7+
model_name AS model,
8+
metric_name AS metric,
9+
value,
10+
metric_extra_info AS extra_info,
11+
benchmark_extra_info['output'] AS output,
12+
timestamp,
13+
DATE_TRUNC({granularity: String}, fromUnixTimestamp(timestamp))
14+
AS granularity_bucket
15+
FROM benchmark.oss_ci_benchmark_torchinductor
16+
WHERE
17+
(head_sha) IN (
18+
SELECT DISTINCT head_sha
19+
FROM benchmark.oss_ci_benchmark_torchinductor
20+
PREWHERE
21+
timestamp >= toUnixTimestamp({startTime: DateTime64(3,)})
22+
AND timestamp < toUnixTimestamp({stopTime: DateTime64(3)})
23+
)
24+
AND (
25+
has(
26+
{branches: Array(String)},
27+
replaceOne(head_branch, 'refs/heads/', '')
28+
)
29+
OR empty({branches: Array(String)})
30+
)
31+
AND benchmark_dtype = {dtype: String}
32+
AND benchmark_mode = {mode: String}
33+
AND device = {device: String}
34+
AND positionCaseInsensitive(arch, {arch: String}) > 0
35+
36+
SETTINGS session_timezone = 'UTC';

torchci/lib/benchmark/api_helper/compilers/precompute.ts

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,29 @@ import {
66
getPassingModels,
77
} from "lib/benchmark/compilerUtils";
88
import { queryClickhouseSaved } from "lib/clickhouse";
9-
import {
10-
BenchmarkTimeSeriesResponse,
11-
CommitRow,
12-
groupByBenchmarkData,
13-
toCommitRowMap,
14-
} from "../utils";
15-
16-
const BENCNMARK_TABLE_NAME = "compilers_benchmark_performance";
17-
const BENCNMARK_COMMIT_NAME = "compilers_benchmark_performance_branches";
9+
import { CompilerPerformanceData } from "lib/types";
10+
import { BenchmarkTimeSeriesResponse, groupByBenchmarkData } from "../utils";
11+
//["x86_64","NVIDIA A10G","NVIDIA H100 80GB HBM3"]
12+
const COMPILER_BENCHMARK_TABLE_NAME = "compilers_benchmark_api_query";
1813

1914
// TODO(elainewy): improve the fetch performance
20-
export async function getCompilerBenchmarkData(inputparams: any) {
15+
export async function getCompilerBenchmarkData(
16+
inputparams: any,
17+
query_table: string = ""
18+
) {
19+
let table = COMPILER_BENCHMARK_TABLE_NAME;
20+
if (query_table.length > 0) {
21+
table = query_table;
22+
}
23+
2124
const start = Date.now();
22-
const rows = await queryClickhouseSaved(BENCNMARK_TABLE_NAME, inputparams);
25+
let rows = await queryClickhouseSaved(table, inputparams);
2326
const end = Date.now();
24-
console.log("time to get data", end - start);
25-
26-
const startc = Date.now();
27-
const commits = await queryClickhouseSaved(
28-
BENCNMARK_COMMIT_NAME,
29-
inputparams
30-
);
31-
const endc = Date.now();
32-
console.log("time to get commit data", endc - startc);
33-
const commitMap = toCommitRowMap(commits);
27+
console.log("time to get compiler timeseris data", end - start);
3428

3529
if (rows.length === 0) {
3630
const response: BenchmarkTimeSeriesResponse = {
31+
total_rows: 0,
3732
time_series: [],
3833
time_range: {
3934
start: "",
@@ -43,11 +38,26 @@ export async function getCompilerBenchmarkData(inputparams: any) {
4338
return response;
4439
}
4540

41+
// extract backend from output in runtime instead of doing it in the query. since it's expensive for regex matching.
42+
// TODO(elainewy): we should add this as a column in the database for less runtime logics.
43+
rows.map((row) => {
44+
const backend =
45+
row.backend && row.backend !== ""
46+
? row.backend
47+
: extractBackendSqlStyle(
48+
row.output,
49+
row.suite,
50+
inputparams.dtype,
51+
inputparams.mode,
52+
inputparams.device
53+
);
54+
row["backend"] = backend;
55+
});
56+
4657
// TODO(elainewy): add logics to handle the case to return raw data
4758
const benchmark_time_series_response = toPrecomputeCompiler(
4859
rows,
4960
inputparams,
50-
commitMap,
5161
"time_series"
5262
);
5363
return benchmark_time_series_response;
@@ -56,18 +66,16 @@ export async function getCompilerBenchmarkData(inputparams: any) {
5666
function toPrecomputeCompiler(
5767
rawData: any[],
5868
inputparams: any,
59-
commitMap: Record<string, CommitRow>,
6069
type: string = "time_series"
6170
) {
6271
const data = convertToCompilerPerformanceData(rawData);
72+
const commit_map = toWorkflowIdMap(data);
6373
const models = getPassingModels(data);
64-
6574
const passrate = computePassrate(data, models);
6675
const geomean = computeGeomean(data, models);
6776
const peakMemory = computeMemoryCompressionRatio(data, models);
6877

6978
const all_data = [passrate, geomean, peakMemory].flat();
70-
7179
const earliest_timestamp = Math.min(
7280
...all_data.map((row) => new Date(row.granularity_bucket).getTime())
7381
);
@@ -81,9 +89,8 @@ function toPrecomputeCompiler(
8189
row["arch"] = inputparams["arch"];
8290
row["device"] = inputparams["device"];
8391
row["mode"] = inputparams["mode"];
84-
// always keep this:
85-
row["commit"] = commitMap[row["workflow_id"]]?.head_sha;
86-
row["branch"] = commitMap[row["workflow_id"]]?.head_branch;
92+
row["commit"] = commit_map.get(row.workflow_id)?.commit;
93+
row["branch"] = commit_map.get(row.workflow_id)?.branch;
8794
});
8895

8996
let res: any[] = [];
@@ -163,11 +170,44 @@ function toPrecomputeCompiler(
163170
}
164171

165172
const response: BenchmarkTimeSeriesResponse = {
166-
time_series: res,
173+
total_rows: res.length,
174+
total_raw_rows: rawData.length,
167175
time_range: {
168176
start: new Date(earliest_timestamp).toISOString(),
169177
end: new Date(latest_timestamp).toISOString(),
170178
},
179+
time_series: res,
171180
};
172181
return response;
173182
}
183+
184+
export function extractBackendSqlStyle(
185+
output: string,
186+
suite: string,
187+
dtype: string,
188+
mode: string,
189+
device: string
190+
): string | null {
191+
const esc = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
192+
const tail = `_${esc(suite)}_${esc(dtype)}_${esc(mode)}_${esc(device)}_`;
193+
194+
const temp = output.replace(new RegExp(`${tail}.*$`), "");
195+
196+
const m = temp.match(/.*[\/\\]([^\/\\]+)$/);
197+
return m ? m[1] : null;
198+
}
199+
200+
export function toWorkflowIdMap(data: CompilerPerformanceData[]) {
201+
const commit_map = new Map<string, any>();
202+
data.forEach((row) => {
203+
const commit = row?.commit;
204+
const branch = row?.branch;
205+
const workflow_id = `${row.workflow_id}`;
206+
commit_map.set(workflow_id, {
207+
commit,
208+
branch,
209+
workflow_id,
210+
});
211+
});
212+
return commit_map;
213+
}

torchci/lib/benchmark/api_helper/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,10 @@ export function getNestedField(obj: any, path: string): any {
136136
}
137137

138138
export type BenchmarkTimeSeriesResponse = {
139+
total_rows: number;
139140
time_series: any[];
140141
time_range: { start: string; end: string };
142+
total_raw_rows?: number;
141143
};
142144

143145
export type CommitRow = {

torchci/lib/benchmark/compilerUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ export function convertToCompilerPerformanceData(data: BenchmarkData[]) {
440440
suite: r.suite,
441441
workflow_id: r.workflow_id,
442442
job_id: r.job_id,
443+
branch: r.head_branch,
444+
commit: r.head_sha,
443445
};
444446
}
445447

torchci/lib/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ export interface CompilerPerformanceData {
204204
suite: string;
205205
workflow_id: number;
206206
job_id?: number;
207+
branch?: string;
208+
commit?: string;
207209
}
208210

209211
export interface TritonBenchPerformanceData {
@@ -231,6 +233,8 @@ export interface BenchmarkData {
231233
suite: string;
232234
value: number;
233235
workflow_id: number;
236+
head_sha?: string;
237+
head_branch?: string;
234238
}
235239

236240
export interface RepoBranchAndCommit {

0 commit comments

Comments
 (0)