Skip to content
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

Align vLLM's beam search implementation with HF generate #857

Merged
merged 25 commits into from
Sep 5, 2023

Conversation

zhuohan123
Copy link
Member

@zhuohan123 zhuohan123 commented Aug 24, 2023

This PR refactors the changes in #646.

The goal of this PR is to align the beam search with hf_model.generate(), which is also aligned with many other older frameworks, including tensor2tensor and fairseq. When meeting a finished beam candidate, our old beam search algorithm will always keep this finished beam and reduce the beam width of the remaining beam search by 1. However, for HF, the beam width will always be a fixed number, and we will select the top-"beam width" running requests for the next iteration.

This change breaks the assumption that every sequence group in vLLM will always have a fixed number (which actually always equals to best_of) of requests. Therefore, we need to dynamically grow the number of sequences in a sequence group. After this PR, every request will start with only one sequence (for prompt computation). Later, each request will grow into multiple other sequences during the decoding process based on their sampling algorithms.

Should be merged after #867

TODOs:

  • Document the exact changes in PR's description.
  • Add more comments to the code about the change.
  • Conduct a more thorough test with more input examples (maybe read from a dataset) and mixed sampling methods.
  • Maybe in a separate PR, add a test with multiple processes querying the API to test for race conditions.

cc @hsm1997

@zhuohan123 zhuohan123 changed the title Align vLLM's beam search implementation with HF generate [WIP] Align vLLM's beam search implementation with HF generate Aug 25, 2023
@zhuohan123 zhuohan123 changed the title [WIP] Align vLLM's beam search implementation with HF generate Align vLLM's beam search implementation with HF generate Aug 25, 2023
examples/test_sampling.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

@zhuohan123 Awesome! Thanks for the amazing work! 🚀

As we discussed offline, I think the PR only needs small fixes for further clarification. I like the changes in the system design. Thanks again for the hard work.

vllm/model_executor/models/mpt.py Outdated Show resolved Hide resolved
vllm/model_executor/models/qwen.py Outdated Show resolved Hide resolved
vllm/sampling_params.py Show resolved Hide resolved
examples/test_sampling.py Outdated Show resolved Hide resolved
vllm/model_executor/layers/sampler.py Show resolved Hide resolved
vllm/sequence.py Outdated Show resolved Hide resolved
vllm/sequence.py Outdated Show resolved Hide resolved
vllm/sequence.py Outdated Show resolved Hide resolved
vllm/engine/llm_engine.py Outdated Show resolved Hide resolved
vllm/engine/llm_engine.py Show resolved Hide resolved
@WoosukKwon WoosukKwon mentioned this pull request Aug 31, 2023
3 tasks
Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

Looks very good to me! Many thanks for the hard work. I believe this will make vLLM a unique inference engine that effectively supports beam search. Nice work!

@WoosukKwon
Copy link
Collaborator

@zhuohan123 BTW, please close some issues fixed by this PR.

@WoosukKwon WoosukKwon mentioned this pull request Sep 4, 2023
4 tasks
@zhuohan123 zhuohan123 merged commit 002800f into main Sep 5, 2023
2 checks passed
@zhuohan123 zhuohan123 deleted the correct-beam-search branch September 7, 2023 21:02
liuyanyi pushed a commit to liuyanyi/vllm that referenced this pull request Sep 12, 2023
hongxiayang pushed a commit to hongxiayang/vllm that referenced this pull request Feb 13, 2024
sjchoi1 pushed a commit to casys-kaist-internal/vllm that referenced this pull request May 7, 2024
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.

2 participants