Skip to content

Commit 93fc7e2

Browse files
committed
use exact date matching for GPU comparison benchmark queries
1 parent 4e074c6 commit 93fc7e2

5 files changed

Lines changed: 22 additions & 9 deletions

File tree

packages/app/src/app/api/v1/benchmarks/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { cachedJson, cachedQuery } from '@/lib/api-cache';
99
export const dynamic = 'force-dynamic';
1010

1111
const getCachedBenchmarks = cachedQuery(
12-
async (dbModelKey: string, date?: string) => {
12+
async (dbModelKey: string, date?: string, exact?: boolean) => {
1313
const sql = getDb();
14-
return getLatestBenchmarks(sql, dbModelKey, date);
14+
return getLatestBenchmarks(sql, dbModelKey, date, exact);
1515
},
1616
'benchmarks',
1717
{ blobOnly: true },
@@ -21,13 +21,14 @@ export async function GET(request: NextRequest) {
2121
const params = request.nextUrl.searchParams;
2222
const model = params.get('model') ?? '';
2323
const date = params.get('date') ?? undefined;
24+
const exact = params.get('exact') === 'true';
2425
const dbModelKey = DISPLAY_MODEL_TO_DB[model];
2526
if (!dbModelKey) {
2627
return NextResponse.json({ error: 'Unknown model' }, { status: 400 });
2728
}
2829

2930
try {
30-
const rows = await getCachedBenchmarks(dbModelKey, date);
31+
const rows = await getCachedBenchmarks(dbModelKey, date, exact || undefined);
3132
return cachedJson(rows);
3233
} catch (error) {
3334
console.error('Error fetching benchmarks:', error);

packages/app/src/components/inference/hooks/useChartData.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ export function useChartData(
100100
}, [selectedGPUs, selectedDates, selectedDateRange, selectedRunDate]);
101101

102102
const comparisonQueries = useQueries({
103-
queries: comparisonDates.map((date) => benchmarkQueryOptions(selectedModel, date, enabled)),
103+
queries: comparisonDates.map((date) =>
104+
benchmarkQueryOptions(selectedModel, date, enabled, true),
105+
),
104106
});
105107

106108
const comparisonLoading = comparisonQueries.some((q) => q.isLoading);

packages/app/src/hooks/api/use-benchmarks.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import { useQuery, keepPreviousData } from '@tanstack/react-query';
33
import { fetchBenchmarks } from '@/lib/api';
44

55
/** Shared query options — reused by useQueries for comparison dates. */
6-
export function benchmarkQueryOptions(model: string, date: string, enabled: boolean = true) {
6+
export function benchmarkQueryOptions(
7+
model: string,
8+
date: string,
9+
enabled: boolean = true,
10+
exact?: boolean,
11+
) {
712
return {
8-
queryKey: ['benchmarks', model, date] as const,
9-
queryFn: () => fetchBenchmarks(model, date),
13+
queryKey: ['benchmarks', model, date, exact ? 'exact' : 'latest'] as const,
14+
queryFn: () => fetchBenchmarks(model, date, exact),
1015
enabled: enabled && Boolean(model),
1116
};
1217
}

packages/app/src/lib/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ async function fetchJson<T>(url: string): Promise<T> {
9494
return res.json();
9595
}
9696

97-
export function fetchBenchmarks(model: string, date?: string) {
97+
export function fetchBenchmarks(model: string, date?: string, exact?: boolean) {
9898
const params = new URLSearchParams({ model });
9999
if (date) params.set('date', date);
100+
if (exact) params.set('exact', 'true');
100101
return fetchJson<BenchmarkRow[]>(`/api/v1/benchmarks?${params}`);
101102
}
102103

packages/db/src/queries/benchmarks.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ export async function getLatestBenchmarks(
3838
sql: NeonClient,
3939
modelKey: string,
4040
date?: string,
41+
exact?: boolean,
4142
): Promise<BenchmarkRow[]> {
4243
if (date) {
4344
// Date-filtered: use base table with DISTINCT ON (the view only has the absolute latest)
45+
// exact=true: only return data from this exact date (for GPU comparison)
46+
// exact=false (default): return latest data as of this date (for main chart)
47+
const dateFilter = exact ? sql`br.date = ${date}::date` : sql`br.date <= ${date}::date`;
4448
const rows = await sql`
4549
SELECT DISTINCT ON (br.config_id, br.conc, br.isl, br.osl)
4650
c.hardware,
@@ -71,7 +75,7 @@ export async function getLatestBenchmarks(
7175
JOIN latest_workflow_runs wr ON wr.id = br.workflow_run_id
7276
WHERE c.model = ${modelKey}
7377
AND br.error IS NULL
74-
AND br.date <= ${date}::date
78+
AND ${dateFilter}
7579
ORDER BY br.config_id, br.conc, br.isl, br.osl, br.date DESC
7680
`;
7781
return rows as unknown as BenchmarkRow[];

0 commit comments

Comments
 (0)