Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 62 additions & 17 deletions packages/app/src/components/GlobalFilterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
SEQUENCE_OPTIONS,
} from '@/lib/data-mappings';
import { computeAutoSwitchDecision } from '@/lib/unofficial-run-auto-switch';
import { countCurvesByPrecision, resolveEffectivePrecisions } from '@/lib/default-precisions';
import type { AvailabilityRow, WorkflowInfoResponse } from '@/lib/api';

interface RunInfo {
Expand Down Expand Up @@ -149,17 +150,23 @@ export function GlobalFilterProvider({
return Sequence.EightK_OneK;
});

const [selectedPrecisions, setSelectedPrecisionsRaw] = useState<string[]>(() => {
if (initialPrecisions && initialPrecisions.length > 0) {
const valid = initialPrecisions.filter((p) =>
(PRECISION_OPTIONS as readonly string[]).includes(p),
);
if (valid.length > 0) return valid;
}
return [Precision.FP4];
});
const initialValidPrecisions = useMemo(
() =>
(initialPrecisions ?? []).filter((p) => (PRECISION_OPTIONS as readonly string[]).includes(p)),
[initialPrecisions],
);
const [selectedPrecisions, setSelectedPrecisionsRaw] = useState<string[]>(() =>
initialValidPrecisions.length > 0 ? initialValidPrecisions : [Precision.FP4],
);
// Whether the precision was chosen explicitly (seeded prop, URL `i_prec`,
// preset, or manual toggle). Until then we auto-pick the densest precision
// for the current model/sequence so FP8-heavy models don't open barren.
const [precisionExplicit, setPrecisionExplicit] = useState<boolean>(
() => initialValidPrecisions.length > 0,
);
const setSelectedPrecisions = useCallback((precisions: string[]) => {
setSelectedPrecisionsRaw(precisions);
setPrecisionExplicit(true);
}, []);

// ── Run date / run ID ─────────────────────────────────────────────────────
Expand Down Expand Up @@ -198,7 +205,10 @@ export function GlobalFilterProvider({
const precs = urlPrec
.split(',')
.filter((p) => (PRECISION_OPTIONS as readonly string[]).includes(p));
if (precs.length > 0) setSelectedPrecisionsRaw(precs);
if (precs.length > 0) {
setSelectedPrecisionsRaw(precs);
setPrecisionExplicit(true);
}
}
applyIfMatches('g_rundate', RUNDATE_RE, setSelectedRunDateBase);
applyIfMatches('g_runid', RUNID_RE, setSelectedRunId);
Expand Down Expand Up @@ -294,12 +304,44 @@ export function GlobalFilterProvider({
return merged.length > 0 ? merged : ['fp4'];
}, [availabilityRows, modelRows, effectiveSequence, unofficialAvailable, selectedModel]);

// Synchronously validated precisions
const effectivePrecisions = useMemo(() => {
const valid = selectedPrecisions.filter((p) => availablePrecisions.includes(p));
if (valid.length > 0) return valid;
return availablePrecisions.length > 0 ? [availablePrecisions[0]] : selectedPrecisions;
}, [selectedPrecisions, availablePrecisions]);
// Curve count per precision (distinct hw/framework/spec/disagg series) for the
// selected model + sequence — drives the auto default toward the densest one.
const precisionCurveCounts = useMemo(
() =>
countCurvesByPrecision(
modelRows.filter((r) => islOslToSequence(r.isl, r.osl) === effectiveSequence),
),
[modelRows, effectiveSequence],
);

// Precisions present in a loaded unofficial run for the current model + sequence.
const unofficialPrecisionsForSelection = useMemo(
() =>
unofficialAvailable
.filter((a) => a.model === selectedModel && a.sequence === effectiveSequence)
.flatMap((a) => a.precisions),
[unofficialAvailable, selectedModel, effectiveSequence],
);

// Synchronously validated precisions. When the user hasn't explicitly chosen a
// precision, auto-pick the densest (see resolveEffectivePrecisions).
const effectivePrecisions = useMemo(
() =>
resolveEffectivePrecisions({
selectedPrecisions,
availablePrecisions,
curveCounts: precisionCurveCounts,
unofficialPrecisions: unofficialPrecisionsForSelection,
explicit: precisionExplicit,
}),
[
selectedPrecisions,
availablePrecisions,
precisionCurveCounts,
unofficialPrecisionsForSelection,
precisionExplicit,
],
);

// Dates available for selected model + sequence + precisions
const availableDates = useMemo(() => {
Expand Down Expand Up @@ -397,14 +439,17 @@ export function GlobalFilterProvider({
g_rundate: selectedRunDate,
g_runid: selectedRunId,
i_seq: effectiveSequence,
i_prec: effectivePrecisions.join(','),
// Only pin the precision in the URL once chosen explicitly; in auto mode
// leave it out so the link keeps following the per-model densest default.
i_prec: precisionExplicit ? effectivePrecisions.join(',') : undefined,
});
}, [
selectedModel,
selectedRunDate,
selectedRunId,
effectiveSequence,
effectivePrecisions,
precisionExplicit,
setUrlParams,
]);

Expand Down
185 changes: 185 additions & 0 deletions packages/app/src/lib/default-precisions.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import { describe, expect, it } from 'vitest';

import {
MIN_SOLE_DEFAULT_CURVES,
countCurvesByPrecision,
pickDefaultPrecisions,
resolveEffectivePrecisions,
} from './default-precisions';

function row(precision: string, hardware: string, framework = 'vllm', disagg = false) {
return { precision, hardware, framework, spec_method: 'none', disagg };
}

describe('countCurvesByPrecision', () => {
it('counts distinct (hardware, framework, spec_method, disagg) per precision', () => {
const counts = countCurvesByPrecision([
row('fp8', 'b200'),
row('fp8', 'b300'),
row('fp8', 'b200'), // dup curve, not counted again
row('fp4', 'mi355x', 'atom'),
]);
expect(counts).toEqual({ fp8: 2, fp4: 1 });
});

it('treats disagg and non-disagg of the same hw as distinct curves', () => {
const counts = countCurvesByPrecision([
row('fp8', 'b200', 'vllm', false),
row('fp8', 'b200', 'vllm', true),
]);
expect(counts).toEqual({ fp8: 2 });
});

it('returns {} for no rows', () => {
expect(countCurvesByPrecision([])).toEqual({});
});
});

describe('pickDefaultPrecisions', () => {
it('picks the single densest precision only when every precision clears the threshold', () => {
// dsr1 shape: both dense.
expect(pickDefaultPrecisions({ fp4: 23, fp8: 38 })).toEqual(['fp8']);
});

it('shows both when one precision is below the threshold (MiniMax M3 shape)', () => {
// fp4 barren (1 curve) next to a dense fp8 → surface both, not just fp8.
expect(pickDefaultPrecisions({ fp4: 1, fp8: 14 })).toEqual(['fp4', 'fp8']);
});

it('keeps fp4 when it is the densest and both clear the threshold (dsv4 shape)', () => {
expect(pickDefaultPrecisions({ fp4: 28, fp8: 5 })).toEqual(['fp4']);
});

it('breaks ties in favor of fp4 when both clear the threshold', () => {
expect(pickDefaultPrecisions({ fp4: 8, fp8: 8 })).toEqual(['fp4']);
});

it('breaks non-fp4 ties by canonical enum order', () => {
// fp8 precedes bf16 in PRECISION_OPTIONS.
expect(pickDefaultPrecisions({ bf16: 6, fp8: 6 })).toEqual(['fp8']);
});

it('surfaces all precisions (sorted) when any is below threshold', () => {
expect(pickDefaultPrecisions({ fp8: 3, fp4: 2 })).toEqual(['fp4', 'fp8']);
// llama70b shape: fp4 sparse (3), fp8 dense (8) → both.
expect(pickDefaultPrecisions({ fp4: 3, fp8: 8 })).toEqual(['fp4', 'fp8']);
expect(MIN_SOLE_DEFAULT_CURVES).toBe(4);
});

it('returns the lone precision for a single-precision model regardless of count', () => {
expect(pickDefaultPrecisions({ fp4: 2 })).toEqual(['fp4']);
expect(pickDefaultPrecisions({ fp4: 10 })).toEqual(['fp4']);
});

it('returns [] when there are no precisions', () => {
expect(pickDefaultPrecisions({})).toEqual([]);
});
});

describe('resolveEffectivePrecisions', () => {
const M3_COUNTS = { fp4: 1, fp8: 14 };
const M3_AVAIL = ['fp4', 'fp8'];

it('auto-defaults to both when one precision is sparse (M3 → fp4 + fp8)', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: M3_AVAIL,
curveCounts: M3_COUNTS,
explicit: false,
}),
).toEqual(['fp4', 'fp8']);
});

