-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[Misc] Add tensor schema test coverage for multimodal models #21754
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
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
aea2a9a
init tensor schema test
Isotr0py da47b08
extend tests
Isotr0py bceed0a
update
Isotr0py 16b4695
deal with batching
Isotr0py 7567b03
fix hf overrides
Isotr0py 4887d9e
fix batching
Isotr0py a92da96
remove transformers version check and make mypy happy
Isotr0py ab3692a
gemini suggestion
Isotr0py 42b5fc9
Merge branch 'vllm-project:main' into tensor-scheme-test
Isotr0py 0af4eb9
skip molmo
Isotr0py a0e5732
use v1 for test
Isotr0py fa7981f
oops
Isotr0py 2ba463f
solve deadlock
Isotr0py 765758b
fix h2ovl
Isotr0py 1f3b612
fix deepseek-vl2
Isotr0py 25a17a9
Merge branch 'vllm-project:main' into tensor-scheme-test
Isotr0py fcbd9ff
fix deepseek-vl2
Isotr0py 502678f
fix keye
Isotr0py 7c43262
skip minimax-vl now
Isotr0py 4ae019a
code format
Isotr0py c5e8055
deadlock?
Isotr0py bb3cc19
separate test process
Isotr0py cadb1ad
solve hf overrides process
Isotr0py File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from transformers import PretrainedConfig | ||
|
|
||
| from vllm.config import ModelConfig | ||
| from vllm.engine.llm_engine import LLMEngine as V0LLMEngine | ||
| from vllm.inputs import InputProcessingContext | ||
| from vllm.multimodal import MULTIMODAL_REGISTRY, MultiModalKwargs | ||
| from vllm.multimodal.processing import BaseMultiModalProcessor | ||
| from vllm.transformers_utils.tokenizer import cached_tokenizer_from_config | ||
| from vllm.utils import GiB_bytes, set_default_torch_num_threads | ||
| from vllm.v1.core.kv_cache_utils import get_kv_cache_config | ||
| from vllm.v1.engine.core import EngineCore as V1EngineCore | ||
|
|
||
| from ...conftest import VllmRunner | ||
| from ...utils import fork_new_process_for_each_test | ||
| from ..registry import _MULTIMODAL_EXAMPLE_MODELS, HF_EXAMPLE_MODELS | ||
|
|
||
| ARCH_TO_SKIP = { | ||
| "MolmoForCausalLM": "incompatible requirements", | ||
| "MiniMaxVL01ForConditionalGeneration": "broken model", | ||
| } | ||
|
|
||
|
|
||
| def create_batched_mm_kwargs( | ||
| model_config: ModelConfig, | ||
| processor: BaseMultiModalProcessor, | ||
| ) -> MultiModalKwargs: | ||
| processing_info = processor.info | ||
| dummy_inputs = processor.dummy_inputs | ||
| supported_mm_limits = processing_info.get_supported_mm_limits() | ||
| mm_counts = { | ||
| modality: 3 if limit is None else limit | ||
| for modality, limit in supported_mm_limits.items() | ||
| } | ||
| processor_inputs = dummy_inputs.get_dummy_processor_inputs( | ||
| seq_len=model_config.max_model_len, | ||
| mm_counts=mm_counts, | ||
| ) | ||
| mm_kwargs = processor.apply( | ||
| prompt=processor_inputs.prompt, | ||
| mm_data=processor_inputs.mm_data, | ||
| hf_processor_mm_kwargs=processor_inputs.hf_processor_mm_kwargs, | ||
| tokenization_kwargs=processor_inputs.tokenization_kwargs, | ||
| )["mm_kwargs"] | ||
| mm_kwargs = MultiModalKwargs.batch([mm_kwargs]) | ||
| return mm_kwargs | ||
|
|
||
|
|
||
| @pytest.mark.core_model | ||
| @pytest.mark.parametrize("model_arch", list(_MULTIMODAL_EXAMPLE_MODELS.keys())) | ||
| @fork_new_process_for_each_test | ||
| def test_model_tensor_schema(model_arch: str, vllm_runner: type[VllmRunner], | ||
| monkeypatch): | ||
| if model_arch in ARCH_TO_SKIP: | ||
| pytest.skip(f"Skipping {model_arch} due to {ARCH_TO_SKIP[model_arch]}") | ||
|
|
||
| model_info = HF_EXAMPLE_MODELS.get_hf_info(model_arch) | ||
| model_info.check_available_online(on_fail="skip") | ||
|
|
||
| model_id = model_info.default | ||
|
|
||
| # Avoid OOM and reduce initialization time by only using 1 layer | ||
| def hf_overrides(hf_config: PretrainedConfig) -> PretrainedConfig: | ||
| hf_config.update(model_info.hf_overrides) | ||
| text_config = hf_config.get_text_config() | ||
| # Ensure at least 2 expert per group | ||
| # Since `grouped_topk` assumes top-2 | ||
| n_group = getattr(text_config, 'n_group', None) | ||
| num_experts = n_group * 2 if n_group is not None else 2 | ||
| # we use three layers for Gemma-3n to check | ||
| # both normal layer and kv_shared_layer | ||
| text_config.update({ | ||
| "num_layers": 1, | ||
| "num_hidden_layers": 1, | ||
| "num_experts": num_experts, | ||
| "num_experts_per_tok": 2, | ||
| "num_local_experts": num_experts, | ||
| # Otherwise there will not be any expert layers | ||
| "first_k_dense_replace": 0, | ||
| # To avoid OOM on DeepSeek-V3 | ||
| "n_routed_experts": num_experts, | ||
| # For Gemma-3n | ||
| "num_kv_shared_layers": 1, | ||
| }) | ||
| if hasattr(hf_config, "vision_config"): | ||
| hf_config.vision_config.update({ | ||
| "num_layers": 1, | ||
| "num_hidden_layers": 1, | ||
| }) | ||
| # e.g.: ibm-granite/granite-speech-3.3-2b | ||
| if hasattr(hf_config, "encoder_config"): | ||
| hf_config.encoder_config.update({ | ||
| "num_layers": 1, | ||
| "num_hidden_layers": 1, | ||
| }) | ||
|
|
||
| # e.g.: Qwen/Qwen2-Audio-7B-Instruct | ||
| if hasattr(hf_config, "audio_config"): | ||
| hf_config.audio_config.update({ | ||
| "num_layers": 1, | ||
| "num_hidden_layers": 1, | ||
| "encoder_layers": 1, | ||
| }) | ||
|
|
||
| return hf_config | ||
|
|
||
| model_config = ModelConfig( | ||
| model_id, | ||
| tokenizer=model_info.tokenizer or model_id, | ||
| tokenizer_mode=model_info.tokenizer_mode, | ||
| revision=model_info.revision, | ||
| trust_remote_code=model_info.trust_remote_code, | ||
| hf_overrides=model_info.hf_overrides, | ||
| ) | ||
| model_cls = MULTIMODAL_REGISTRY._get_model_cls(model_config) | ||
| factories = MULTIMODAL_REGISTRY._processor_factories[model_cls] | ||
|
|
||
| if not any( | ||
| hasattr(model_cls, f"_parse_and_validate_{m}_input") | ||
| for m in ["image", "video", "audio"]): | ||
| pytest.skip(f"{model_arch} does not support tensor schema validation.") | ||
|
|
||
| ctx = InputProcessingContext( | ||
| model_config, | ||
| tokenizer=cached_tokenizer_from_config(model_config), | ||
| ) | ||
| processing_info = factories.info(ctx) | ||
| supported_mm_limits = processing_info.get_supported_mm_limits() | ||
| limit_mm_per_prompt = { | ||
| modality: 3 if limit is None else limit | ||
| for modality, limit in supported_mm_limits.items() | ||
| } | ||
|
|
||
| # Avoid calling model.forward() | ||
| def _initialize_kv_caches_v0(self) -> None: | ||
| self.cache_config.num_gpu_blocks = 0 | ||
| self.cache_config.num_cpu_blocks = 0 | ||
|
|
||
| def _initialize_kv_caches_v1(self, vllm_config): | ||
| kv_cache_specs = self.model_executor.get_kv_cache_specs() | ||
| scheduler_kv_cache_config = get_kv_cache_config( | ||
| vllm_config, | ||
| kv_cache_specs[0], | ||
| 10 * GiB_bytes, | ||
| ) | ||
|
|
||
| # gpu_blocks (> 0), cpu_blocks, scheduler_kv_cache_config | ||
| return 1, 0, scheduler_kv_cache_config | ||
|
|
||
| with (patch.object(V0LLMEngine, "_initialize_kv_caches", | ||
| _initialize_kv_caches_v0), | ||
| patch.object(V1EngineCore, "_initialize_kv_caches", | ||
| _initialize_kv_caches_v1), monkeypatch.context() as m): | ||
| m.setenv("VLLM_ALLOW_INSECURE_SERIALIZATION", "1") | ||
| if model_info.v0_only: | ||
| m.setenv("VLLM_USE_V1", "0") | ||
|
|
||
| with ( | ||
| set_default_torch_num_threads(1), | ||
| vllm_runner( | ||
| model_id, | ||
| tokenizer_name=model_info.tokenizer, | ||
| tokenizer_mode=model_info.tokenizer_mode, | ||
| revision=model_info.revision, | ||
| trust_remote_code=model_info.trust_remote_code, | ||
| max_model_len=model_info.max_model_len, | ||
| load_format="dummy", | ||
| hf_overrides=hf_overrides, | ||
| limit_mm_per_prompt=limit_mm_per_prompt, | ||
| ) as vllm_model, | ||
| ): | ||
| model_config = vllm_model.llm.llm_engine.model_config | ||
| llm_engine = vllm_model.llm.llm_engine | ||
|
|
||
| if hasattr(llm_engine, "processor"): | ||
| # v1 processor | ||
| mm_registry = llm_engine.processor.mm_registry | ||
| else: | ||
| # v0 input_preprocessor | ||
| mm_registry = llm_engine.input_preprocessor.mm_registry | ||
|
|
||
| processor = mm_registry.create_processor(model_config) | ||
| mm_kwargs = create_batched_mm_kwargs(model_config, processor) | ||
|
|
||
| def validate_model_input(model): | ||
| for modality in ("audio", "image", "video"): | ||
| method_name = f"_parse_and_validate_{modality}_input" | ||
| if hasattr(model, method_name): | ||
| getattr(model, method_name)(**mm_kwargs) | ||
|
|
||
| vllm_model.apply_model(validate_model_input) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @Isotr0py for improving model coverage and fixes! Please feel free to share any feedback to help make these changes safer in the future. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even after fixing the shape check for MiniMax, this model can't still work due to mismatch mm tokens and placeholders:
To avoid bloking other migration PRs, I will fix this model in a separate PR.