-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathllmUtils.ts
More file actions
516 lines (462 loc) · 14.9 KB
/
Copy pathllmUtils.ts
File metadata and controls
516 lines (462 loc) · 14.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
import dayjs from "dayjs";
import { geomean } from "lib/benchmark/compilerUtils";
import { fetcher } from "lib/GeneralUtils";
import { BranchAndCommit } from "lib/types";
import _ from "lodash";
import useSWR from "swr";
import {
BranchAndCommitPerfData,
DEFAULT_ARCH_NAME,
DEFAULT_BACKEND_NAME,
DEFAULT_DEVICE_NAME,
DEFAULT_DTYPE_NAME,
DEFAULT_MODE_NAME,
DEFAULT_MODEL_NAME,
EXCLUDED_METRICS,
LLMsBenchmarkData,
REPO_TO_BENCHMARKS,
} from "../common";
import { LLMsBenchmarkProps } from "../types/dashboardProps";
import { TORCHAO_BASELINE } from "./aoUtils";
export function useBenchmark(
queryParams: { [key: string]: any },
branchAndCommit: BranchAndCommit
) {
const queryName: string = "oss_ci_benchmark_llms";
const queryParamsWithBranchAndCommit: { [key: string]: any } = queryParams;
(queryParamsWithBranchAndCommit as { [key: string]: any })["branches"] =
branchAndCommit.branch ? [branchAndCommit.branch] : [];
(queryParamsWithBranchAndCommit as { [key: string]: any })["commits"] =
branchAndCommit.commit ? [branchAndCommit.commit] : [];
const url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParamsWithBranchAndCommit)
)}`;
return useSWR(url, fetcher, {
refreshInterval: 60 * 60 * 1000, // refresh every hour
});
}
/**
* generate query params for benchmark page.
* @param props LLMsBenchmarkProps
*/
export function getLLMsBenchmarkPropsQueryParameter(props: LLMsBenchmarkProps) {
let dtypes: any[] = [];
if (props.dtypeName === DEFAULT_DTYPE_NAME) {
dtypes = [];
} else if (props.repoName == "pytorch/ao") {
if (props.backendName.startsWith("micro-benchmark")) {
dtypes = [props.dtypeName];
} else {
dtypes = [props.dtypeName, TORCHAO_BASELINE];
}
} else {
dtypes = [props.dtypeName];
}
const deviceName =
props.deviceName === DEFAULT_DEVICE_NAME ? "" : props.deviceName;
const archName = props.archName === DEFAULT_ARCH_NAME ? "" : props.archName;
let device = "";
let arch = "";
if (archName === "") {
// All the dashboards currently put device and arch into the same field in
// device (arch) format, i.e. cuda (NVIDIA B200). So, we need to extract
// the arch name here to use it in the query
const deviceArchRegex = new RegExp("^(?<device>.+)\\s+\\((?<arch>.+)\\)$");
const m = deviceName.match(deviceArchRegex);
device =
m !== null && m.groups !== undefined ? m.groups.device : deviceName;
arch = m !== null && m.groups !== undefined ? m.groups.arch : archName;
} else {
// If both device and arch are set, we just need to use them as they are
device = deviceName;
arch = archName;
}
const queryParams = {
arch: arch,
device: device,
mode: props.modeName === DEFAULT_MODE_NAME ? "" : props.modeName,
dtypes: dtypes,
excludedMetrics: EXCLUDED_METRICS,
benchmarks: props.benchmarkName
? [props.benchmarkName]
: REPO_TO_BENCHMARKS[props.repoName],
granularity: props.granularity,
models: props.modelName === DEFAULT_MODEL_NAME ? [] : [props.modelName],
backends:
props.backendName === DEFAULT_BACKEND_NAME ? [] : [props.backendName],
repo: props.repoName,
startTime: dayjs(props.startTime).utc().format("YYYY-MM-DDTHH:mm:ss.SSS"),
stopTime: dayjs(props.stopTime).utc().format("YYYY-MM-DDTHH:mm:ss.SSS"),
};
return queryParams;
}
export const useBenchmarkPropsData = (queryParams: any) => {
const queryName = "oss_ci_benchmark_names";
const url = `/api/clickhouse/${queryName}?parameters=${encodeURIComponent(
JSON.stringify(queryParams)
)}`;
return useSWR(url, fetcher, {
refreshInterval: 60 * 60 * 1000, // refresh every
});
};
export function combineLeftAndRight(
repoName: string,
benchmarkName: string,
lPerfData: BranchAndCommitPerfData,
rPerfData: BranchAndCommitPerfData
): { [k: string]: any }[] {
const dataGroupedByModel: { [k: string]: any } = getDataGroupedByModel(
lPerfData,
rPerfData
);
// process git job level failure rows
const jobFailureKeySet = processJobLevelFailureRows(
dataGroupedByModel,
repoName
);
const data: { [k: string]: any }[] = [];
for (const key of Object.keys(dataGroupedByModel)) {
if (jobFailureKeySet.has(key)) {
continue;
}
const row = toRowData(dataGroupedByModel, key, repoName, benchmarkName);
if ("metadata" in row) {
data.push(row);
}
}
return data;
}
export function computeGeomean(data: LLMsBenchmarkData[], metricName: string) {
const metricValues: { [key: string]: number[] } = {};
const returnedGeomean: LLMsBenchmarkData[] = [];
data.forEach((r: LLMsBenchmarkData) => {
if (r.metric !== metricName) {
return;
}
const origins = r.origins.join(",");
const k = `${r.granularity_bucket}+${r.workflow_id}+${r.job_id}+${r.backend}+${r.dtype}+${origins}+${r.device}+${r.arch}+${r.metric}`;
if (!(k in metricValues)) {
metricValues[k] = [];
}
if (r.actual !== 0) {
metricValues[k].push(r.actual);
}
});
Object.keys(metricValues).forEach((k: string) => {
const gm = geomean(metricValues[k]);
const [
bucket,
workflowId,
jobId,
backend,
dtype,
origins,
device,
arch,
metric,
] = k.split("+");
returnedGeomean.push({
granularity_bucket: bucket,
model: "",
backend: backend,
origins: origins.split(","),
workflow_id: Number(workflowId),
job_id: Number(jobId),
metric: `${metric} (geomean)`,
actual: Number(gm),
actual_geomean: Number(gm),
target: 0,
dtype: dtype,
device: device,
arch: arch,
});
});
return returnedGeomean;
}
const getDataGroupedByModel = (
lPerfData: BranchAndCommitPerfData,
rPerfData: BranchAndCommitPerfData
) => {
const lCommit = lPerfData.commit;
const lData = lPerfData.data;
// and the right (new commit)
const rCommit = rPerfData.commit;
const rData = rPerfData.data;
const dataGroupedByModel: { [k: string]: any } = {};
// The right (base commit)
rData.forEach((record: LLMsBenchmarkData) => {
const model = record.model;
const backend = record.backend;
const mode = record.mode;
const dtype = record.dtype;
const device = record.device;
const arch = record.arch;
const extra = JSON.stringify(record.extra);
const metric = record.metric;
const key = `${model};${backend};${mode};${dtype};${device};${arch};${extra}`;
if (!(key in dataGroupedByModel)) {
dataGroupedByModel[key] = {};
}
if (!(metric in dataGroupedByModel[key])) {
dataGroupedByModel[key][metric] = {};
}
dataGroupedByModel[key][metric] = {
r: record,
};
});
// Combine with left (base) data
if (lCommit !== rCommit && lData !== undefined) {
lData.forEach((record: LLMsBenchmarkData) => {
const model = record.model;
const backend = record.backend;
const mode = record.mode;
const dtype = record.dtype;
const device = record.device;
const arch = record.arch;
const extra = JSON.stringify(record.extra);
const metric = record.metric;
const key = `${model};${backend};${mode};${dtype};${device};${arch};${extra}`;
if (!(key in dataGroupedByModel)) {
dataGroupedByModel[key] = {};
}
if (!(metric in dataGroupedByModel[key])) {
dataGroupedByModel[key][metric] = {};
}
dataGroupedByModel[key][metric]["l"] = record;
});
}
return dataGroupedByModel;
};
const toRowData = (
dataGroupedByModel: { [k: string]: any },
key: string,
repoName: string,
benchmarkName: string
) => {
const [model, backend, mode, dtype, device, arch, extra] = key.split(";");
const row: { [k: string]: any } = {
// Keep the name as as the row ID as DataGrid requires it
name: `${model} ${backend} (${mode} / ${dtype} / ${device} / ${arch} / ${extra})`,
};
for (const metric in dataGroupedByModel[key]) {
const record = dataGroupedByModel[key][metric];
const hasL = "l" in record;
const hasR = "r" in record;
if (!("metadata" in row)) {
row["metadata"] = {
model: model,
origins: hasR ? record["r"].origins : [],
backend: backend,
mode: mode,
dtype: dtype,
device: device,
arch: arch,
l: hasL ? record["l"]["job_id"] : undefined,
r: hasR ? record["r"]["job_id"] : undefined,
};
} else {
row["metadata"]["l"] =
row["metadata"]["l"] ?? (hasL ? record["l"]["job_id"] : undefined);
row["metadata"]["r"] =
row["metadata"]["r"] ?? (hasR ? record["r"]["job_id"] : undefined);
}
if (mode !== "") {
row["mode"] = mode;
}
if (dtype !== "") {
row["dtype"] = dtype;
}
if (backend !== "") {
row["backend"] = backend;
}
row["device_arch"] = {
device: device,
arch: arch,
};
if (repoName === "vllm-project/vllm" || repoName === "sgl-project/sglang") {
// These fields are only available on vLLM benchmark
const extraInfo = JSON.parse(extra);
row["extra"] = extraInfo;
row["tensor_parallel_size"] = extraInfo["tensor_parallel_size"];
row["request_rate"] = extraInfo["request_rate"];
row["input_len"] = extraInfo["random_input_len"]
? extraInfo["random_input_len"]
: extraInfo["input_len"];
row["output_len"] = extraInfo["random_output_len"]
? extraInfo["random_input_len"]
: extraInfo["output_len"];
}
if (
repoName === "pytorch/pytorch" &&
benchmarkName === "TorchCache Benchmark"
) {
const extraInfo = JSON.parse(extra);
row["is_dynamic"] = extraInfo["is_dynamic"];
}
if (metric == "FAILURE_REPORT") {
row[metric] = {
l: hasL
? {
actual: Number.MAX_SAFE_INTEGER, // indicate the failure on left side
actual_geomean: Number.MAX_SAFE_INTEGER, // indicate the failure on left side
target: 0,
}
: {
actual: 0,
actual_geomean: 0,
target: 0,
},
r: hasR
? {
actual: Number.MAX_SAFE_INTEGER, // indicate the failure on right side
actual_geomean: Number.MAX_SAFE_INTEGER, // indicate the failure on right side
target: 0,
}
: {
actual: 0,
actual_geomean: 0,
target: 0,
},
highlight: hasL && hasR,
};
} else {
row[metric] = {
l: hasL
? {
actual: record["l"].actual,
actual_geomean: record["l"].actual_geomean,
target: record["l"].target,
}
: {
actual: 0,
actual_geomean: 0,
target: 0,
},
r: hasR
? {
actual: record["r"].actual,
actual_geomean: record["r"].actual_geomean,
target: record["r"].target,
}
: {
actual: 0,
actual_geomean: 0,
target: 0,
},
highlight: hasL && hasR,
};
}
}
return row;
};
const processJobLevelFailureRows = (
dataGroupedByModel: { [k: string]: any },
repoName: string
): Set<string> => {
// see if a repo need special handling for job level failure
const config = getJobReportFailureConfigs();
if (!(repoName in config)) {
return new Set();
}
const repoSpecificConfig: any = config[repoName];
const jobLevelFailureConfig = repoSpecificConfig["job_level_failure"];
// find rows that related to the job level failure
const jobLevelFailureKeys = Object.keys(dataGroupedByModel).filter(
(key: string) => {
const identifier = jobLevelFailureConfig["key_name"];
const val = getGroupKeyItem(key, identifier);
const record = dataGroupedByModel[key];
let isJobLevelFailure = false;
// check if the row is a git job level failure
if ("FAILURE_REPORT" in record) {
const failure_record = record["FAILURE_REPORT"];
const hasrFailure =
"r" in failure_record && failure_record["r"].metadata_info
? failure_record["r"].metadata_info["failure_type"] === "GIT_JOB"
: false;
const haslFailure =
"l" in failure_record && failure_record["l"].metadata_info
? failure_record["l"].metadata_info["failure_type"] === "GIT_JOB"
: false;
isJobLevelFailure = hasrFailure || haslFailure;
}
if (!val) {
return false;
}
if (jobLevelFailureConfig["content"].includes(val) && isJobLevelFailure) {
return true;
}
}
);
// process data to add Failure Report
Object.keys(dataGroupedByModel).forEach((key: string) => {
if (jobLevelFailureKeys.includes(key)) {
return;
}
jobLevelFailureKeys.forEach((failureKey: string) => {
// add FAILURE_REPORT related to job level failure in dataGroupedByModel
if (jobLevelFailureConfig["is_included"](key, failureKey)) {
dataGroupedByModel[key]["FAILURE_REPORT"] = _.cloneDeep(
dataGroupedByModel[failureKey]["FAILURE_REPORT"]
);
}
});
});
const jobLevelFailureRowSet = new Set(jobLevelFailureKeys);
return jobLevelFailureRowSet;
};
function getJobReportFailureConfigs() {
const JobReportFailureConfig: { [key: string]: any } = {
"pytorch/executorch": {
job_level_failure: {
key_name: "device",
content: [
"apple_iphone_15",
"samsung_galaxy_s22",
"samsung_galaxy_s24",
"google_pixel_8_pro",
],
is_included: (key: string, failureRowKey: string, field: string) => {
const model = getGroupKeyItem(key, "model");
const backend = getGroupKeyItem(key, "backend");
const device = getGroupKeyItem(key, "device");
const failure_model = getGroupKeyItem(failureRowKey, "model");
const failure_backend = getGroupKeyItem(failureRowKey, "backend");
const failure_device = getGroupKeyItem(failureRowKey, "device");
// form prefix for device name
const prefix = failure_device.split("_").join(" ").toLowerCase();
if (
model === failure_model &&
backend === failure_backend &&
device.toLocaleLowerCase().startsWith(prefix)
) {
return true;
}
return false;
},
},
},
};
return JobReportFailureConfig;
}
function getGroupKeyItem(key: string, type: string) {
const [model, backend, mode, dtype, device, arch, extra] = key.split(";");
switch (type) {
case "model":
return model;
case "backend":
return backend;
case "mode":
return mode;
case "dtype":
return dtype;
case "device":
return device;
case "arch":
return arch;
case "extra":
return extra;
default:
return "";
}
}