Skip to content

[V1][Spec Decode] Implement Eagle Proposer [1/N] #15729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 1, 2025
Merged

Conversation

WoosukKwon
Copy link
Collaborator

@WoosukKwon WoosukKwon commented Mar 28, 2025

Efficient implementation based upon #15346

NOTE1: I intentionally used a dummy model instead of the real eagle models to reduce the scope of the PR.

NOTE2: Currently, I intentionally ignored all sampling parameters except the temperature when sampling the draft tokens.
The reason being is,

  1. Ignoring the sampling parameter for draft tokens doesn’t change the final outputs after rejection sampling, only affecting the acceptance rate.
  2. Given that the draft model is small, applying top-p, top-k, etc. could be relatively very expensive. I hypothesize that avoiding these expensive ops despite slightly degraded acceptance rate would lead to better end performance.

cc @sroy745 @LiuXiaoxuanPKU

Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@mergify mergify bot added the v1 label Mar 28, 2025
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
logits.div_(sampling_metadata.temperature)
probs = logits.softmax(dim=-1, dtype=torch.float32)

# TODO(woosuk): Consider seeds?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure seeds will work with conditional speculation and rejection sampling? :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TODO. I'd like to defer this to a future PR because 1) the sampling code in the PR needs some refactoring anyways, and 2) handling RNG in spec decoding is quite tricky, so I need more time to think more about it.

Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Signed-off-by: Woosuk Kwon <[email protected]>
Copy link
Collaborator

@LiuXiaoxuanPKU LiuXiaoxuanPKU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me, just have some questions. Also, we might want some tests for this PR? Maybe move some from #15346 if possible?

probs = logits.softmax(dim=-1, dtype=torch.float32)

# TODO(woosuk): Consider seeds?
q = torch.empty_like(logits)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least we need to enable seed for reproducibility? i.e., the draft head proposes the same token when seeded.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TODO. I'd like to defer this to a future PR because 1) the sampling code in the PR needs some refactoring anyways, and 2) handling RNG in spec decoding is quite tricky, so I need more time to think more about it.

@WoosukKwon
Copy link
Collaborator Author

WoosukKwon commented Mar 31, 2025

@njhill @LiuXiaoxuanPKU @sroy745 Thanks for the reviews.

Because the integration of EAGLE involves a lot of changes, I tried to break it down to smaller steps. This PR is the first step to establish the high-level design, so I intentionally left many TODOs and FIXMEs.

The next steps should be:

  1. Correctly initializing and loading the EAGLE draft model
  2. Consider the lookahead slots in the KV cache manager
  3. Cache draft_probs inside the model runner and correctly feed it to the rejection sampler in the next step
  4. Handle the edge cases like when the draft model generates beyond max_pos_embeddings
  5. Handle the seeds correctly
  6. Do E2E correctness and performance tests
  7. Support prefix caching. Eagle requires special handling because Eagle's i-th KV cache is coupled with the i+1-th token ID.

I don't think I have bandwidth for all of these, so it'd be nice if we can get some helps from the community.

@LiuXiaoxuanPKU
Copy link
Collaborator

Sounds good. I am happy to take 2 since I already start thinking about it. Let me create issues for 1,3,4,5,6 and move some of them to onboarding tasks.

@WoosukKwon
Copy link
Collaborator Author

@LiuXiaoxuanPKU Can you please take 1 as well?

@LiuXiaoxuanPKU
Copy link
Collaborator

@LiuXiaoxuanPKU Can you please take 1 as well?

Sure, will give a try today

Copy link
Collaborator

@sroy745 sroy745 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One small comment.

Copy link
Collaborator

@LiuXiaoxuanPKU LiuXiaoxuanPKU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link

mergify bot commented Mar 31, 2025

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @WoosukKwon.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

# Common case.
next_token_id = token_ids[-1]
else:
# Partial prefill (rare case).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this corresponding to this case when we had to backtrack a bit so that we can have ensure we have num_computed_tokens as a multiple of the block size?

Copy link
Contributor

@ekagra-ranjan ekagra-ranjan Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or this handles chunked context?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is for chunked context, eagle needs the next_token_id as the input. In the decoding phase, next token id is the last generated token id. In the chunked prefill case, it's the next token id of the current chunk.

Signed-off-by: Woosuk Kwon <[email protected]>
@WoosukKwon WoosukKwon changed the title [V1][Spec Decode] Implement Eagle Proposer [V1][Spec Decode] Implement Eagle Proposer [1/N] Apr 1, 2025
Signed-off-by: Woosuk Kwon <[email protected]>
@WoosukKwon WoosukKwon added the ready ONLY add when PR is ready to merge/full CI is needed label Apr 1, 2025
@WoosukKwon WoosukKwon merged commit e75a630 into main Apr 1, 2025
11 of 15 checks passed
@WoosukKwon WoosukKwon deleted the woosuk-eagle branch April 1, 2025 19:33
@v-lmn
Copy link

v-lmn commented Apr 3, 2025

I found a bug when using this code
because self._num_decodes = 0 and decode_metadata is None
image

@WoosukKwon

@ekagra-ranjan
Copy link
Contributor

@v-lmn can you share how you ran this code? My understanding is that this code is not finished and cannot be executed until the futher PRs adding missing functionality in eagle

Alex4210987 pushed a commit to LeiWang1999/vllm-bitblas that referenced this pull request Apr 5, 2025
lulmer pushed a commit to lulmer/vllm that referenced this pull request Apr 7, 2025
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Apr 29, 2025
shreyankg pushed a commit to shreyankg/vllm that referenced this pull request May 3, 2025
RichardoMrMu pushed a commit to RichardoMrMu/vllm that referenced this pull request May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed v1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants