-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathLLMsBenchmarkPage.tsx
More file actions
353 lines (323 loc) · 10.2 KB
/
Copy pathLLMsBenchmarkPage.tsx
File metadata and controls
353 lines (323 loc) · 10.2 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
import { Stack, Typography } from "@mui/material";
import {
DEFAULT_REPO_NAME,
LAST_N_DAYS,
MAIN_BRANCH,
} from "components/benchmark/common";
import CopyLink from "components/common/CopyLink";
import { Granularity } from "components/metrics/panels/TimeSeriesPanel";
import dayjs from "dayjs";
import _, { cloneDeep } from "lodash";
import { NextRouter, useRouter } from "next/router";
import { ParsedUrlQuery } from "querystring";
import { useEffect, useReducer, useState } from "react";
import { propsReducer } from "./context/BenchmarkProps";
import LoadingPage from "components/common/LoadingPage";
import {
DEFAULT_ARCH_NAME,
DEFAULT_BACKEND_NAME,
DEFAULT_DEVICE_NAME,
DEFAULT_DTYPE_NAME,
DEFAULT_MODE_NAME,
DEFAULT_MODEL_NAME,
REPO_TO_BENCHMARKS,
} from "lib/benchmark/llms/common";
import { LLMsBenchmarkProps } from "lib/benchmark/llms/types/dashboardProps";
import { getBenchmarkDropdownFeatures } from "lib/benchmark/llms/utils/dashboardPickerUtils";
import {
getLLMsBenchmarkPropsQueryParameter,
useBenchmarkPropsData,
} from "lib/benchmark/llms/utils/llmUtils";
import { LLMsDashboardPicker } from "./components/dashboardPicker/LLMsDashboardPicker";
import { LLMsTimeRangePicker } from "./components/dashboardPicker/LLMsTimeRangePicker";
import LLMsReport from "./components/LLMsReport";
export default function LLMsBenchmarkPage() {
const router = useRouter();
// Set the default start and stop time to be the last N days when the page is loaded
const defaultStartTime = dayjs().subtract(LAST_N_DAYS, "day");
const defaultStopTime = dayjs();
const initialPropsState: LLMsBenchmarkProps = {
repoName: DEFAULT_REPO_NAME,
benchmarkName: "",
modelName: DEFAULT_MODEL_NAME,
backendName: DEFAULT_BACKEND_NAME,
modeName: DEFAULT_MODE_NAME,
dtypeName: DEFAULT_DTYPE_NAME,
deviceName: DEFAULT_DEVICE_NAME,
archName: DEFAULT_ARCH_NAME,
startTime: defaultStartTime,
stopTime: defaultStopTime,
timeRange: LAST_N_DAYS,
granularity: "day",
lCommit: "",
rCommit: "",
lBranch: MAIN_BRANCH,
rBranch: MAIN_BRANCH,
};
const [props, dispatch] = useReducer(propsReducer, initialPropsState);
// pass initial state in runtime for benchmark props
return (
<MainPage
props={props}
dispatch={dispatch}
defaultStartTime={defaultStartTime}
defaultStopTime={defaultStopTime}
router={router}
/>
);
}
// render the page before the data is loaded or when an error occured
const PrefetchRender = ({
children,
props,
dispatch,
baseUrl,
}: {
children: any;
props: LLMsBenchmarkProps;
dispatch: React.Dispatch<any>;
baseUrl: string;
}) => {
return (
<div>
<Stack direction="row" spacing={2} sx={{ mb: 2 }}>
{getBenchmarkName(props.benchmarkName, props.repoName)}
{formLink(props, baseUrl)}
</Stack>
<Stack direction="row" spacing={2} sx={{ mb: 2 }}>
<LLMsTimeRangePicker props={props} dispatch={dispatch} />
</Stack>
<Stack>{children}</Stack>
</div>
);
};
/**
* @returns Main page for the LLMs dashboard
* the page is routed in pagesM/bencmark/llms.tsx
*/
const MainPage = ({
defaultStartTime,
defaultStopTime,
props,
dispatch,
router,
}: {
defaultStartTime: dayjs.Dayjs;
defaultStopTime: dayjs.Dayjs;
router: NextRouter;
props: LLMsBenchmarkProps;
dispatch: React.Dispatch<any>;
}) => {
const [baseUrl, setBaseUrl] = useState<string>("");
useEffect(() => {
const newProps = resetProps(
router.query,
props,
defaultStartTime,
defaultStopTime
);
dispatch({ type: "UPDATE_FIELDS", payload: newProps });
setBaseUrl(
`${window.location.protocol}//${
window.location.host
}${router.asPath.replace(/\?.+/, "")}`
);
}, [router.query]);
const queryParams = getLLMsBenchmarkPropsQueryParameter(props);
const { data, error, isLoading } = useBenchmarkPropsData(queryParams);
// an error occured while fetching the benchmark props data
// give user choice for time range picker
if (error) {
return (
<PrefetchRender props={props} dispatch={dispatch} baseUrl={baseUrl}>
<>
Error loading data for{" "}
{(props.benchmarkName
? [props.benchmarkName]
: REPO_TO_BENCHMARKS[props.repoName]
).join(", ")}
, please select different time range, if this happens again, please
reach out to the pytorch team.
</>
</PrefetchRender>
);
}
// the benchmark props data is stil loading
if (!data && isLoading) {
return (
<div>
<PrefetchRender props={props} dispatch={dispatch} baseUrl={baseUrl}>
<>
Loading data for{" "}
{(props.benchmarkName
? [props.benchmarkName]
: REPO_TO_BENCHMARKS[props.repoName]
).join(", ")}
, please wait a min
</>
</PrefetchRender>
<div>
<LoadingPage />
</div>
</div>
);
}
// no prop data found for the given time range
if (data.length === 0) {
return (
<PrefetchRender props={props} dispatch={dispatch} baseUrl={baseUrl}>
<>
Found no records for{" "}
{(props.benchmarkName
? [props.benchmarkName]
: REPO_TO_BENCHMARKS[props.repoName]
).join(", ")}
, please select different time range
</>
</PrefetchRender>
);
}
const options = data;
const dropdownMapList = getBenchmarkDropdownFeatures(options, props.repoName);
const metricNames = getMetricNames(data);
// Default to latest for Helion Benchmark, otherwise default to oldest commit
const lcommitFallbackIdx =
props.benchmarkName === "Helion Benchmark" ? 0 : -1;
return (
<div>
<Stack direction="row" spacing={2} sx={{ mb: 2 }}>
{getBenchmarkName(props.benchmarkName, props.repoName)}
{formLink(props, baseUrl)}
</Stack>
<LLMsDashboardPicker
options={dropdownMapList}
props={props}
dispatch={dispatch}
queryParams={queryParams}
lcommitFallbackIdx={lcommitFallbackIdx}
/>
<LLMsReport
props={props}
metricNames={metricNames}
benchmarkPropsQueryParams={queryParams}
/>
</div>
);
};
function getMetricNames(data: any) {
const metricNames = _.uniq(data.map((r: any) => r.metric));
return metricNames as string[];
}
function resetProps(
urlQuery: ParsedUrlQuery,
prevProps: any,
defaultStartTime: dayjs.Dayjs,
defaultStopTime: dayjs.Dayjs
) {
const newProps = cloneDeep(prevProps);
const startTime: string = (urlQuery.startTime as string) ?? undefined;
if (startTime !== undefined) {
newProps.startTime = dayjs(startTime);
if (dayjs(startTime).valueOf() !== defaultStartTime.valueOf()) {
newProps.timeRange = -1;
}
}
const stopTime: string = (urlQuery.stopTime as string) ?? undefined;
if (stopTime !== undefined) {
newProps.stopTime = dayjs(stopTime);
if (dayjs(stopTime).valueOf() !== defaultStopTime.valueOf()) {
newProps.timeRange = -1;
}
}
const granularity: Granularity =
(urlQuery.granularity as Granularity) ?? undefined;
if (granularity !== undefined) {
newProps.granularity = granularity;
}
const repoName: string = (urlQuery.repoName as string) ?? undefined;
if (repoName !== undefined && repoName) {
newProps.repoName = repoName;
}
const benchmarkName: string = (urlQuery.benchmarkName as string) ?? undefined;
if (benchmarkName != undefined) {
newProps.benchmarkName = benchmarkName;
}
const modelName: string = (urlQuery.modelName as string) ?? undefined;
if (modelName !== undefined) {
newProps.modelName = modelName;
}
const backendName: string = (urlQuery.backendName as string) ?? undefined;
if (backendName !== undefined) {
newProps.backendName = backendName;
}
const modeName: string = (urlQuery.modeName as string) ?? undefined;
if (modeName !== undefined) {
newProps.modeName = modeName;
}
const dtypeName: string = (urlQuery.dtypeName as string) ?? undefined;
if (dtypeName !== undefined) {
newProps.dtypeName = dtypeName;
}
const deviceName: string = (urlQuery.deviceName as string) ?? undefined;
if (deviceName !== undefined) {
newProps.deviceName = deviceName;
}
// Set the default arch to Android for ExecuTorch as it has only 2 options Android and iOS
const archName: string = (urlQuery.archName as string) ?? undefined;
if (archName !== undefined) {
newProps.archName = archName;
}
const lBranch: string = (urlQuery.lBranch as string) ?? undefined;
if (lBranch !== undefined) {
newProps.lBranch = lBranch;
}
const lCommit: string = (urlQuery.lCommit as string) ?? undefined;
if (lCommit !== undefined) {
newProps.lCommit = lCommit;
}
const rBranch: string = (urlQuery.rBranch as string) ?? undefined;
if (rBranch !== undefined) {
newProps.rBranch = rBranch;
}
const rCommit: string = (urlQuery.rCommit as string) ?? undefined;
if (rCommit !== undefined) {
newProps.rCommit = rCommit;
}
return newProps;
}
const getBenchmarkName = (benchmarkName: string | any, repoName: string) => {
return (
<Typography fontSize={"2rem"} fontWeight={"bold"}>
{benchmarkName ? benchmarkName : REPO_TO_BENCHMARKS[repoName]} dashboard
</Typography>
);
};
const formLink = (props: LLMsBenchmarkProps, baseUrl: string) => {
return (
<CopyLink
textToCopy={`${baseUrl}?startTime=${encodeURIComponent(
props.startTime.toString()
)}&stopTime=${encodeURIComponent(
props.stopTime.toString()
)}&granularity=${props.granularity}&lBranch=${props.lBranch}&lCommit=${
props.lCommit
}&rBranch=${props.rBranch}&rCommit=${
props.rCommit
}&repoName=${encodeURIComponent(
props.repoName
)}&benchmarkName=${encodeURIComponent(
props.benchmarkName
)}&modelName=${encodeURIComponent(
props.modelName
)}&backendName=${encodeURIComponent(
props.backendName
)}&modeName=${encodeURIComponent(
props.modeName
)}&dtypeName=${encodeURIComponent(
props.dtypeName
)}&deviceName=${encodeURIComponent(
props.deviceName
)}&archName=${encodeURIComponent(props.archName)}`}
/>
);
};