Spaces:
Running on CPU Upgrade

stevhliu HF Staff commited on
Commit
9b65d3b
·
1 Parent(s): 0ce8cee

Replace the precision dropdown with a hover receipt

Browse files

The dropdown made you commit to a precision before it would tell you
anything. Now the four capabilities that actually decide the choice — can it
quantize on load, does it compile, does it fine-tune, does it save — hang off
the tick itself.

- MethodReceipt lists each method with all four capabilities in fixed lanes,
supported in the accent and everything else greyed, so the shape of a row
reads before any word does. A legend defines the four once, including "?"
for cells the upstream docs leave blank and "*" for partial.
- Ticks become 44-unit hit targets with tabIndex and labels: a 2px dotted
line is not something you can point at, and it was not reachable by
keyboard at all.
- Method names link to their Transformers docs page.
- Closing waits 160ms so the pointer can travel to the card, which sits
outside the container's box and would otherwise dismiss on approach.
- The bar opens at the largest precision that fits rather than a default of
4-bit, since there is no longer a control to change it.

The trade-off map is gone from this screen; /compare still uses it.

.claude/launch.json CHANGED
@@ -3,7 +3,7 @@
3
  "configurations": [
4
  {
5
  "name": "quantization-picker",
6
- "runtimeExecutable": "npm",
7
  "runtimeArgs": ["run", "dev"],
8
  "port": 3000
9
  }
 
3
  "configurations": [
4
  {
5
  "name": "quantization-picker",
6
+ "runtimeExecutable": "pnpm",
7
  "runtimeArgs": ["run", "dev"],
8
  "port": 3000
9
  }
app/page.tsx CHANGED
@@ -1,23 +1,40 @@
1
  "use client";
2
 
3
  import { useState } from "react";
4
- import SentenceSelect from "@/components/SentenceSelect";
5
  import SentenceCombobox from "@/components/SentenceCombobox";
6
  import ModelInput from "@/components/ModelInput";
7
  import MemoryBar from "@/components/MemoryBar";
8
- import TradeoffMap from "@/components/TradeoffMap";
9
- import { GOALS, GPUS, PRECISIONS, methodsFor, type Model } from "@/lib/data";
 
 
 
 
 
 
 
 
10
 
11
  export default function CalculatorPage() {
12
  const [model, setModel] = useState<Model | null>(null);
13
  const [gpuId, setGpuId] = useState("a100-80gb");
14
- const [bits, setBits] = useState(4);
15
 
16
  const gpu = GPUS.find((g) => g.id === gpuId)!;
17
  const contextTokens = 8192;
18
- // No goal filter on this screen — every method that can hit this precision
19
- // on this backend belongs on the map.
20
- const methods = methodsFor(bits, gpu.backend, GOALS[0]);
 
 
 
 
 
 
 
 
 
 
21
 
22
  return (
23
  <main className="mx-auto w-full max-w-[1280px] px-10 pb-24 pt-20">
@@ -44,35 +61,12 @@ export default function CalculatorPage() {
44
  model={model}
45
  gpu={gpu}
46
  contextTokens={contextTokens}
47
- selectedBits={bits}
 
 
 
48
  />
49
  </div>
50
-
51
- {model && (
52
- <>
53
- <div className="flex flex-wrap items-center gap-2.5 pt-10">
54
- <span className="text-[40px] font-medium leading-[44px] tracking-[-0.04em] text-stone">
55
- Quantize to
56
- </span>
57
- <SentenceSelect
58
- ariaLabel="Precision"
59
- value={String(bits)}
60
- options={PRECISIONS.map((p) => ({ id: String(p), label: `${p}-bit` }))}
61
- onChange={(v) => setBits(Number(v))}
62
- />
63
- </div>
64
-
65
- {methods.length > 0 ? (
66
- <div className="pt-8">
67
- <TradeoffMap methods={methods} />
68
- </div>
69
- ) : (
70
- <p className="label pt-5 text-graphite">
71
- No method supports {bits}-bit on {gpu.label}
72
- </p>
73
- )}
74
- </>
75
- )}
76
  </main>
77
  );
78
  }
 
1
  "use client";
2
 
3
  import { useState } from "react";
 
4
  import SentenceCombobox from "@/components/SentenceCombobox";
5
  import ModelInput from "@/components/ModelInput";
6
  import MemoryBar from "@/components/MemoryBar";
7
+ import MethodReceipt from "@/components/MethodReceipt";
8
+ import {
9
+ GOALS,
10
+ GPUS,
11
+ PRECISIONS,
12
+ methodsFor,
13
+ overheadGB,
14
+ weightsGB,
15
+ type Model,
16
+ } from "@/lib/data";
17
 
18
  export default function CalculatorPage() {
19
  const [model, setModel] = useState<Model | null>(null);
20
  const [gpuId, setGpuId] = useState("a100-80gb");
21
+ const [hoverBits, setHoverBits] = useState<number | null>(null);
22
 
23
  const gpu = GPUS.find((g) => g.id === gpuId)!;
24
  const contextTokens = 8192;
25
+
26
+ // With no dropdown, the bar shows the largest precision that still fits —
27
+ // the best quality you can have — until you point at a different tick.
28
+ const overhead = model ? overheadGB(model, contextTokens) : 0;
29
+ const bestFitting =
30
+ model &&
31
+ PRECISIONS.find((p) => weightsGB(model, p) + overhead <= gpu.vram);
32
+ const shownBits = hoverBits ?? bestFitting ?? 4;
33
+
34
+ // No goal filter: every method that reaches this precision on this backend.
35
+ const methods = hoverBits
36
+ ? methodsFor(hoverBits, gpu.backend, GOALS[0])
37
+ : [];
38
 
39
  return (
40
  <main className="mx-auto w-full max-w-[1280px] px-10 pb-24 pt-20">
 
61
  model={model}
62
  gpu={gpu}
63
  contextTokens={contextTokens}
64
+ selectedBits={shownBits}
65
+ hoverBits={hoverBits}
66
+ onHoverBits={setHoverBits}
67
+ hoverCard={<MethodReceipt methods={methods} />}
68
  />
69
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </main>
71
  );
72
  }
components/MemoryBar.tsx CHANGED
@@ -1,5 +1,7 @@
1
  "use client";
2
 
 
 
3
  import {
4
  Model,
5
  Gpu,
@@ -13,6 +15,8 @@ import {
13
  const W = 1180;
14
  const BAR_H = 55;
15
  const R = 5.5;
 
 
16
 
17
  interface Props {
18
  /** null until a model resolves — the bar renders empty, but to scale */
@@ -20,13 +24,20 @@ interface Props {
20
  gpu: Gpu;
21
  contextTokens: number;
22
  selectedBits: number;
 
 
 
 
 
 
23
  }
24
 
25
  interface Tick {
26
  bits: number;
27
  total: number;
28
  x: number;
29
- row: 0 | 1;
 
30
  }
31
 
32
  /** Round a scale ceiling up to something a human would pick. */
@@ -35,16 +46,9 @@ function niceCeil(v: number): number {
35
  return Math.ceil(v / step) * step;
36
  }
37
 
38
- export default function MemoryBar({ model, gpu, contextTokens, selectedBits }: Props) {
39
- if (!model) return <EmptyBar />;
40
- return (
41
- <FilledBar
42
- model={model}
43
- gpu={gpu}
44
- contextTokens={contextTokens}
45
- selectedBits={selectedBits}
46
- />
47
- );
48
  }
49
 
50
  /**
@@ -64,7 +68,7 @@ function EmptyBar() {
64
  );
65
  }
66
 
67
- function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model: Model }) {
68
  const overhead = overheadGB(model, contextTokens);
69
  const vram = gpu.vram;
70
 
@@ -74,9 +78,12 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
74
  const selTotal = selWeights + overhead;
75
  const ghostTotal = weightsGB(model, 16) + overhead;
76
 
77
- // The scale follows the selection, so the bar always fills the frame. fp16
78
- // is free to run off the end.
79
- const scaleMax = niceCeil(Math.max(selTotal, vram) * 1.02);
 
 
 
80
  const x = (gb: number) => (gb / scaleMax) * W;
81
 
82
  const overflows = selTotal > vram;
@@ -88,41 +95,71 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
88
  const ghostEnd = x(ghostTotal);
89
  const ghostClipped = ghostEnd > W;
90
  const ghostRight = Math.min(ghostEnd, W - 0.5);
 
 
 
 
 
 
91
  // The callout needs ~215px; right-align it on the block when it would run off.
92
  const kvLabelFlips = kvStart + 215 > W;
93
  // Two totals this close would overprint.
94
- const showGhostLabel = ghostRight - barEnd >= 64;
95
 
96
- // Precision ticks, staggered onto a second row when they would collide.
97
- const MIN_GAP = 68;
98
- const lastX: [number, number] = [-Infinity, -Infinity];
 
 
 
 
 
99
  const ticks: Tick[] = PRECISIONS.map((bits) => {
100
  const total = weightsGB(model, bits) + overhead;
101
- return { bits, total, x: x(total), row: 0 as 0 | 1 };
102
  })
103
  .filter((t) => t.total <= scaleMax)
104
  .sort((a, b) => a.x - b.x)
105
  .map((t) => {
106
- const row: 0 | 1 = t.x - lastX[0] >= MIN_GAP ? 0 : 1;
 
107
  lastX[row] = t.x;
108
  return { ...t, row };
109
  });
110
 
111
- const staggered = ticks.some((t) => t.row === 1);
112
- const barTop = staggered ? 100 : 84;
 
 
113
  const barBottom = barTop + BAR_H;
114
  const height = barBottom + 66;
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  return (
 
117
  <svg viewBox={`0 0 ${W} ${height}`} className="h-auto w-full" role="img"
118
  aria-label={`${model.label} at ${selectedBits}-bit needs ${round1(selTotal)} GB of the ${vram} GB on ${gpu.label}`}>
119
  {/* precision labels + drop lines above the bar */}
120
  {ticks.map((t) => {
121
  const accent = PRECISION_ACCENT[t.bits];
122
  const isSel = t.bits === selectedBits;
123
- const nameY = t.row === 0 ? 11 : 53;
124
- const valY = t.row === 0 ? 29 : 71;
125
- const lineTop = t.row === 0 ? 40 : 82;
126
  return (
127
  <g key={t.bits}>
128
  <text x={t.x} y={nameY} textAnchor="middle" fontFamily="var(--font-geist-mono)"
@@ -164,7 +201,7 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
164
  <path
165
  d={
166
  ghostClipped
167
- ? `M${ghostRight} ${barTop + 0.5} H${R} A${R} ${R} 0 0 0 0.5 ${barTop + R} V${barBottom - R} A${R} ${R} 0 0 0 ${R} ${barBottom + 0.5} H${ghostRight}`
168
  : `M${ghostRight} ${barTop + 0.5} H${R} A${R} ${R} 0 0 0 0.5 ${barTop + R} V${barBottom - R} A${R} ${R} 0 0 0 ${R} ${barBottom + 0.5} H${ghostRight} Z`
169
  }
170
  fill="none"
@@ -173,7 +210,7 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
173
  strokeDasharray="2 3"
174
  />
175
  {showGhostLabel && (
176
- <text x={ghostRight - 6} y={barTop - 8} textAnchor="end"
177
  fontFamily="var(--font-geist-mono)" fontSize="11" letterSpacing="0.79" fill="#a8a8a8">
178
  {round1(ghostTotal)} AT FP16{ghostClipped ? " ›" : ""}
179
  </text>
@@ -203,6 +240,32 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
203
  );
204
  })}
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  {/* in-bar figures */}
207
  {kvStart >= 52 && (
208
  <text x="16" y={barTop + 32} fontFamily="var(--font-geist-mono)" fontSize="13" fill="#fafafa">
@@ -216,13 +279,35 @@ function FilledBar({ model, gpu, contextTokens, selectedBits }: Props & { model:
216
  </text>
217
  )}
218
 
219
- {/* capacity line */}
220
- <line x1={x(vram)} y1={barBottom} x2={x(vram)} y2={barBottom + 12} stroke="#171717" strokeWidth="1.5" />
221
- <text x={x(vram)} y={barBottom + 30} textAnchor="middle" fontFamily="var(--font-geist-mono)"
222
- fontSize="13" fill="#171717">
223
- {vram}
224
- </text>
 
 
 
 
 
225
 
226
  </svg>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  );
228
  }
 
1
  "use client";
2
 
3
+ import { useCallback, useEffect, useRef } from "react";
4
+
5
  import {
6
  Model,
7
  Gpu,
 
15
  const W = 1180;
16
  const BAR_H = 55;
17
  const R = 5.5;
18
+ /** Pointer band around each tick, in viewBox units. */
19
+ const HIT_W = 44;
20
 
21
  interface Props {
22
  /** null until a model resolves — the bar renders empty, but to scale */
 
24
  gpu: Gpu;
25
  contextTokens: number;
26
  selectedBits: number;
27
+ /** fires with the precision under the cursor, or null on leave */
28
+ onHoverBits?: (bits: number | null) => void;
29
+ /** which tick is under the cursor, so the bar can anchor the card to it */
30
+ hoverBits?: number | null;
31
+ /** rendered under the hovered tick, positioned by the bar */
32
+ hoverCard?: React.ReactNode;
33
  }
34
 
35
  interface Tick {
36
  bits: number;
37
  total: number;
38
  x: number;
39
+ /** which label row this tick's caption sits on, 0 = closest to the bar */
40
+ row: number;
41
  }
42
 
43
  /** Round a scale ceiling up to something a human would pick. */
 
46
  return Math.ceil(v / step) * step;
47
  }
48
 
49
+ export default function MemoryBar(props: Props) {
50
+ if (!props.model) return <EmptyBar />;
51
+ return <FilledBar {...props} model={props.model} />;
 
 
 
 
 
 
 
52
  }
53
 
54
  /**
 
68
  );
69
  }
70
 
71
+ function FilledBar({ model, gpu, contextTokens, selectedBits, onHoverBits, hoverBits, hoverCard }: Props & { model: Model }) {
72
  const overhead = overheadGB(model, contextTokens);
73
  const vram = gpu.vram;
74
 
 
78
  const selTotal = selWeights + overhead;
79
  const ghostTotal = weightsGB(model, 16) + overhead;
80
 
81
+ // The scale follows the model, not the card: a 2B model on an 80GB card would
82
+ // otherwise crowd all four precisions into a few pixels. It spans the widest
83
+ // precision on offer, so every tick stays readable. fp16 and — when the model
84
+ // fits comfortably — the capacity mark are free to run off the end.
85
+ const widestTick = Math.max(...PRECISIONS.map((b) => weightsGB(model, b) + overhead));
86
+ const scaleMax = niceCeil(Math.max(selTotal, widestTick) * 1.02);
87
  const x = (gb: number) => (gb / scaleMax) * W;
88
 
89
  const overflows = selTotal > vram;
 
95
  const ghostEnd = x(ghostTotal);
96
  const ghostClipped = ghostEnd > W;
97
  const ghostRight = Math.min(ghostEnd, W - 0.5);
98
+ // The track's corners are rounded, so a clipped ghost must stop before the
99
+ // curve begins or its horizontals cut across the corner.
100
+ const ghostRunEnd = ghostClipped ? W - R - 0.5 : ghostRight;
101
+ // The card only needs showing while it is in play.
102
+ const capX = x(vram);
103
+ const capOff = capX > W;
104
  // The callout needs ~215px; right-align it on the block when it would run off.
105
  const kvLabelFlips = kvStart + 215 > W;
106
  // Two totals this close would overprint.
107
+ const showGhostLabel = ghostRunEnd - barEnd >= 64;
108
 
109
+ // Precision labels are ~56px wide; anything closer than that overprints. Each
110
+ // tick takes the first row with room, so a small model — whose four
111
+ // precisions can land within a few pixels of each other — fans out upward
112
+ // instead of stacking into one illegible blur. The lines stay at their true
113
+ // x: only the captions move.
114
+ const MIN_GAP = 56;
115
+ const ROW_H = 42;
116
+ const lastX: number[] = [];
117
  const ticks: Tick[] = PRECISIONS.map((bits) => {
118
  const total = weightsGB(model, bits) + overhead;
119
+ return { bits, total, x: x(total), row: 0 };
120
  })
121
  .filter((t) => t.total <= scaleMax)
122
  .sort((a, b) => a.x - b.x)
123
  .map((t) => {
124
+ let row = 0;
125
+ while (lastX[row] !== undefined && t.x - lastX[row] < MIN_GAP) row++;
126
  lastX[row] = t.x;
127
  return { ...t, row };
128
  });
129
 
130
+ // Row 0 is the topmost caption and has the longest drop line; each extra row
131
+ // sits 42px lower, so more rows push the bar down.
132
+ const rows = Math.max(1, lastX.length);
133
+ const barTop = Math.max(84, 40 + (rows - 1) * ROW_H + 18);
134
  const barBottom = barTop + BAR_H;
135
  const height = barBottom + 66;
136
 
137
+ // The card hangs below the chart, outside this container's box, so pointing
138
+ // at it would otherwise read as leaving. Closing waits a beat, and anything
139
+ // the pointer lands on in the meantime cancels it.
140
+ const closeTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
141
+ const cancelClose = useCallback(() => clearTimeout(closeTimer.current), []);
142
+ const scheduleClose = useCallback(() => {
143
+ clearTimeout(closeTimer.current);
144
+ closeTimer.current = setTimeout(() => onHoverBits?.(null), 160);
145
+ }, [onHoverBits]);
146
+ useEffect(() => () => clearTimeout(closeTimer.current), []);
147
+
148
+ const anchor = ticks.find((t) => t.bits === hoverBits);
149
+ // Past the midpoint the card would run off, so hang it from its right edge.
150
+ const flips = anchor ? anchor.x > W * 0.55 : false;
151
+
152
  return (
153
+ <div className="relative">
154
  <svg viewBox={`0 0 ${W} ${height}`} className="h-auto w-full" role="img"
155
  aria-label={`${model.label} at ${selectedBits}-bit needs ${round1(selTotal)} GB of the ${vram} GB on ${gpu.label}`}>
156
  {/* precision labels + drop lines above the bar */}
157
  {ticks.map((t) => {
158
  const accent = PRECISION_ACCENT[t.bits];
159
  const isSel = t.bits === selectedBits;
160
+ const nameY = 11 + t.row * ROW_H;
161
+ const valY = 29 + t.row * ROW_H;
162
+ const lineTop = 40 + t.row * ROW_H;
163
  return (
164
  <g key={t.bits}>
165
  <text x={t.x} y={nameY} textAnchor="middle" fontFamily="var(--font-geist-mono)"
 
201
  <path
202
  d={
203
  ghostClipped
204
+ ? `M${ghostRunEnd} ${barTop + 0.5} H${R} A${R} ${R} 0 0 0 0.5 ${barTop + R} V${barBottom - R} A${R} ${R} 0 0 0 ${R} ${barBottom + 0.5} H${ghostRunEnd}`
205
  : `M${ghostRight} ${barTop + 0.5} H${R} A${R} ${R} 0 0 0 0.5 ${barTop + R} V${barBottom - R} A${R} ${R} 0 0 0 ${R} ${barBottom + 0.5} H${ghostRight} Z`
206
  }
207
  fill="none"
 
210
  strokeDasharray="2 3"
211
  />
212
  {showGhostLabel && (
213
+ <text x={ghostRunEnd - 6} y={barTop - 8} textAnchor="end"
214
  fontFamily="var(--font-geist-mono)" fontSize="11" letterSpacing="0.79" fill="#a8a8a8">
215
  {round1(ghostTotal)} AT FP16{ghostClipped ? " ›" : ""}
216
  </text>
 
240
  );
241
  })}
242
 
243
+ {/* hit targets — a 2px line is not a pointer target, so give each tick a
244
+ band running the full height of its label and line */}
245
+ {ticks.map((t) => (
246
+ <rect
247
+ key={`hit-${t.bits}`}
248
+ x={t.x - HIT_W / 2}
249
+ y={0}
250
+ width={HIT_W}
251
+ height={barBottom}
252
+ fill="transparent"
253
+ className="cursor-pointer"
254
+ onMouseEnter={() => {
255
+ cancelClose();
256
+ onHoverBits?.(t.bits);
257
+ }}
258
+ onMouseLeave={scheduleClose}
259
+ onFocus={() => {
260
+ cancelClose();
261
+ onHoverBits?.(t.bits);
262
+ }}
263
+ tabIndex={0}
264
+ role="button"
265
+ aria-label={`${t.bits}-bit, ${round1(t.total)} GB`}
266
+ />
267
+ ))}
268
+
269
  {/* in-bar figures */}
270
  {kvStart >= 52 && (
271
  <text x="16" y={barTop + 32} fontFamily="var(--font-geist-mono)" fontSize="13" fill="#fafafa">
 
279
  </text>
280
  )}
281
 
282
+ {/* capacity line — shown only while the card is in frame; past the edge
283
+ it would just be a number with nothing to point at */}
284
+ {!capOff && (
285
+ <>
286
+ <line x1={capX} y1={barBottom} x2={capX} y2={barBottom + 12} stroke="#171717" strokeWidth="1.5" />
287
+ <text x={capX} y={barBottom + 30} textAnchor="middle" fontFamily="var(--font-geist-mono)"
288
+ fontSize="13" fill="#171717">
289
+ {vram}
290
+ </text>
291
+ </>
292
+ )}
293
 
294
  </svg>
295
+
296
+ {anchor && hoverCard && (
297
+ <div
298
+ className="absolute z-10"
299
+ onMouseEnter={cancelClose}
300
+ onMouseLeave={scheduleClose}
301
+ style={{
302
+ left: `${(anchor.x / W) * 100}%`,
303
+ // Below the whole chart, so it never covers the KV cache caption.
304
+ top: "calc(100% + 6px)",
305
+ transform: flips ? "translateX(-100%)" : undefined,
306
+ }}
307
+ >
308
+ {hoverCard}
309
+ </div>
310
+ )}
311
+ </div>
312
  );
313
  }
components/MethodReceipt.tsx ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import type { Method, Support } from "@/lib/data";
2
+
3
+ /**
4
+ * The four capabilities, in the order they appear on every row. Lane widths
5
+ * are fixed so a capability lands at the same x on every line — that is what
6
+ * makes the card scannable down a column without a header.
7
+ */
8
+ const LANES = [
9
+ { key: "load", label: "load", width: "w-[42px]" },
10
+ { key: "compile", label: "compile", width: "w-[64px]" },
11
+ { key: "tune", label: "tune", width: "w-[44px]" },
12
+ { key: "save", label: "save", width: "w-[40px]" },
13
+ ] as const;
14
+
15
+ interface Cell {
16
+ /** the word as rendered, with its qualifier suffix */
17
+ text: string;
18
+ support: Support;
19
+ }
20
+
21
+ function cell(label: string, support: Support): Cell {
22
+ const suffix = support === "unknown" ? "?" : support === "partial" ? "*" : "";
23
+ return { text: label + suffix, support };
24
+ }
25
+
26
+ function cellsFor(m: Method): Cell[] {
27
+ return [
28
+ cell("load", m.onTheFly ? "yes" : "no"),
29
+ cell("compile", m.compile),
30
+ cell("tune", m.peft),
31
+ cell("save", m.serializable),
32
+ ];
33
+ }
34
+
35
+ /** Supported reads in the accent; everything else recedes. */
36
+ function toneFor(support: Support): string {
37
+ if (support === "yes") return "text-forest";
38
+ if (support === "partial") return "text-smoke";
39
+ return "text-ash";
40
+ }
41
+
42
+ /** Most capable first, so the row shapes go from solid to sparse. */
43
+ function score(m: Method): number {
44
+ return cellsFor(m).filter((c) => c.support === "yes").length;
45
+ }
46
+
47
+ export default function MethodReceipt({ methods }: { methods: Method[] }) {
48
+ if (methods.length === 0) {
49
+ return (
50
+ <div className="w-[466px] rounded-[6px] bg-paper px-[17px] py-4 ring-hairline shadow-[0_6px_20px_rgb(0_0_0/7%)]">
51
+ <p className="font-mono text-[13px] text-graphite">
52
+ Nothing supports this precision here.
53
+ </p>
54
+ </div>
55
+ );
56
+ }
57
+
58
+ const ranked = [...methods].sort((a, b) => score(b) - score(a));
59
+
60
+ return (
61
+ <div className="w-[466px] rounded-[6px] bg-paper px-[17px] pb-[17px] pt-[15px] ring-hairline shadow-[0_6px_20px_rgb(0_0_0/7%)]">
62
+ <div className="flex flex-col gap-[9px]">
63
+ {ranked.map((m) => (
64
+ <div key={m.id} className="flex items-center gap-[9px]">
65
+ <a
66
+ href={m.docs}
67
+ target="_blank"
68
+ rel="noreferrer"
69
+ title={`${m.name} docs`}
70
+ className="w-[150px] shrink-0 truncate font-mono text-[13px] text-obsidian underline decoration-hairline decoration-1 underline-offset-[3px] hover:decoration-graphite focus-visible:decoration-graphite"
71
+ >
72
+ {m.name}
73
+ </a>
74
+ <span className="h-px flex-1 border-b border-dashed border-hairline" />
75
+ <span className="flex shrink-0 gap-2.5">
76
+ {cellsFor(m).map((c, i) => (
77
+ <span
78
+ key={LANES[i].key}
79
+ className={`${LANES[i].width} font-mono text-[11px] ${toneFor(c.support)}`}
80
+ >
81
+ {c.text}
82
+ </span>
83
+ ))}
84
+ </span>
85
+ </div>
86
+ ))}
87
+ </div>
88
+
89
+ <div className="mt-[11px] flex flex-col gap-[3px] border-t border-dashed border-hairline pt-[11px]">
90
+ <p className="font-mono text-[10px] leading-[15px] tracking-[0.04em] text-graphite">
91
+ load = quantizes as it loads, no prep step
92
+ </p>
93
+ <p className="font-mono text-[10px] leading-[15px] tracking-[0.04em] text-graphite">
94
+ compile = works under torch.compile
95
+ </p>
96
+ <p className="font-mono text-[10px] leading-[15px] tracking-[0.04em] text-graphite">
97
+ tune = fine-tunes with PEFT adapters
98
+ </p>
99
+ <p className="font-mono text-[10px] leading-[15px] tracking-[0.04em] text-graphite">
100
+ save = save_pretrained keeps it quantized
101
+ </p>
102
+ <p className="font-mono text-[10px] leading-[15px] tracking-[0.04em] text-ash">
103
+ ? = the docs do not say · * = partly
104
+ </p>
105
+ </div>
106
+ </div>
107
+ );
108
+ }
components/ModelInput.tsx CHANGED
@@ -1,7 +1,24 @@
1
  "use client";
2
 
3
- import { useRef, useState } from "react";
4
  import type { Model } from "@/lib/data";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  interface Props {
7
  onResolve: (model: Model | null) => void;
@@ -21,6 +38,12 @@ type Status =
21
  export default function ModelInput({ onResolve }: Props) {
22
  const [text, setText] = useState("");
23
  const [status, setStatus] = useState<Status>({ kind: "empty" });
 
 
 
 
 
 
24
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
25
  // Only the newest lookup may write state; earlier ones lose the race.
26
  const latest = useRef(0);
@@ -60,18 +83,39 @@ export default function ModelInput({ onResolve }: Props) {
60
  timer.current = setTimeout(() => lookup(id, ticket), 400);
61
  }
62
 
 
 
 
 
 
 
 
63
  return (
64
  <span className="relative inline-flex flex-col">
65
  <input
 
66
  aria-label="Model"
67
  value={text}
68
  onChange={(e) => handleChange(e.target.value)}
 
 
69
  placeholder="Qwen/Qwen3-32B"
70
  spellCheck={false}
71
  autoCapitalize="off"
72
  autoComplete="off"
73
- className="h-[52px] w-[420px] rounded-md bg-paper px-3.5 text-[40px] font-medium leading-[44px] tracking-[-0.04em] text-obsidian ring-raised outline-none placeholder:text-ash"
 
 
 
74
  />
 
 
 
 
 
 
 
 
75
  <span
76
  className="label absolute top-[56px] left-1 whitespace-nowrap text-graphite"
77
  role={status.kind === "error" ? "alert" : undefined}
 
1
  "use client";
2
 
3
+ import { useCallback, useRef, useState } from "react";
4
  import type { Model } from "@/lib/data";
5
+ import { elideMiddle } from "./elide";
6
+
7
+ // The field is a fixed 420px with 14px of padding either side. It does not
8
+ // grow with the name: a field that resized would shove the rest of the
9
+ // sentence around on every keystroke.
10
+ const TEXT_PX = 420 - 28;
11
+ const TRACKING = "-1.6px"; // -0.04em at 40px
12
+
13
+ /**
14
+ * The canvas cannot resolve `var(--font-geist-sans)`, so take the font the
15
+ * browser actually resolved on the field itself.
16
+ */
17
+ function fontOf(el: HTMLInputElement | null): string | null {
18
+ if (!el) return null;
19
+ const s = getComputedStyle(el);
20
+ return s.font || `${s.fontWeight} ${s.fontSize} ${s.fontFamily}`;
21
+ }
22
 
23
  interface Props {
24
  onResolve: (model: Model | null) => void;
 
38
  export default function ModelInput({ onResolve }: Props) {
39
  const [text, setText] = useState("");
40
  const [status, setStatus] = useState<Status>({ kind: "empty" });
41
+ const [focused, setFocused] = useState(false);
42
+ const [font, setFont] = useState<string | null>(null);
43
+ // A callback ref runs at commit, which is where the resolved font can be read.
44
+ const attachInput = useCallback((el: HTMLInputElement | null) => {
45
+ if (el) setFont(fontOf(el));
46
+ }, []);
47
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
48
  // Only the newest lookup may write state; earlier ones lose the race.
49
  const latest = useRef(0);
 
83
  timer.current = setTimeout(() => lookup(id, ticket), 400);
84
  }
85
 
86
+ // While the field is not being edited, a name too long for the box shows its
87
+ // middle elided so the tail — the part that names the checkpoint — stays
88
+ // visible. The input keeps the real value throughout.
89
+ const elided =
90
+ focused || !font ? text : elideMiddle(text, TEXT_PX, font, TRACKING);
91
+ const isElided = elided !== text;
92
+
93
  return (
94
  <span className="relative inline-flex flex-col">
95
  <input
96
+ ref={attachInput}
97
  aria-label="Model"
98
  value={text}
99
  onChange={(e) => handleChange(e.target.value)}
100
+ onFocus={() => setFocused(true)}
101
+ onBlur={() => setFocused(false)}
102
  placeholder="Qwen/Qwen3-32B"
103
  spellCheck={false}
104
  autoCapitalize="off"
105
  autoComplete="off"
106
+ title={isElided ? text : undefined}
107
+ className={`h-[52px] w-[420px] rounded-md bg-paper px-3.5 text-[40px] font-medium leading-[44px] tracking-[-0.04em] ring-raised outline-none placeholder:text-ash ${
108
+ isElided ? "text-transparent" : "text-obsidian"
109
+ }`}
110
  />
111
+ {isElided && (
112
+ <span
113
+ aria-hidden
114
+ className="pointer-events-none absolute inset-y-0 left-3.5 flex items-center text-[40px] font-medium leading-[44px] tracking-[-0.04em] text-obsidian"
115
+ >
116
+ {elided}
117
+ </span>
118
+ )}
119
  <span
120
  className="label absolute top-[56px] left-1 whitespace-nowrap text-graphite"
121
  role={status.kind === "error" ? "alert" : undefined}
components/elide.ts ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ let ctx: CanvasRenderingContext2D | null | undefined;
2
+
3
+ /** A shared canvas for text measurement; null during SSR. */
4
+ function measurer(): CanvasRenderingContext2D | null {
5
+ if (ctx === undefined) {
6
+ ctx =
7
+ typeof document === "undefined"
8
+ ? null
9
+ : document.createElement("canvas").getContext("2d");
10
+ }
11
+ return ctx;
12
+ }
13
+
14
+ /**
15
+ * Shorten `text` to fit `maxPx` by eating the middle:
16
+ * "openbmb/MiniCPM5-2B-sft-bf16" → "openb…2B-sft-bf16".
17
+ *
18
+ * The tail is what distinguishes one checkpoint from another, so it keeps two
19
+ * thirds of the budget; the owner prefix is the part you can afford to lose.
20
+ * Returns `text` unchanged when it already fits, or during SSR where there is
21
+ * nothing to measure with.
22
+ */
23
+ export function elideMiddle(
24
+ text: string,
25
+ maxPx: number,
26
+ font: string,
27
+ letterSpacing = "0px",
28
+ ): string {
29
+ const m = measurer();
30
+ if (!m || !text) return text;
31
+
32
+ m.font = font;
33
+ if ("letterSpacing" in m) m.letterSpacing = letterSpacing;
34
+ const fits = (s: string) => m.measureText(s).width <= maxPx;
35
+ if (fits(text)) return text;
36
+
37
+ for (let kept = text.length - 1; kept > 0; kept--) {
38
+ const head = Math.max(1, Math.round(kept / 3));
39
+ const tail = kept - head;
40
+ if (tail < 1) continue;
41
+ const candidate = `${text.slice(0, head)}…${text.slice(text.length - tail)}`;
42
+ if (fits(candidate)) return candidate;
43
+ }
44
+ return "…";
45
+ }