Verify speculative decoding proposals
Verify a block of draft tokens with rejection sampling.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input draft is a list of candidate token IDs; q and p contain normalized nonnegative draft and target probability vectors for each proposal. q[i][draft[i]] > 0. uniforms provides one acceptance draw in [0,1) per proposal. Accept while draw < min(1,p/q). At first rejection sample once from normalized max(p−q,0) with replacement_draw and stop. If every proposal is accepted, sample one bonus token using bonus (a target distribution) and replacement_draw. Categorical draws use ascending ID and a strict cumulative boundary. Return tokens and accepted (number of accepted draft tokens).
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Verify a block of draft tokens with rejection sampling.
Reproduction
{"draft":[0,0,1],"p":[[0.8,0.2],[0.1,0.9],[0.2,0.8]],"q":[[0.7,0.3],[0.9,0.1],[0.3,0.7]],"uniforms":[0.99,0.5,0.1],"bonus":[1,0],"replacement_draw":0.5}{"tokens":[0,1],"accepted":1}{"draft":[],"p":[],"q":[],"uniforms":[],"bonus":[1,0],"replacement_draw":0.9}{"tokens":[0],"accepted":0}{"draft":[0,1],"p":[[0.7,0.3],[0.2,0.8]],"q":[[0.6,0.4],[0.4,0.6]],"uniforms":[0.9,0.9],"bonus":[0.2,0.8],"replacement_draw":0.1}{"tokens":[0,1,0],"accepted":2}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.