Skip to content

Commit d0ccc65

Browse files
authored
feat: add better default precision selection (#471)
1 parent be5b5c8 commit d0ccc65

4 files changed

Lines changed: 369 additions & 18 deletions

File tree

packages/app/src/components/GlobalFilterContext.tsx

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
SEQUENCE_OPTIONS,
3838
} from '@/lib/data-mappings';
3939
import { computeAutoSwitchDecision } from '@/lib/unofficial-run-auto-switch';
40+
import { countCurvesByPrecision, resolveEffectivePrecisions } from '@/lib/default-precisions';
4041
import type { AvailabilityRow, WorkflowInfoResponse } from '@/lib/api';
4142

4243
interface RunInfo {
@@ -149,17 +150,23 @@ export function GlobalFilterProvider({
149150
return Sequence.EightK_OneK;
150151
});
151152

152-
const [selectedPrecisions, setSelectedPrecisionsRaw] = useState<string[]>(() => {
153-
if (initialPrecisions && initialPrecisions.length > 0) {
154-
const valid = initialPrecisions.filter((p) =>
155-
(PRECISION_OPTIONS as readonly string[]).includes(p),
156-
);
157-
if (valid.length > 0) return valid;
158-
}
159-
return [Precision.FP4];
160-
});
153+
const initialValidPrecisions = useMemo(
154+
() =>
155+
(initialPrecisions ?? []).filter((p) => (PRECISION_OPTIONS as readonly string[]).includes(p)),
156+
[initialPrecisions],
157+
);
158+
const [selectedPrecisions, setSelectedPrecisionsRaw] = useState<string[]>(() =>
159+
initialValidPrecisions.length > 0 ? initialValidPrecisions : [Precision.FP4],
160+
);
161+
// Whether the precision was chosen explicitly (seeded prop, URL `i_prec`,
162+
// preset, or manual toggle). Until then we auto-pick the densest precision
163+
// for the current model/sequence so FP8-heavy models don't open barren.
164+
const [precisionExplicit, setPrecisionExplicit] = useState<boolean>(
165+
() => initialValidPrecisions.length > 0,
166+
);
161167
const setSelectedPrecisions = useCallback((precisions: string[]) => {
162168
setSelectedPrecisionsRaw(precisions);
169+
setPrecisionExplicit(true);
163170
}, []);
164171

165172
// ── Run date / run ID ─────────────────────────────────────────────────────
@@ -198,7 +205,10 @@ export function GlobalFilterProvider({
198205
const precs = urlPrec
199206
.split(',')
200207
.filter((p) => (PRECISION_OPTIONS as readonly string[]).includes(p));
201-
if (precs.length > 0) setSelectedPrecisionsRaw(precs);
208+
if (precs.length > 0) {
209+
setSelectedPrecisionsRaw(precs);
210+
setPrecisionExplicit(true);
211+
}
202212
}
203213
applyIfMatches('g_rundate', RUNDATE_RE, setSelectedRunDateBase);
204214
applyIfMatches('g_runid', RUNID_RE, setSelectedRunId);
@@ -294,12 +304,44 @@ export function GlobalFilterProvider({
294304
return merged.length > 0 ? merged : ['fp4'];
295305
}, [availabilityRows, modelRows, effectiveSequence, unofficialAvailable, selectedModel]);
296306

297-
// Synchronously validated precisions
298-
const effectivePrecisions = useMemo(() => {
299-
const valid = selectedPrecisions.filter((p) => availablePrecisions.includes(p));
300-
if (valid.length > 0) return valid;
301-
return availablePrecisions.length > 0 ? [availablePrecisions[0]] : selectedPrecisions;
302-
}, [selectedPrecisions, availablePrecisions]);
307+
// Curve count per precision (distinct hw/framework/spec/disagg series) for the
308+
// selected model + sequence — drives the auto default toward the densest one.
309+
const precisionCurveCounts = useMemo(
310+
() =>
311+
countCurvesByPrecision(
312+
modelRows.filter((r) => islOslToSequence(r.isl, r.osl) === effectiveSequence),
313+
),
314+
[modelRows, effectiveSequence],
315+
);
316+
317+
// Precisions present in a loaded unofficial run for the current model + sequence.
318+
const unofficialPrecisionsForSelection = useMemo(
319+
() =>
320+
unofficialAvailable
321+
.filter((a) => a.model === selectedModel && a.sequence === effectiveSequence)
322+
.flatMap((a) => a.precisions),
323+
[unofficialAvailable, selectedModel, effectiveSequence],
324+
);
325+
326+
// Synchronously validated precisions. When the user hasn't explicitly chosen a
327+
// precision, auto-pick the densest (see resolveEffectivePrecisions).
328+
const effectivePrecisions = useMemo(
329+
() =>
330+
resolveEffectivePrecisions({
331+
selectedPrecisions,
332+
availablePrecisions,
333+
curveCounts: precisionCurveCounts,
334+
unofficialPrecisions: unofficialPrecisionsForSelection,
335+
explicit: precisionExplicit,
336+
}),
337+
[
338+
selectedPrecisions,
339+
availablePrecisions,
340+
precisionCurveCounts,
341+
unofficialPrecisionsForSelection,
342+
precisionExplicit,
343+
],
344+
);
303345

304346
// Dates available for selected model + sequence + precisions
305347
const availableDates = useMemo(() => {
@@ -397,14 +439,17 @@ export function GlobalFilterProvider({
397439
g_rundate: selectedRunDate,
398440
g_runid: selectedRunId,
399441
i_seq: effectiveSequence,
400-
i_prec: effectivePrecisions.join(','),
442+
// Only pin the precision in the URL once chosen explicitly; in auto mode
443+
// leave it out so the link keeps following the per-model densest default.
444+
i_prec: precisionExplicit ? effectivePrecisions.join(',') : undefined,
401445
});
402446
}, [
403447
selectedModel,
404448
selectedRunDate,
405449
selectedRunId,
406450
effectiveSequence,
407451
effectivePrecisions,
452+
precisionExplicit,
408453
setUrlParams,
409454
]);
410455

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import {
4+
MIN_SOLE_DEFAULT_CURVES,
5+
countCurvesByPrecision,
6+
pickDefaultPrecisions,
7+
resolveEffectivePrecisions,
8+
} from './default-precisions';
9+
10+
function row(precision: string, hardware: string, framework = 'vllm', disagg = false) {
11+
return { precision, hardware, framework, spec_method: 'none', disagg };
12+
}
13+
14+
describe('countCurvesByPrecision', () => {
15+
it('counts distinct (hardware, framework, spec_method, disagg) per precision', () => {
16+
const counts = countCurvesByPrecision([
17+
row('fp8', 'b200'),
18+
row('fp8', 'b300'),
19+
row('fp8', 'b200'), // dup curve, not counted again
20+
row('fp4', 'mi355x', 'atom'),
21+
]);
22+
expect(counts).toEqual({ fp8: 2, fp4: 1 });
23+
});
24+
25+
it('treats disagg and non-disagg of the same hw as distinct curves', () => {
26+
const counts = countCurvesByPrecision([
27+
row('fp8', 'b200', 'vllm', false),
28+
row('fp8', 'b200', 'vllm', true),
29+
]);
30+
expect(counts).toEqual({ fp8: 2 });
31+
});
32+
33+
it('returns {} for no rows', () => {
34+
expect(countCurvesByPrecision([])).toEqual({});
35+
});
36+
});
37+
38+
describe('pickDefaultPrecisions', () => {
39+
it('picks the single densest precision only when every precision clears the threshold', () => {
40+
// dsr1 shape: both dense.
41+
expect(pickDefaultPrecisions({ fp4: 23, fp8: 38 })).toEqual(['fp8']);
42+
});
43+
44+
it('shows both when one precision is below the threshold (MiniMax M3 shape)', () => {
45+
// fp4 barren (1 curve) next to a dense fp8 → surface both, not just fp8.
46+
expect(pickDefaultPrecisions({ fp4: 1, fp8: 14 })).toEqual(['fp4', 'fp8']);
47+
});
48+
49+
it('keeps fp4 when it is the densest and both clear the threshold (dsv4 shape)', () => {
50+
expect(pickDefaultPrecisions({ fp4: 28, fp8: 5 })).toEqual(['fp4']);
51+
});
52+
53+
it('breaks ties in favor of fp4 when both clear the threshold', () => {
54+
expect(pickDefaultPrecisions({ fp4: 8, fp8: 8 })).toEqual(['fp4']);
55+
});
56+
57+
it('breaks non-fp4 ties by canonical enum order', () => {
58+
// fp8 precedes bf16 in PRECISION_OPTIONS.
59+
expect(pickDefaultPrecisions({ bf16: 6, fp8: 6 })).toEqual(['fp8']);
60+
});
61+
62+
it('surfaces all precisions (sorted) when any is below threshold', () => {
63+
expect(pickDefaultPrecisions({ fp8: 3, fp4: 2 })).toEqual(['fp4', 'fp8']);
64+
// llama70b shape: fp4 sparse (3), fp8 dense (8) → both.
65+
expect(pickDefaultPrecisions({ fp4: 3, fp8: 8 })).toEqual(['fp4', 'fp8']);
66+
expect(MIN_SOLE_DEFAULT_CURVES).toBe(4);
67+
});
68+
69+
it('returns the lone precision for a single-precision model regardless of count', () => {
70+
expect(pickDefaultPrecisions({ fp4: 2 })).toEqual(['fp4']);
71+
expect(pickDefaultPrecisions({ fp4: 10 })).toEqual(['fp4']);
72+
});
73+
74+
it('returns [] when there are no precisions', () => {
75+
expect(pickDefaultPrecisions({})).toEqual([]);
76+
});
77+
});
78+
79+
describe('resolveEffectivePrecisions', () => {
80+
const M3_COUNTS = { fp4: 1, fp8: 14 };
81+
const M3_AVAIL = ['fp4', 'fp8'];
82+
83+
it('auto-defaults to both when one precision is sparse (M3 → fp4 + fp8)', () => {
84+
expect(
85+
resolveEffectivePrecisions({
86+
selectedPrecisions: ['fp4'],
87+
availablePrecisions: M3_AVAIL,
88+
curveCounts: M3_COUNTS,
89+
explicit: false,
90+
}),
91+
).toEqual(['fp4', 'fp8']);
92+
});
93+
94+
it('auto-defaults to the densest precision when every precision is dense (dsr1 → fp8)', () => {
95+
expect(
96+
resolveEffectivePrecisions({
97+
selectedPrecisions: ['fp4'],
98+
availablePrecisions: ['fp4', 'fp8'],
99+
curveCounts: { fp4: 23, fp8: 38 },
100+
explicit: false,
101+
}),
102+
).toEqual(['fp8']);
103+
});
104+
105+
it('leaves an unchanged model on fp4 when fp4 is densest and both are dense', () => {
106+
expect(
107+
resolveEffectivePrecisions({
108+
selectedPrecisions: ['fp4'],
109+
availablePrecisions: ['fp4', 'fp8'],
110+
curveCounts: { fp4: 28, fp8: 5 },
111+
explicit: false,
112+
}),
113+
).toEqual(['fp4']);
114+
});
115+
116+
it('honors an explicit selection even when it is the sparse precision', () => {
117+
expect(
118+
resolveEffectivePrecisions({
119+
selectedPrecisions: ['fp4'],
120+
availablePrecisions: M3_AVAIL,
121+
curveCounts: M3_COUNTS,
122+
explicit: true,
123+
}),
124+
).toEqual(['fp4']);
125+
});
126+
127+
it('honors an explicit multi-precision selection (e.g. a preset)', () => {
128+
expect(
129+
resolveEffectivePrecisions({
130+
selectedPrecisions: ['fp4', 'fp8'],
131+
availablePrecisions: M3_AVAIL,
132+
curveCounts: M3_COUNTS,
133+
explicit: true,
134+
}),
135+
).toEqual(['fp4', 'fp8']);
136+
});
137+
138+
it('drops explicitly-selected precisions that are unavailable, falling back to first available', () => {
139+
expect(
140+
resolveEffectivePrecisions({
141+
selectedPrecisions: ['fp8'],
142+
availablePrecisions: ['fp4'],
143+
curveCounts: { fp4: 10 },
144+
explicit: true,
145+
}),
146+
).toEqual(['fp4']);
147+
});
148+
149+
it('includes a loaded unofficial run precision so the overlay is visible by default', () => {
150+
// Both official precisions dense → base is the sole densest (fp8); the user
151+
// opened an fp4 unofficial run, so fp4 must be merged in.
152+
expect(
153+
resolveEffectivePrecisions({
154+
selectedPrecisions: ['fp4'],
155+
availablePrecisions: ['fp4', 'fp8'],
156+
curveCounts: { fp4: 23, fp8: 38 },
157+
unofficialPrecisions: ['fp4'],
158+
explicit: false,
159+
}),
160+
).toEqual(['fp4', 'fp8']);
161+
});
162+
163+
it('ignores unofficial precisions that have no available data', () => {
164+
expect(
165+
resolveEffectivePrecisions({
166+
selectedPrecisions: ['fp4'],
167+
availablePrecisions: ['fp4', 'fp8'],
168+
curveCounts: { fp4: 23, fp8: 38 },
169+
unofficialPrecisions: ['int4'],
170+
explicit: false,
171+
}),
172+
).toEqual(['fp8']);
173+
});
174+
175+
it('falls back to the first available precision when curve data is missing (still loading)', () => {
176+
expect(
177+
resolveEffectivePrecisions({
178+
selectedPrecisions: ['fp4'],
179+
availablePrecisions: ['fp4'],
180+
curveCounts: {},
181+
explicit: false,
182+
}),
183+
).toEqual(['fp4']);
184+
});
185+
});

0 commit comments

Comments
 (0)