Memory Scale Viz
A horizontal-bar comparison primitive for the way memory consumption scales across operating points — sequence length, batch size, or model size sweeps. Each point renders as one bar at a shared scale; a dashed capacity line overlays the chart so the reader sees, by length, where the configuration overflows the GPU. Bars past the line tint into cb-error and the footer chip flips to exceeds capacity.
Memory scale. 5 points. small / 1B: 4.00 GiB; med / 3B: 16.0 GiB; large / 7B: 56.0 GiB; xl / 13B: 104 GiB (over capacity); xxl / 30B: 240 GiB (over capacity). Capacity: 80.0 GiB.
Memory scalecapacity 80.0 GiB
- small / 1B4.00 GiB
- med / 3B16.0 GiB
- large / 7B56.0 GiB
- xl / 13B104 GiB
- xxl / 30B240 GiB
exceeds capacity
Customize
Points
1.00x
large
Capacity
80 GiB
Installation
npx shadcn@latest add https://craftbits.dev/r/memory-scale-viz.jsonUsage
import { MemoryScaleViz } from "@craft-bits/core";
<MemoryScaleViz
points={[
{ id: "small", label: "small / 1B", memoryGb: 4 },
{ id: "med", label: "med / 3B", memoryGb: 16 },
{ id: "large", label: "large / 7B", memoryGb: 56 },
{ id: "xl", label: "xl / 13B", memoryGb: 104 },
{ id: "xxl", label: "xxl / 30B", memoryGb: 240 },
]}
capacityGb={80}
currentPoint="large"
/>Drive the highlighted point from a surrounding stepper or slider:
<MemoryScaleViz
points={points}
capacityGb={80}
currentPoint={selected}
/>Drop the capacity line for a pure-comparison readout:
<MemoryScaleViz points={points} capacityGb={undefined} />Understanding the component
- One shared denominator. Bar widths divide by
max(largest memoryGb, capacityGb)so the dashed capacity tick stays anchored at the right edge until a point actually overshoots it. Proportions across points stay honest — a small point never balloons just because no other bar is wider. - Capacity overlay. When
capacityGbis provided, a dashed vertical line is drawn over the bar column at the capacity position. The line tints tocb-erroronce any point overshoots it; otherwise it stays incb-border-strong. - Over-capacity tint. Bars whose
memoryGbexceedscapacityGbpaint incb-error(not the defaultcb-info), the numeric readout flips tocb-error, and the row carriesdata-over="true"for downstream styling. - Current-point highlight. Setting
currentPointto a point'sidstrengthens its fill (tocb-accent), surrounds the bar track with a 1px accent outline, and marks the row withdata-state="current". - Verdict chip. Below the chart, an
exceeds capacity/within capacitychip states the pass/fail state textually — colour is never the only signal. SPRINGS.smootheverywhere. Bar-width changes animate with the canonical smooth spring;prefers-reduced-motion: reducecollapses every spring to an instant swap.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
points | readonly { id: string; label: string; memoryGb: number }[] | — | Operating points to compare, in display order. |
capacityGb | number | 80 | GPU memory capacity in gibibytes (the dashed reference line and overflow threshold). Pass undefined to hide the capacity overlay and verdict chip. |
currentPoint | string | — | id of the point to visually highlight (stronger fill, accent outline, data-state="current"). |
transition | Transition | SPRINGS.smooth | Spring used for bar-width transitions. |
className | string | — | Merged onto the root via cn(). |
Accessibility
- The figure is
role="figure"with a hidden summary listing every point's label, GiB, and over-capacity state plus the capacity line — screen readers hear the whole comparison whenever props change. - Colour is never the only signal — each row pairs a textual label with a tabular-nums GiB readout, every over-capacity row carries
data-over="true", and the footer chip statesexceeds capacity/within capacityas words. - The current point is announced through both the visible label tone and the
data-state="current"attribute, not by colour alone. - Motion respects
prefers-reduced-motion: reduce.
Credits
- Extracted from:
craftingattention(app/src/lessons/primitives/nn/MemoryScaleViz.tsx). The source paired a single-bar log-scale plot of attention-matrix bytes with a discrete-step sequence-length slider, a four-phase narration state machine (observe / growing / overflow / insight), a hard-coded comparison row for flash attention'sO(N)memory, RTX 4090 and A100 capacity tick markers, a mini N×N-square animation on the left, an SVG breathing-pulse hint, a screen-reader live region, and aChallengeBtn-driven comparison toggle. The library extract is the pure plotting primitive — N operating points in, normalised bars out — driven entirely by props with motion-library springs, a single configurable capacity line, and acurrentPointhighlight hook for surrounding steppers.