Xzero UI
Pro library

Speculative decodingPro

An illustration of speculative decoding: a fast draft model guesses a few tokens, the target model checks them in one pass, and accepted guesses join the answer.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/speculative-decoding
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/speculative-decoding

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { SpeculativeDecoding } from "@/components/xzero/speculative-decoding/speculative-decoding";

// Simulated: pass the answer and let the seeded draft guess.
<SpeculativeDecoding
  tokens={[{ text: "The" }, { text: " build", ease: 0.6, miss: " deploy" }, { text: " passed" }, { text: "." }]}
  defaultDraftLength={5}
  defaultCompare
/>

// Replayed: pass rounds recorded from your own server.
<SpeculativeDecoding
  rounds={[
    { draft: ["The", " build", " failed"], accepted: 2, target: " passed" },
    { draft: [], accepted: 0, target: "." },
  ]}
  onComplete={stats => console.log(stats.speedup)}
/>

API reference

SpeculativeDecoding

An illustration of speculative decoding in one card. A draft model lane proposes a few ghost tokens quickly; a target model lane checks them in one sweep. Accepted guesses get a check and travel into the answer, the first miss is struck through and replaced by the target's token, and the rest fade away. Rounds repeat until the sentence is done. A compare switch races a second line where the target writes one token per pass, while the speedup, the share of drafts accepted and the tokens per target pass roll up below. Every token in the answer is underlined in the color of the model that wrote it.

PropTypeDefaultDescription
tokensDecodeToken[]sampleTokensThe target model's answer, one entry per token with its leading space ({ text: " deploy" }). Optional ease (0 to 1) is how likely the draft guesses the token, and miss is what it proposes instead.
roundsDecodeRound[]–A recorded run to replay instead of the simulation: per round the draft tokens, how many were accepted from the start, and the target's own token. Hides the draft length slider.
draftLengthnumber–Tokens the draft guesses per round, 2 to 8 (controlled). Changing it replans and replays from the start.
defaultDraftLengthnumber4Draft length on first render.
onDraftLengthChange(length: number) => void–Called when the slider moves.
compareboolean–Shows the target only line and races it on the same clock (controlled).
defaultComparebooleanfalseCompare state on first render.
onCompareChange(compare: boolean) => void–Called when the compare switch changes.
autoplaybooleantrueStarts the run once, when the card is mostly in view. Never starts on its own with reduced motion.
seednumber12Seed for the simulated guesses. The same seed, tokens and draft length always give the same run.
draftCostnumber0.1Cost of one draft token as a share of a target pass. It sets how long drafting takes on screen and counts toward the speedup.
passDurationnumber640Milliseconds one target pass takes on screen.
titlestring"Speculative decoding"Card title and the group's accessible name.
draftLabel / draftDetailstring"Draft model" / "Small, fast"Name and detail of the draft lane. Keep them generic or clearly illustrative.
targetLabel / targetDetailstring"Target model" / "Large"Name and detail of the target lane.
status"ready" | "loading" | "error""ready"Loading dims the lanes and shimmers the status line; error shows the message with a retry. Controls are disabled in both.
errorstring–Message shown when status is "error".
onRetry() => void–Called by the retry button in the error state. The button is hidden without it.
onComplete(stats: DecodeStats) => void–Called each time the speculative line finishes, with passes, drafted, accepted, tokens, acceptance, tokensPerPass and speedup.
classNamestring–Class on the root element.
styleCSSProperties–Inline style on the root element.

Keyboard interactions

KeysAction
TabMoves through play or pause, restart, the draft length slider and the compare switch.
Enter, SpaceOn play or pause and restart, activates them. On the compare switch, toggles the race.
Arrow left / Arrow right, Home, EndOn the draft length slider, changes the length by one or jumps to 2 or 8. The run replays with the new length.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in illustrations

Guidance for AI tools

Speculative decoding: An illustration of speculative decoding: a fast draft model guesses a few tokens, the target model checks them in one pass, and accepted guesses join the answer. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components