Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds initial support for the Gemma4 visual-language model in the C++ VLM pipeline, extending the existing model-type routing, preprocessing config, and LM input wiring to handle Gemma4’s vision encoder + optional per-layer text embeddings.
Changes:
- Add
GEMMA4model type and wire it intoVisionEncoderandInputsEmbedderfactories. - Introduce Gemma4-specific vision preprocessing + prompt normalization and optional
per_layer_inputshandling. - Extend LM generation to recompute and feed
per_layer_inputsduring the generation phase when available.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/cpp/src/visual_language/vlm_config.hpp | Adds GEMMA4 model type and Gemma4 prompt token fields. |
| src/cpp/src/visual_language/vlm_config.cpp | Maps "gemma4" string to VLMModelType::GEMMA4. |
| src/cpp/src/visual_language/vision_encoder.cpp | Routes Gemma4 to VisionEncoderGemma4. |
| src/cpp/src/visual_language/processor_config.hpp | Adds Gemma4 processor params (pooling_kernel_size, max_soft_tokens). |
| src/cpp/src/visual_language/processor_config.cpp | Reads Gemma4 processor params from JSON when present. |
| src/cpp/src/visual_language/pipeline.cpp | Passes per-layer embedding queue to LM encoding; extends SDPA requirement to Gemma4. |
| src/cpp/src/visual_language/inputs_embedder.hpp | Exposes optional per-layer embeddings queue from embedders. |
| src/cpp/src/visual_language/inputs_embedder.cpp | Instantiates InputsEmbedderGemma4 and forwards queue accessor. |
| src/cpp/src/visual_language/gemma4/classes.hpp | Declares Gemma4 vision encoder + inputs embedder. |
| src/cpp/src/visual_language/gemma4/classes.cpp | Implements Gemma4 preprocessing, prompt normalization, and per-layer embeddings model support. |
| src/cpp/src/lm_encoding.hpp | Extends get_lm_encoded_results() signature to accept per-layer embeddings request queue. |
| src/cpp/src/lm_encoding.cpp | Recomputes per_layer_inputs on each generation step when configured. |
Comment on lines
+109
to
+110
| // fixme: there is seem to be an issue with how image_token is replaced. unified_prompt.find needs search_offset. | ||
| // refer to gemma4 implementation. |
Comment on lines
+116
to
+127
| // 5. Extract patches: (num_patches, patch_size*patch_size*3) | ||
| const size_t num_patches_h = target_height / config.patch_size; | ||
| const size_t num_patches_w = target_width / config.patch_size; | ||
| const size_t patch_dim = config.patch_size * config.patch_size * 3; | ||
|
|
||
| // Create padded pixel_values tensor [1, max_patches, patch_dim] | ||
| ov::Tensor pixel_values(ov::element::f32, {1, max_patches, patch_dim}); | ||
| float* pv_data = pixel_values.data<float>(); | ||
| std::fill(pv_data, pv_data + max_patches * patch_dim, 0.0f); | ||
|
|
||
| extract_patches(float_image, config.patch_size, pv_data, num_patches_h, num_patches_w); | ||
|
|
|
|
||
| ov::Tensor input_ids = get_encoded_input_ids(prompt, metrics); | ||
|
|
||
| m_lm_extra_inputs["per_layer_inputs"] = get_per_layer_embeddings(input_ids); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Depends on: huggingface/optimum-intel#1688
optimum-intel PR depends on transformers v5 (update: transformers v5 support merged to optimum-intel).
WWB Accuracy:
genai vs optimum-intel: 0.9682357
genai vs transformers: 0.94821364
optimum-intel vs transformers: 0.9387633
Fixes: #3653
Checklist: