Verify Draft Tokens In Speculative Decoding

Last updated: November 29, 2026

Quick Overview

Implement the verification step of speculative decoding: given k tokens sampled from a draft model with their draft distributions and the target model's distributions for the k+1 positions, accept or reject tokens so that the output is distributed exactly as if sampled from the target model.

Fireworks AI
Coding & Algorithms
Machine Learning Engineer
Fireworks AI
November 29, 2026
Machine Learning Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Implement the verification step of speculative decoding: given k tokens sampled from a draft model with their draft distributions and the target model's distributions for the k+1 positions, accept or reject tokens so that the output is distributed exactly as if sampled from the target model.

Fireworks uses speculative decoding and custom draft models to raise tokens per second, and an inference engineer must get the acceptance rule exactly right or sampling quality silently changes. The interviewer looks for the min(1, p/q) rule, the residual distribution on rejection, and the bonus token.

What the Interviewer Expects
  • Accept each draft token with probability min(1, p(x)/q(x))
  • On rejection, sample from the normalized positive part of p minus q and stop
  • Sample a bonus token from the target when every draft token is accepted
  • Explain why the procedure preserves the target distribution
  • Verify empirically or by argument
Key Topics to Cover
Speculative decoding
Rejection sampling
Probability
LLM inference
Sampling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How does the expected number of accepted tokens depend on the draft acceptance rate and k?
  • How would you pick k adaptively per request?
  • What changes for greedy decoding?
  • How does this interact with batching when sequences accept different numbers of tokens?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs: draft tokens x_1..x_k, draft distributions q_i used to sample them, and target distributions p_0..p_k from one forward pass of the target over the prefix plus drafts. Output between 1 an...

High-Level Design

Walk the drafts in order. For token x, accept with probability min(1, p(x)/q(x)). On the first rejection, sample a replacement from norm(max(p - q, 0)) and stop, because later drafts were conditio...


Submit Your Answer
Markdown supported

Related Questions