it('auto-defaults to the densest precision when every precision is dense (dsr1 → fp8)', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: ['fp4', 'fp8'],
curveCounts: { fp4: 23, fp8: 38 },
explicit: false,
}),
).toEqual(['fp8']);
});

it('leaves an unchanged model on fp4 when fp4 is densest and both are dense', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: ['fp4', 'fp8'],
curveCounts: { fp4: 28, fp8: 5 },
explicit: false,
}),
).toEqual(['fp4']);
});

it('honors an explicit selection even when it is the sparse precision', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: M3_AVAIL,
curveCounts: M3_COUNTS,
explicit: true,
}),
).toEqual(['fp4']);
});

it('honors an explicit multi-precision selection (e.g. a preset)', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4', 'fp8'],
availablePrecisions: M3_AVAIL,
curveCounts: M3_COUNTS,
explicit: true,
}),
).toEqual(['fp4', 'fp8']);
});

it('drops explicitly-selected precisions that are unavailable, falling back to first available', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp8'],
availablePrecisions: ['fp4'],
curveCounts: { fp4: 10 },
explicit: true,
}),
).toEqual(['fp4']);
});

it('includes a loaded unofficial run precision so the overlay is visible by default', () => {
// Both official precisions dense → base is the sole densest (fp8); the user
// opened an fp4 unofficial run, so fp4 must be merged in.
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: ['fp4', 'fp8'],
curveCounts: { fp4: 23, fp8: 38 },
unofficialPrecisions: ['fp4'],
explicit: false,
}),
).toEqual(['fp4', 'fp8']);
});

it('ignores unofficial precisions that have no available data', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: ['fp4', 'fp8'],
curveCounts: { fp4: 23, fp8: 38 },
unofficialPrecisions: ['int4'],
explicit: false,
}),
).toEqual(['fp8']);
});

it('falls back to the first available precision when curve data is missing (still loading)', () => {
expect(
resolveEffectivePrecisions({
selectedPrecisions: ['fp4'],
availablePrecisions: ['fp4'],
curveCounts: {},
explicit: false,
}),
).toEqual(['fp4']);
});
});
Loading
Loading