[OpenVINO] Support Gemma3TextModel for feature-extraction#1799
[OpenVINO] Support Gemma3TextModel for feature-extraction#1799mlukasze wants to merge 6 commits into
Conversation
Enables clean OpenVINO feature-extraction export of Gemma3 text-embedding backbones such as microsoft/harrier-oss-v1-270m. Mirrors Qwen3OpenVINOConfig feature-extraction support (huggingface#1415): excludes position_ids and exports only input_ids + attention_mask for the embedding path. - model_configs.py: inputs property override on Gemma3TextOpenVINOConfig - test_modeling.py: gemma3_text in OVModelForFeatureExtractionIntegrationTest - test_export.py: gemma3_text in ExportModelTest Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
rkazants
left a comment
There was a problem hiding this comment.
needs proper PR description with code snippets
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
…eights tiny-random-gemma3-text on the Hub stores Gemma3ForCausalLM weights (with model. prefix) while model_type=gemma3_text. Loading via AutoModel/ Gemma3TextModel causes ALL weights to be randomly re-initialised, so the OV-exported model and the PyTorch reference end up with *different* random seeds and their outputs diverge → test_compare_to_transformers fails. Add _create_tiny_gemma3_text_model() that creates a Gemma3TextModel from the Hub config, saves its weights to a temp dir, and returns the path. MODEL_NAMES[gemma3_text] now points at this locally-saved model, so both the export and the comparison load identical weights. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Roman Kazantsev <roman.kazantsev@intel.com>
|
@mitruska, please check failing test https://github.com/huggingface/optimum-intel/actions/runs/28499616266/job/84473639987?pr=1799 |
…egression) test_compare_to_transformers_6_gemma3_text fails on transformers 4.57.6 and latest for two distinct reasons, both traced to the tiny-random-gemma3-text checkpoint versus transformers-side Gemma3TextModel changes - not a bug in this PR's own diff or in optimum-intel: - On transformers==4.57.6: Gemma3TextModel.base_model_prefix resolves to '' (and to 'language_model' on some nearby releases) instead of 'model', so none of the checkpoint's model.*-prefixed weights match and the reference model silently falls back to random init (transformers logs 'newly initialized' for every parameter). Comparing OV output against a randomly initialized reference is meaningless, so this case is now skipped with a clear reason instead of asserting nonsense. Real Gemma3TextModel checkpoints (e.g. microsoft/harrier-oss-v1-270m) are saved without any wrapper prefix and are unaffected - confirmed by the existing WWB accuracy results (~0.999 similarity) in openvinotoolkit/omega#18. - On transformers==latest: base_model_prefix correctly resolves to 'model' and weights load fine, but AutoModel now honors the checkpoint's torch_dtype=bfloat16 by default, so the reference forward pass runs in bf16 while OV always runs in fp32 (F32_CONFIG). torch.allclose raises instead of comparing because the dtypes differ. Cast both tensors to fp32 before comparing, with a slightly relaxed atol (2e-2) to absorb the bf16 rounding noise (~1.5e-2 observed) - mirroring the existing per-arch atol overrides already used in this test for flaubert/squeezebert. Verified locally: - transformers==4.57.6: test now skips (was: AssertionError) - transformers==latest (5.13.0): test now passes (was: RuntimeError) - Full OVModelForFeatureExtractionIntegrationTest class: no regressions for any other architecture under either transformers version. Unrelated, pre-existing CI failures observed but out of scope for this fix (confirmed unaffected by this change): test_compare_to_transformers_4_qwen3_vl_embedding (latest-only package drift) and PIL.UnidentifiedImageError flakiness in test_quantization.py.
|
Thanks for flagging this, @mitruska — investigated and pushed a fix in Root cause (two distinct issues, both external to this PR's diff)
Neither issue is caused by this PR's diff (only touches FixNarrowly scoped to
Verification (local)
Follow-up (logged, not addressed here to keep this PR minimal)The durable fix is re-saving CI on the new commit is currently |
What does this PR do?
Adds a
feature-extractioninputs override toGemma3TextOpenVINOConfigso thatGemma3TextModel-based text-embedding models (e.g.microsoft/harrier-oss-v1-270m) export cleanly to OpenVINO IR.Without the override the config inherits
GemmaOpenVINOConfig.inputs, which injectsposition_idsinto the graph and breaks sentence-transformers-style callers that pass onlyinput_ids+attention_mask.Mirrors the pattern used for
Qwen3OpenVINOConfigadded in #1415.Installation instructions
Exporting cmd-line
Inference script
Before submitting