Skip to content

ggml-openvino: enable Qwen3.5/Gemma4 vision and preserve F32 MatMul precision - #461

Draft
wine99 wants to merge 6 commits into
dev_backend_openvinofrom
feat/openvino-multimodal
Draft

wine99 wants to merge 6 commits into
dev_backend_openvinofrom
feat/openvino-multimodal

Conversation

@wine99

@wine99 wine99 commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Enable Qwen3.5 and Gemma4 E2B image inputs on OpenVINO CPU/GPU, including four-slot serving with unified and split KV. Qwen3.5 reuses the vision graph across image resolutions; Gemma4 keeps resolution-specific encoder graphs. Fix independent spatial RoPE inputs, attention scaling, embedding-input shapes, and recurrent-state handling needed by these paths.

Keep process-local weight allocation IDs out of persistent cache fingerprints. Honor explicit F32 MatMul input precision with node-level guards, preserving the configured precision of other branches. The required helper was verified in the official OpenVINO 2026.4.1 Runtime SDK.

Additional information

Pre-rebase validation

  • 144 image/follow-up checks passed across Qwen3.5 and Gemma4 on CPU/GPU, including four concurrent slots and both KV layouts; focused backend suites passed 21/21 on each device.
  • F32 MatMul suites passed 12/12 on local OV CPU/GPU and official 2026.4.1 default CPU/FP16-hint GPU. Mixed graphs retain F32 for sensitive MatMul and FP16 for ordinary GPU branches; cached F32/default/F32 transitions passed.
  • Known limitation: official 2026.4.1 with an explicit CPU BF16 hint passes only 5/12 F32 precision cases. The local 2026.5.1 build passes this configuration.

Gemma4 audio remains disabled. Follow-up work is dynamic sample/frame and Conformer block sizes, runtime padding and view/state offsets, and compiled-model reuse for the small weightless preprocessing graph, which currently takes the uncached naive path based on node count. Static/NPU multimodal execution is untested.

Validation after rebase

Rebased onto dev_backend_openvino at a11efd3e1 and kept the base branch's recurrent replay implementation. On the rebased head 304c8a750, all 80 streaming image requests completed across OpenVINO and Vulkan. Qwen passed 16/16 four-slot image and follow-up checks across split and unified KV. The focused F32 MatMul tests passed 12/12 on default OpenVINO CPU and 12/12 on OpenVINO GPU with the FP16 inference hint.

Large-image GPU benchmark

Intel Arc B390, local OpenVINO 2026.5.1 and Mesa Vulkan, Q4_0 language models, and F16 vision projectors. Each measurement column gives OpenVINO / Vulkan. The table reports medians of four warm repeats per size with one server slot and prompt caching disabled. Decoder throughput measures generation after prefill. Full response time covers the streaming request from submission through all 32 generated tokens.

Model Source image Image tokens Encoder (ms) Time to first token (ms) Full response (ms) Decoder (tokens/s)
Qwen3.5-2B 512x512 256 65 / 219 250 / 356 977 / 790 42.6 / 71.6
Qwen3.5-2B 1024x1024 1024 656 / 2363 983 / 2735 1716 / 3169 42.2 / 71.5
Qwen3.5-2B 1536x1024 1536 1199 / 5014 1631 / 5518 2373 / 5956 41.7 / 70.8
Qwen3.5-2B 2048x2048 2025 2331 / 8804 2886 / 9462 3635 / 9903 41.4 / 70.2
Gemma4 E2B 512x512 121 19 / 173 129 / 240 684 / 771 55.9 / 58.6
Gemma4 E2B 1024x1024 441 100 / 1231 256 / 1385 819 / 1919 55.2 / 58.2
Gemma4 E2B 1536x1024 672 180 / 2536 361 / 2725 938 / 3262 53.8 / 57.7
Gemma4 E2B 2048x2048 1089 352 / 6501 608 / 6778 1195 / 7321 52.9 / 57.1

The 2048x2048 source produced a 1440x1440 encoder input for Qwen and a 1584x1584 encoder input for Gemma. Vulkan generated tokens faster at every size. OpenVINO completed the full response sooner for both models at sizes of 1024x1024 and above.

With server warmup disabled, first-request TTFT at 512x512 was 4.41 / 1.00 s for Qwen and 26.51 / 0.60 s for Gemma.

Requirements

  • I have read and agree with the contributing guidelines.
  • AI usage disclosure: YES. Codex assisted with implementation, debugging, validation, documentation, and preparing this draft under the contributor's direction. Human review is pending.

@ravi9
ravi9 force-pushed the dev_backend_openvino branch 2 times, most recently from 7d8ccda to e0b9fd7 Compare November 27, 2026 02:29
Reuse Qwen vision graphs across image resolutions with runtime spatial
shapes and interpolation targets. Support Gemma spatial positions,
normalized vision attention and variable image-embedding counts.
Preserve recurrent cache state and sequence grouping during parallel
serving, using the native single-output cache-update contract. Keep
KV head dimensions fixed after relayout when applying dynamic axes.

Validated image requests and four-slot unified/split KV serving for
Qwen3.5 and Gemma4 E2B on OpenVINO CPU and GPU. Vision and recurrent
backend regressions passed 21/21 on each device.

(cherry picked from commit d64dcb5594db74c0f03945cac668aefcca75e0b1)
Store weight allocation generations separately from graph descriptors.
Private cache keys retain allocation isolation, while dynamic model
fingerprints stay stable when the same source weights are reloaded.
Honor GGML_PREC_F32 on MatMul src1 with node precision guards and precision-sensitive input paths, including grouped-query attention. Keep other branches at their configured precision. Probe the runtime helper and include precision guards in cache identities.

Validated on the local OpenVINO 2026.5.1 CPU/GPU runtime: 12/12 F32 precision cases under CPU default, CPU BF16 and GPU FP16 hints; mixed-precision branches and cached F32/default/F32 transitions; five real audio preprocessing lengths per device.
The official OpenVINO 2026.4.1 Runtime SDK exports the node precision helper. Remove its link probe and conditional fallback while retaining the Runtime SDK declaration shim and the recurrent-cache-op guard.

Validated the downloaded SDK with a compiled/linked API probe and 12/12 F32 MatMul cases on default CPU and FP16-hint GPU. The local 2026.5.1 build also passes 12/12 on each device. An additional 2026.4.1 CPU BF16-hint check has seven precision failures, independent of this availability-guard removal.
Move the exported helper declaration into mulmat.cpp and remove the single-consumer precision_control.hpp header.

Validated builds and 12/12 F32 MatMul cases on CPU/GPU with both the local OpenVINO build and the official 2026.4.1 Runtime SDK.

Assisted-by: Codex
@wine99
wine99 force-pushed the feat/openvino-multimodal branch from b41ce56 to 304c8a7 Compare November 27, 2026 08:33
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