Support GPU tensors in tensor_data() to enable GPU-accelerated multimodal preprocessing #30667
+8
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Add support for GPU tensors in the
tensor_datafunction, enabling proper functionality of GPU-accelerated multimodal preprocessing.Background
In our practical deployment, we enabled GPU-accelerated multimodal preprocessing by utilizing the following configurations, thereby moving tasks such as image and video preprocessing to the GPU. This significantly reduces CPU overhead in high-concurrency scenarios:
--mm-processor-kwargs '{"device": "cuda"}'"device": "cuda"inpreprocessor_config.jsonHowever, the current implementation of the
tensor_data()function invllm/v1/utils.pyfails to handle tensors residing on the GPU, causing errors when GPU preprocessing is enabled.Problem
The
tensor_data()function is used for tensor serialization and hashing, particularly in multimodal input processing. The current implementation directly calls.numpy()on tensors:This fails for GPU tensors because PyTorch's
.numpy()method only supports CPU tensors, raising:Solution
Add
.cpu()call before.numpy()to handle both CPU and GPU tensors:Performance Impact:
.cpu()is a no-op, no performance impactThis change is critical for multimodal models when GPU preprocessing is enabled, as tensors may reside on GPU devices.
Test Plan
Unit Tests
Integration Test
Test with actual multimodal preprocessing using GPU device:
Test Result
Before Fix
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.After Fix
Test Output:
Affected Code Paths
The
tensor_data()function is called in:vllm/v1/serial_utils.py- Tensor encoding for serializationvllm/v1/core/kv_cache_utils.py- Block prompt embeddings hashingAll these code paths now work correctly with GPU tensors when GPU preprocessing is enabled.
Documentation Updates
Updated docstring in
vllm/v1/utils.py:tensor_data()to clarify:Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.