Response (1/2)
Thanks for your comments.
Below, we use an example to thoroughly explain the theoretical guarantee of ReDrafter in producing the same distribution as the LLM. Regarding your question:
> Why is the output distribution unchanged?
This is guaranteed through the verification stage in speculative decoding, either with greedy decoding (when t=0) or speculative sampling (when t>0).
- A greedy decode example: if the drafter proposes `I like tea` and the LLM outputs `I am bob`, only the first token I is accepted to ensure a match.
- Speculative sampling: When we sample tokens from the drafter, the beam search method returns their log probabilities log Q(v), in addition to v. To verify v, we pass the token before v to the LLM, which returns log P(v). Given v, log Q(v), and log P(v), we follow the routine:
- Step 1: accept v with probability min(1,P(v)/Q(v)).
- Step 2.1: if v is accepted, continue to the next token proposed by the drafter.
- Step 2.2: if v is rejected, sample v from an un-normalized distribution R(v)=max(0, P(v)-Q(v)).
Consider a simple vocabulary with only two tokens: A and B. Assume that Q(A)=Q(B)=1/2, P(A)=1/4, and P(B)=3/4.
```
P(B)=3/4
▄▄
Q(A)=1/2 Q(B)=1/2 ██
┌─┐ P(A)=1/4 ┌─┐ ██
│ │ ▄▄ │ │ ██
└─┘ ▀▀ └─┘ ▀▀
----------------------------------------
A B
```
Assume that sampling from Q(v) produces a token A. Since the true probability of A, P(A), is lower than Q(A), we accept A with a probability of P(A)/Q(A)=1/2 and reject it with a probability of 1-P(A)/Q(A)=1/2. Now, assume that sampling from Q(v) produces a token B. Since the true probability P(B) is higher than Q(B), we always accept B. This procedure results in the following outcomes:
- Acceptance of v=A with probability 1/4.
- Acceptance of v=B with probability 1/2.
- Rejection with probability 1/4.
If the token is rejected, we resample from a tilted, unnormalized distribution R(v)=max(0,P(v)−Q(v)).
```
R(B)=1/4
▄▄
R(A)=0 ▀▀
-------------------------
A B
```
In this case, R(A)=0, R(B)=1/4, meaning sampling from R yields B almost surely. The overall probably of selecting B is 1/2+1/4=3/4, which matches the LLM's probability.
Append A.1 of the paper at [1] shows that the above intuition is exactly what we need to do to alter drafter samples such that they look like LLM samples.
[1] Y. Leviathan et al. Fast Inference from Transformers via Speculative Decoding. ICML 2023.