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] VLM preprocessor hashing #11020

Merged
merged 2 commits into from
Dec 12, 2024
Merged

[V1] VLM preprocessor hashing #11020

merged 2 commits into from
Dec 12, 2024

Conversation

alexm-neuralmagic
Copy link
Collaborator

@alexm-neuralmagic alexm-neuralmagic commented Dec 9, 2024

This PR adds:

  1. Hashing functionality for images
  2. Caching of the multi-modal (MM) preprocessor/mapper

The idea of MM preprocessor caching is based on having a client and a server, where the client executes in the frontend process (=P0) and the server in the core process (=P1).

  • Client: Executes the MM mapper and performs caching of the results.
  • Server: Performs caching of the results

The caching for both client and server is mirrored/similar, and this allows us to avoid the serialization of "mm_inputs" (like pixel values) between client (=P0) and server (=P1) processes.

Currently, the MM preprocessor caching is disabled by default, since we did not finish the performance analysis yet. We still need to enable encoder caching and prefix caching end-to-end.

Follow up PRs:

  1. Benchmark script for TTFT and TPOT and more deeper analysis of performance.
  2. Encoder caching
  3. Prefix caching end-to-end with skipping of all MM pipeline steps (if hashed)

Copy link

github-actions bot commented Dec 9, 2024

👋 Hi! Thank you for contributing to the vLLM project.
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 do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Copy link

mergify bot commented Dec 9, 2024

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

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 Dec 9, 2024
@alexm-neuralmagic alexm-neuralmagic marked this pull request as draft December 9, 2024 13:58
@alexm-neuralmagic alexm-neuralmagic changed the title [WIP] [V1] VLM preprocessor hashing [V1] VLM preprocessor hashing Dec 9, 2024
@mergify mergify bot removed the needs-rebase label Dec 9, 2024
@alexm-neuralmagic
Copy link
Collaborator Author

/ready

@alexm-neuralmagic alexm-neuralmagic marked this pull request as ready for review December 9, 2024 14:33
Copy link
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Overall LGTM. Just some comments for style. Also please

  1. Revert unnecessary changes in the example code.
  2. Add some unit tests.

vllm/config.py Outdated Show resolved Hide resolved
vllm/engine/arg_utils.py Outdated Show resolved Hide resolved
vllm/v1/engine/__init__.py Show resolved Hide resolved
vllm/v1/engine/mm_input_mapper.py Outdated Show resolved Hide resolved
Comment on lines 117 to 122
mm_hashes = self.mm_hasher.hash(decoder_inputs.multi_modal_data) \
if self.mm_hasher is not None else None

mm_inputs, mm_hashes = self.mm_input_mapper_client.process_inputs(
decoder_inputs.multi_modal_data, mm_hashes,
decoder_inputs.mm_processor_kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably need some assertions to make sure mm_hasher and mm_input_mapper_client are not None.

vllm/v1/utils.py Show resolved Hide resolved
vllm/v1/utils.py Outdated Show resolved Hide resolved
vllm/v1/utils.py Show resolved Hide resolved
@comaniac comaniac added the ready ONLY add when PR is ready to merge/full CI is needed label Dec 9, 2024
@alexm-neuralmagic
Copy link
Collaborator Author

@comaniac thanks for the quick review! I actually realized that I need to push the hash and the cache into the _process_multimodal(..) due to recent merging of preprocessor for llava. Also it caches the first preprocessor too. Will send changes tomorrow.

Copy link

mergify bot commented Dec 10, 2024

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

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 Dec 10, 2024
@alexm-neuralmagic alexm-neuralmagic force-pushed the v1_vlm_hash_mapper branch 2 times, most recently from 0e26569 to f4466ba Compare December 10, 2024 15:16
@mergify mergify bot removed the needs-rebase label Dec 10, 2024
@alexm-neuralmagic
Copy link
Collaborator Author

@comaniac code is ready for re-review. Eventually, I did not push the hasher/cacher into the _process_multimodal(..) since it is also used to compute the MM placeholders, and there is no simple way to skip it due to hash HIT. We can look into this as a follow up.

Copy link
Collaborator

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

LGTM. Just some nits

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does these changes compatible with v0? If not then we should differentiate them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah it should not matter if it is v0 or v1, since it simply controls the images used.

vllm/v1/engine/__init__.py Show resolved Hide resolved
vllm/v1/engine/core.py Outdated Show resolved Hide resolved
vllm/v1/engine/mm_input_mapper.py Outdated Show resolved Hide resolved
vllm/v1/engine/mm_input_mapper.py Outdated Show resolved Hide resolved
Signed-off-by: Roger Wang <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: Roger Wang <[email protected]>
Signed-off-by: Alexander Matveev <[email protected]>
@comaniac comaniac enabled auto-merge (squash) December 11, 2024 17:28
Signed-off-by: Alexander Matveev <[email protected]>
@comaniac comaniac merged commit 4e11683 into main Dec 12, 2024
76 checks passed
@comaniac comaniac deleted the v1_vlm_hash_mapper branch December 12, 2024 00:55
Akshat-Tripathi pushed a commit to krai/vllm that referenced this pull request Dec 12, 2024
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Alexander Matveev <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: Roger Wang <[email protected]>
Signed-off-by: Akshat Tripathi <[email protected]>
sleepwalker2017 pushed a commit to sleepwalker2017/vllm that referenced this pull request Dec 13, 2024
Signed-off-by: Roger Wang <[email protected]>
Signed-off-by: Alexander Matveev <[email protected]>
Co-authored-by: Michael Goin <[email protected]>
Co-authored-by: Roger Wang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/build ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants