Skip to content

Serve Qwen4-MoE on Qwen4MoePipeline with Python-side image and video preprocessing - #211

Open
SearchSavior wants to merge 1 commit into
claude/openvino-nightly-indexfrom
ccr-45d94ac3-pussz7
Open

SearchSavior wants to merge 1 commit into
claude/openvino-nightly-indexfrom
ccr-45d94ac3-pussz7

Conversation

@SearchSavior

@SearchSavior SearchSavior commented Dec 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

Serves Qwen4-MoE (model_type: qwen4_moe) through OpenArc's existing VLM path on the new openvino_genai.Qwen4MoePipeline (SearchSavior/openvino.genai#7). Images and videos are decoded and preprocessed in Python with the model's own Hugging Face processors. The C++ pipeline gets pixel_values and does the rest.

This is an alternative to #208 that does not depend on it. #208 runs Qwen4 on the stock VLMPipeline and adds the qwen35 tool-parser wiring. This PR stacks on #209 (the nightly OpenVINO index), as #208 does. The two touch one shared line in resolve_vlm_type.py, the Qwen4MoeForConditionalGeneration vision token.

How it plugs in

  • create_model_instance sends ovgenai/vlm loads whose config.json says qwen4_moe to OVGenAI_Qwen4MoeVLM, a subclass of OVGenAI_VLM. Nothing changes for other models. It falls back to VLMPipeline when the installed openvino-genai has no Qwen4MoePipeline, or when OPENARC_QWEN4_MOE_PIPELINE=0.
  • Everything else is the existing VLM engine, so the language model is built exactly as VLMPipeline builds it:
    • load config: scheduler config, MTP draft_model_path, CACHE_DIR, runtime_config
    • streamers, tool parsers and the gemma4/museglimmer paths
    • create_generation_config
    • metrics
    • worker queueing and cancellation
  • OVGenAI_VLM gets two small hooks, _create_pipeline and _vision_kwargs. It also now resolves inputs with asyncio.to_thread, so image and video decoding doesn't block the event loop.
  • New content items next to text and image_url. All media must be base64 data URLs:
    • {"type": "video_url", "video_url": {"url": "data:video/mp4;base64,...", "fps": 30}}: decoded with PyAV, or OpenCV as a fallback. The container fps is used when no fps is given.
    • {"type": "video", "video": ["data:image/...", ...], "fps": 2}: frames that are already decoded.
  • VisionInputError(ValueError): an image or video that cannot be decoded or preprocessed fails that request with HTTP 400 and keeps the model loaded, like AudioDecodeError. Without it, the worker would unload the model on any inference exception.
  • A docs section in docs/api_usage.md.

Testing

  • Unit tests: tests/unit/test_ov_genai_qwen4_moe_vlm_unit.py (22 tests) and the VLM rejection tests in test_worker_registry_unit.py. The full tests/unit suite gives 364 passed, 7 failed. The 7 failures are the kokoro tests, which fail identically on the base branch here because kokoro can't be installed on this machine's Python 3.13.
  • End to end through the real HTTP server, using a tiny random qwen4_moe exported from the real Qwen4-35B-A3B configs and a locally built openvino.genai#7, on CPU:
    • /openarc/load works, and /v1/chat/completions works with:
      • an image
      • a video as frames
      • an mp4 video_url
      • image+video
      • text only
    • Streaming output equals non-streaming output.
    • The server's text is identical to Qwen4MoePipeline called directly with the same templated prompt. It is also identical to VLMPipeline (VISION_PREPROCESS=CPP) for every case.
    • Loading with draft_model_path (MTP) works.
    • An https:// image URL returns 400, and the model still answers the next request.
  • Not tested: GPU (none available here) and a real Qwen4-35B-A3B checkpoint.

Notes

https://claude.ai/code/session_011SRNH98gDNX6mWPMJoe2DD


Generated by Claude Code

…preprocessing

qwen4_moe VLMs (config.json model_type) now load as OVGenAI_Qwen4MoeVLM, a
subclass of OVGenAI_VLM that runs openvino_genai.Qwen4MoePipeline. Every
image and video is decoded and preprocessed in Python with the model's own
Hugging Face processors (openvino_genai.qwen4_moe.Qwen4MoeProcessor); the
pipeline gets pixel_values and does the rest in C++. Scheduler config, MTP
draft model, CACHE_DIR, runtime_config, streamers, tool parsers and metrics
are the existing VLM engine's, so the language model is built exactly as
VLMPipeline builds it.

- Video input: OpenAI-style video_url (base64 data URL, decoded with PyAV
  or OpenCV, container fps) and video (list of frame data URLs + fps).
- Dispatch in create_model_instance; falls back to VLMPipeline when
  openvino-genai has no Qwen4MoePipeline or OPENARC_QWEN4_MOE_PIPELINE=0.
- OVGenAI_VLM gets two small hooks (_create_pipeline, _vision_kwargs) and
  resolves inputs off the event loop.
- VisionInputError: an image or video that cannot be decoded or
  preprocessed fails that request with 400 and keeps the model loaded,
  like AudioDecodeError.
- Qwen4MoeForConditionalGeneration vision token for the VLMPipeline path.
- Unit tests and docs/api_usage.md section.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011SRNH98gDNX6mWPMJoe2DD

This branch has not been deployed

No deployments
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.

2 participants