InferenceAI

Enter at least two characters to search.

Start free

Speculative Decode Acceptance

mediumInference20 min25 XP

A draft model proposes token IDs and a target model verifies them in order. Implement accepted_draft_tokens(draft, target) and return the longest prefix of draft that exactly matches target. Both inputs are lists of token IDs. Stop at the first mismatch or the end of either list. This simplified exercise covers prefix acceptance, not sampling-based speculative decoding.

Examples

EXAMPLE WALKTHROUGHfirst mismatch

A guided view of the published example, not a trace of your code.

INPUT[[10,11,12,13],[10,11,99,13]]
TASKaccepted_draft_tokens()
EXPECTED OUTPUT[10,11]

Start with the input values shown in this example.

Example 1 of 2

Input: draft = [10,11,12,13], target = [10,11,99,13]

Output: [10,11]

Explanation: first mismatch

Input: draft = [1,2], target = [1,2,3]

Output: [1,2]

Explanation: all draft tokens

Hint 1

A mismatch ends the accepted prefix immediately.

Topics

PythonSpeculative DecodingInference