Skip to content

Commit 4f1beab

Browse files
authored
Bug fix for deviceName mapping to arc and device (#7374)
special care for default filter option deviceName
1 parent fdcd2e5 commit 4f1beab

File tree

3 files changed

+64
-11
lines changed

3 files changed

+64
-11
lines changed

torchci/components/benchmark_v3/components/benchmarkSideBar/components/filters/DefaultSideBarMetricsDropdowns.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ export default function DefaultMetricsDropdowns() {
6464
optionListMap={metadataList}
6565
onChange={(_key: string, _value: any) => {
6666
if (_key == "deviceName") {
67-
const v = _value.split("||");
68-
if (v.length === 2) {
69-
setStagedFilter("device", v[0]);
70-
setStagedFilter("arch", v[1]);
71-
}
67+
handleDeviceName(_value, setStagedFilter);
7268
}
7369
setStagedFilter(_key, _value);
7470
}}
@@ -77,3 +73,24 @@ export default function DefaultMetricsDropdowns() {
7773
</Box>
7874
);
7975
}
76+
77+
function handleDeviceName(
78+
deviceName: string,
79+
setFilter: (k: string, v: string) => void
80+
) {
81+
if (deviceName == "") {
82+
setFilter("device", "");
83+
setFilter("arch", "");
84+
return;
85+
}
86+
87+
const v = deviceName.split("||");
88+
89+
if (v.length === 2) {
90+
setFilter("device", v[0]);
91+
setFilter("arch", v[1]);
92+
} else {
93+
setFilter("device", deviceName);
94+
setFilter("arch", "");
95+
}
96+
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,28 @@ export function toBenchmarkTimeSeriesReponseFormat(
406406
config: any = {},
407407
formats: string[] = ["time_series"]
408408
) {
409-
if (rawData.length === 0) {
409+
if (!rawData || rawData.length === 0) {
410410
return emptyTimeSeriesResponse();
411411
}
412-
const start_ts = new Date(rawData[0]?.granularity_bucket).getTime();
413-
const end_ts = new Date(
414-
rawData[rawData.length - 1].granularity_bucket
412+
413+
let start_ts = new Date(rawData[0]?.granularity_bucket).getTime();
414+
let end_ts = new Date(
415+
rawData[rawData.length - 1]?.granularity_bucket
415416
).getTime();
416417

418+
// Handle invalid dates (NaN from getTime)
419+
if (isNaN(start_ts) || isNaN(end_ts)) {
420+
console.warn("Invalid granularity_bucket values detected");
421+
throw new Error(
422+
`Invalid granularity_bucket values detected peek first data: ${rawData[0]}`
423+
);
424+
}
425+
426+
// Swap if needed
427+
if (end_ts < start_ts) {
428+
[start_ts, end_ts] = [end_ts, start_ts];
429+
}
430+
417431
let formats_result: any = {};
418432

419433
formats.forEach((format) => {

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getPassingModels,
1010
} from "lib/benchmark/compilerUtils";
1111
import {
12+
emptyTimeSeriesResponse,
1213
to_table,
1314
to_time_series_data,
1415
toTimeSeriesResponse,
@@ -80,6 +81,10 @@ export function toPrecomputeCompilerData(
8081
Date.parse(a.granularity_bucket) - Date.parse(b.granularity_bucket)
8182
);
8283

84+
if (!data || data.length === 0) {
85+
return emptyTimeSeriesResponse();
86+
}
87+
8388
// post process data to get start_ts and end_ts, and add commit metadata
8489
const { start_ts, end_ts } = postFetchProcess(all_data, commit_map, metadata);
8590

@@ -88,6 +93,7 @@ export function toPrecomputeCompilerData(
8893
const f = getFormat(all_data, format);
8994
res[format] = f;
9095
});
96+
9197
return toTimeSeriesResponse(res, rawData.length, start_ts, end_ts);
9298
}
9399

@@ -96,8 +102,24 @@ function postFetchProcess(
96102
commit_map: Map<string, any>,
97103
metadata: any
98104
) {
99-
const end_ts = new Date(data[0].granularity_bucket).getTime();
100-
const start_ts = new Date(data[data.length - 1].granularity_bucket).getTime();
105+
let start_ts = new Date(data[0]?.granularity_bucket).getTime();
106+
let end_ts = new Date(data[data.length - 1]?.granularity_bucket).getTime();
107+
108+
// Handle invalid dates (NaN from getTime)
109+
if (isNaN(start_ts) || isNaN(end_ts)) {
110+
console.warn(
111+
"(postFetchProcess) Invalid granularity_bucket values detected"
112+
);
113+
throw new Error(
114+
`(postFetchProcess)Invalid granularity_bucket values detected peek first data: ${data[0]}`
115+
);
116+
}
117+
118+
// Swap if needed
119+
if (end_ts < start_ts) {
120+
[start_ts, end_ts] = [end_ts, start_ts];
121+
}
122+
101123
data.map((row) => {
102124
row["commit"] = commit_map.get(row.workflow_id)?.commit;
103125
row["branch"] = commit_map.get(row.workflow_id)?.branch;

0 commit comments

Comments
 (0)