Skip to content

vllm: add MiniCPM-V 4.6 support (MiniCPMV4_6ForConditionalGeneration)#472

Open
Zjq9409 wants to merge 2 commits into
intel:mainfrom
Zjq9409:feat/minicpmv4_6-support
Open

vllm: add MiniCPM-V 4.6 support (MiniCPMV4_6ForConditionalGeneration)#472
Zjq9409 wants to merge 2 commits into
intel:mainfrom
Zjq9409:feat/minicpmv4_6-support

Conversation

@Zjq9409

@Zjq9409 Zjq9409 commented Jun 12, 2026

Copy link
Copy Markdown
  • 新增 MiniCPMV4_6ForConditionalGeneration(Qwen3.5 backbone + Idefics2 vision tower + hybrid mamba)。
  • 依赖 transformers==5.8.0(仓库已 pin,无需改)。
  • 6处针对 b8.3.1 基线的适配(mamba dtype 2 参、_get_data_parser().parse_mm_data、vit_merger qkv 权重名、handle_oov_mm_token、idefics2 attention_mask、im_id token 走 tokenizer)。
  • 验证:Arc Pro B60 / intel/llm-scaler-vllm:0.14.0-b8.3.1,文本 + 图片(OpenAI API)推理均通过,fp8 量化在线服务正常。

Zjq9409 added 2 commits June 12, 2026 10:02
Signed-off-by: Zhoujianqian <15205085056@163.com>
…kens

The XPU MiniCPM-V-4.6 support passed vLLM ImageSize (width, height)
directly to transformers image_processor.get_sliced_grid /
find_best_resize / get_refine_size, which expect (height, width).
For non-square images whose slice grid is asymmetric (e.g. 1084x820)
this produced a transposed grid, so the number of image placeholder
tokens (495) did not match the vision encoder output (441). The
mismatched masked_scatter_ then tripped the XPU indexing assert
'totalElements <= srcSize' (torch-xpu-ops Indexing.cpp), killing
EngineCore (EngineDeadError -> HTTP 500).

Convert ImageSize to (height, width) before calling the processor,
matching upstream vLLM releases/v0.24.0. Verified across 12 image
sizes that placeholder count now equals encoder token count, and the
original crashing request now succeeds.
@Zjq9409

Zjq9409 commented Jul 13, 2026

Copy link
Copy Markdown
Author

追加修复:MiniCPM-V-4.6 图像 (W,H)/(H,W) 顺序导致 XPU 崩溃 (commit e71854d)

现象:非正方形、且切片网格非对称的图(如 1084×820)发到 XPU 服务时返回 500,server 端报:

/pytorch/third_party/torch-xpu-ops/src/ATen/native/xpu/sycl/Indexing.cpp:786: operator():
Assertion `totalElements <= srcSize_` failed.
→ EngineCore died → vllm.v1.engine.exceptions.EngineDeadError → HTTP 500

根因:minicpmv4_6.py_compute_visual_tokens 把 vLLM 的 ImageSize(width, height) 直接传给了 transformers 的 get_sliced_grid / find_best_resize / get_refine_size,而这些接口期望 (height, width)。对非对称切片图,grid 被转置([2,3][3,2]),导致:

  • 占位符 token 数 = 495
  • 视觉编码器实际输出 token 数 = 441

两者不一致 → _merge_multimodal_embeddingsmasked_scatter_ 越界 → 触发 XPU MaskedScatterSizeCheckFunctor 的设备端断言。该断言是异步 device assert,无法被 Python try/except 捕获,所以 XPU 上直接崩引擎(NVIDIA 上通常只是可捕获的 RuntimeError/单请求失败)。

修复:在调用 processor 前显式转成 (height, width),与上游 vLLM releases/v0.24.0 的做法一致:

# vLLM ImageSize is (width, height); transformers get_sliced_grid/
# find_best_resize/get_refine_size expect (height, width).
if hasattr(image_size, "height"):
    hf_image_size = (image_size.height, image_size.width)
else:
    hf_image_size = (image_size[1], image_size[0])

(改动落在 vllm/patches/vllm_for_multi_arc.patchminicpmv4_6.py 新增文件的 _compute_visual_tokens,并同步更新了该 hunk 的行数计数 1351→1358。)

验证:

  • 12 种尺寸(含 1084×820、820×1084、2275×1279 等)下,占位符 token 数与编码器实际输出 token 数全部一致
  • 原始崩溃请求 run_vllm_images.py 重跑成功返回,结果文件无任何 500/error。
  • 补丁内容 py_compile 通过,hunk 行数校验通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant