NumPy allowed · plain Python earns 10 bonus points
Softmax(logits) → probability distribution
Accelerate autoregressive inference without changing the target distribution using Speculative Decoding verification.
Implement verify_speculative_tokens(draft_tokens, draft_probs, target_probs, random_samples). For each step $i$, accept draft token $x$ if $u_i le min(1, P_{target}(x) / P_{draft}(x))$. If accepted, append to accepted_tokens. If rejected: resample from the adjusted distribution $P'(y) = ext{normalize}(max(0, P_{target}(y) - P_{draft}(y)))$ choosing the argmax token as bonus_token, and terminate verification. If all $K$ tokens are accepted and target_probs contains a step $K$, sample bonus_token as $argmax P_{target}(K)$. Return dict with accepted_tokens, bonus_token, and acceptance_count.
verify_speculative_tokens(draft_tokens: list[int], draft_probs: list[list[float]], target_probs: list[list[float]], random_samples: list[float]) -> dict