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

[v1] Support allowed_token_ids in v1 Sampler #13210

Merged
merged 4 commits into from
Feb 22, 2025

Conversation

houseroad
Copy link
Contributor

@houseroad houseroad commented Feb 13, 2025

Follow the implementation in vllm/entrypoints/openai/logits_processors.py.

The idea is straightforward, adding a [batch_size x vocab_size] mask tensor, and leverage a list of bools to determine whether to do the inplace masked fill.

  • add test
  • move some verification in _get_allowed_token_ids_logits_processor to SamplingParam.

Test with

  • pytest tests/v1/sample/test_sampler.py
  • pytest tests/v1/worker/test_gpu_input_batch.py

Sorry, something went wrong.

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 Feb 13, 2025
@houseroad houseroad force-pushed the v1_allowed_token_ids branch from 9b044a4 to ee1d1a0 Compare February 14, 2025 22:16
@houseroad houseroad changed the title Support allowed_token_ids in v1 Sampler [v1] Support allowed_token_ids in v1 Sampler Feb 14, 2025
Copy link

mergify bot commented Feb 16, 2025

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

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

@WoosukKwon
Copy link
Collaborator

cc @njhill Could you please take a look?

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @houseroad!

I have a few comments, mainly to keep the tensor manipulation on cpu and apply mask to the batch rather than individual rows.

Also you might want to take a look at #13360, I'm hoping to get that into shape soon and have all the sampling params like this encapsulated as vectorized logits processors.

@pytest.mark.parametrize("device", CUDA_DEVICES)
@pytest.mark.parametrize("batch_size", [1, 2, 32])
@pytest.mark.parametrize("num_allowed_token_ids", [0, 1, 2])
def test_sampler_allowed_token_ids(device: str, batch_size: int,
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for adding this test!!

Copy link

mergify bot commented Feb 19, 2025

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

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

@mergify mergify bot added the needs-rebase label Feb 19, 2025
@houseroad houseroad force-pushed the v1_allowed_token_ids branch from 1793e7a to 77c8db6 Compare February 19, 2025 05:39
@mergify mergify bot removed the needs-rebase label Feb 19, 2025
@houseroad houseroad force-pushed the v1_allowed_token_ids branch 3 times, most recently from 9c0d832 to 2bdd559 Compare February 19, 2025 06:56
Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @lu-wang-dl for the updates, I think it's close, just a few more things.

sampling_metadata.presence_penalties,
sampling_metadata.frequency_penalties,
sampling_metadata.repetition_penalties,
sampling_metadata.output_token_ids)
sampling_metadata.output_token_ids,
)
Copy link
Member

Choose a reason for hiding this comment

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

Same general comment, it's best not to include unrelated formatting changes, looks like there are a couple above and some in the other file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's done by my VSCode, sorry.

I will be more cautious next time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, confirmed, actually it's done by the yapf in the pre-commit hooks. It forced me to do such change...

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks @houseroad looks great now, just one remaining thing.

Copy link
Member

@njhill njhill left a comment

Choose a reason for hiding this comment

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

Thanks again @houseroad!

@houseroad houseroad closed this Feb 21, 2025
@houseroad houseroad reopened this Feb 21, 2025
@ywang96 ywang96 added the ready ONLY add when PR is ready to merge/full CI is needed label Feb 21, 2025
@houseroad houseroad force-pushed the v1_allowed_token_ids branch from 444d719 to 7c63284 Compare February 21, 2025 05:54
Signed-off-by: Lu Fang <lufang@fb.com>

Complete the main logic for allowed_token_ids in v1 sampler

Signed-off-by: Lu Fang <lufang@fb.com>

lint the code

Signed-off-by: Lu Fang <lufang@fb.com>

Add boundary checks for allowed_token_ids

Signed-off-by: Lu Fang <lufang@fb.com>

address the comments

Signed-off-by: Lu Fang <lufang@fb.com>
Signed-off-by: Lu Fang <lufang@fb.com>

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
Signed-off-by: Lu Fang <lufang@fb.com>
@houseroad houseroad force-pushed the v1_allowed_token_ids branch from 7c63284 to 60b4393 Compare February 21, 2025 20:04
Signed-off-by: Lu Fang <lufang@fb.com>
@DarkLight1337 DarkLight1337 merged commit bb78fb3 into vllm-project:main Feb 22, 2025
42 checks passed
Akshat-Tripathi pushed a commit to krai/vllm that referenced this pull request Mar 3, 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.

None yet

5 participants