[Bugfix][MM] Fix MiniCPM-V placeholder replacement and image processor loading on Transformers v5 - #48413
Conversation
Signed-off-by: YunzhuLu <lucia.yunzhu@gmail.com>
|
cc @DarkLight1337, thanks for taking a look! |
|
cc @tc-mb |
ok |
|
@YunzhuLu I verified this with MiniCPM-V-4: calling it first with max_slice_nums=1 and then with max_slice_nums=2 returned the same processor, and the second call still had max_slice_nums=1. Since cached_get_image_processor already caches by its normalized arguments, could we remove this additional cache or key it by the normalized kwargs? A regression test covering consecutive calls with different kwargs would also help prevent stale processor configuration. |
Signed-off-by: YunzhuLu <lucia.yunzhu@gmail.com>
|
@tc-mb Thanks for the review. I've updated the cache to be keyed by normalized kwargs from I kept the outer cache (instead of removing it) because dropping it caused MiniCPM-V processing tests to spend much more time repeatedly resolving the dynamic processor class and constructing processors. To avoid repeating Added unit tests |
|
Hi @tc-mb, just a gentle ping. I've addressed all the review comments and updated the PR. Could you please take another look when you have time? Thanks! |
Okay, sorry, I was on WAIC a few days ago and didn't keep up. I'll continue today. |
|
Signed-off-by: YunzhuLu <lucia.yunzhu@gmail.com>
|
@tc-mb , hope WAIC went well! Thanks for the thorough review, below are what changed:
pytest tests/models/multimodal/processing/test_minicpmv.py -v
pytest tests/models/multimodal/processing/test_common.py -k "minicpm and not 2_6" -vBoth pass locally; confirmed test_image_processor_for_dif_model and test_prompt_has_dif_BPE_boundaries_in_context fail on main and pass with this branch. |
|
Quick update on the Transformers issue mentioned above: I've opened huggingface/transformers#47628 to fix the config fallback behavior that drops |
OK, @YunzhuLu thank you for your update, I feel like PR can be merged. |
|
This pull request has merge conflicts that must be resolved before it can be |
Signed-off-by: Yunzhu Lu <lucia.yunzhu@gmail.com>
Head branch was pushed to by a user without write access
|
Hi @DarkLight1337 , the previous CI failures seemed to be caused by a possible architecture-name mismatch between |
|
@tc-mb there seems to be some problems with the remote module: https://buildkite.com/vllm/ci/builds/82629/list?sid=019fd5a9-db3a-46d7-b41b-a497da37000c&tab=output |
|
Could you fix them? |
vllm-project#48413 fixed the vLLM-side `MiniCPMVBatchFeature` incompatibility and dropped the `max_transformers_version` cap on `MiniCPMV` entirely. That also un-gated the tests that build an HF reference model, exposing a separate HF-side break: MiniCPMV's remote code never calls `self.post_init()`, so `all_tied_weights_keys` is never set and Transformers v5 raises in `_move_missing_keys_from_meta_to_device`. Restore the cap with an `hf`-scoped reason so HF-runner comparisons skip while vLLM-only coverage keeps running. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Purpose
This PR fixes two independent but related issues that block MiniCPM-V models (2.5 / 2.6 / 4.0 / 4.5) from working with Transformers v5 in vLLM:
Also removes the max_transformers_version="4.57" cap in tests/models/registry.py so MiniCPM-V processing tests can run under Transformers v5, since #44282 already vendors the MiniCPMV processor and aliases
MiniCPMVBatchFeaturetoBatchFeature.Problem 1: Placeholder mismatch
After upgrading to Transformers v5, starting MiniCPM-V4 with
vllm servefails immediately during initializationvllm serve /root/autodl-tmp/huggingface/hub/MiniCPM-V-4/OpenBMB/MiniCPM-V-4 \ --trust-remote-code \ --served-model-name MiniCPM-V-4 \ --gpu-memory-utilization 0.75 \ --max-model-len 4096 \ --max-num-batched-tokens 4096 \ --limit-mm-per-prompt '{"video": 1, "image": 1}'Root cause
MiniCPM-V placeholders are ordinary text, not tokenizer special tokens. Under BPE, the same string tokenizes differently when encoded standalone vs. in a full prompt context.
Solution
Override
_apply_prompt_updatesinMiniCPMVMultiModalProcessor:Test Plan
function test
Serve MiniCPM-V-4 with Transformers v5 and send a single-image request
server
vllm serve /root/autodl-tmp/huggingface/hub/MiniCPM-V-4/OpenBMB/MiniCPM-V-4 \ --trust-remote-code \ --served-model-name MiniCPM-V-4 \ --gpu-memory-utilization 0.75 \ --max-model-len 4096 \ --max-num-batched-tokens 4096 \ --limit-mm-per-prompt '{"video": 1, "image": 1}'client
Test Result
server
client
Problem 2: Wrong image processor loaded when switching MiniCPM-V models
While validating the placeholder fix, running test_processing_correctness for multiple MiniCPM-V models in the same pytest process exposed a second issue.
Reproduction
Reproduction: Run 2.5 and V-4 serially in one process
However, running each model in isolation passes; the failure only appears when models are loaded serially in the same process.
Root cause
MiniCPM-V repos (openbmb/MiniCPM-Llama3-V-2_5, openbmb/MiniCPM-V-2_6, openbmb/MiniCPM-V-4, openbmb/MiniCPM-V-4_5, etc.) declare the same remote class name in preprocessor_config.json. The class name is identical across repos, but implementations differ. After loading 2.5, a subsequent V-4 load reuse 2.5's dynamically loaded processor instead of loading V-4's own.
Solution
Override MiniCPMVProcessingInfo.get_hf_processor to bypass AutoImageProcessor's shared class resolution:
get_class_from_dynamic_modulecached_get_image_processor(..., processor_cls_overrides=processor_cls)soprocessor_cls.from_pretrainedis called directly on the repo-specific class.Test Plan
MiniCPM-V-2_6 is skipped because it is a gated repo and the test environment does not have access.
pytest tests/models/multimodal/processing/test_common.py -k "minicpm and not 2_6" -vTest Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.