Skip to content

Work on part of speculative decoding in TKW - #741

Draft
tpopp wants to merge 1 commit into
iree-org:mainfrom
tpopp:speculative-decoding-tail
Draft

Work on part of speculative decoding in TKW#741
tpopp wants to merge 1 commit into
iree-org:mainfrom
tpopp:speculative-decoding-tail

Conversation

@tpopp

@tpopp tpopp commented Apr 22, 2025

Copy link
Copy Markdown

This is incomplete, but I tried to leave TODO's for the obvious incomplete portions. It has not been run yet as it was trying to get all the pieces outlined.

Handles the following:

last_offset = cur_prob_offset
q = target_probs[bx, last_offset]
p = draft_probs[bx, last_offset] if num_accepted_tokens !=
num_speculative_tokens - 1 else torch.zeros_like(q)
relu_diff = torch.relu(q - p)
sum_relu = relu_diff.sum()

u = coin * sum_relu
sampled_id = d - 1
aggregate = 0.0
for i in range(d):
    val = relu_diff[i]
    if val <= 0:
	continue
    aggregate += val
    if aggregate > u:
	sampled_id = i
	break

This is incomplete, but I tried to leave TODO's for the obvious
incomplete portions. It has not been run yet as it was trying to get all
the pieces outlined.

Handles the following:
```
last_offset = cur_prob_offset
q = target_probs[bx, last_offset]
p = draft_probs[bx, last_offset] if num_accepted_tokens !=
num_speculative_tokens - 1 else torch.zeros_like(q)
relu_diff = torch.relu(q - p)
sum_relu = relu_diff.sum()

u = coin * sum_relu
sampled_id = d - 1
aggregate = 0.0
for i in range(d):
    val = relu_diff[i]
    if val <= 0:
	continue
    aggregate += val
    if aggregate > u:
	sampled_id = i
	break
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant