Repository navigation
optimum-emb: feed position_ids to embedding IRs that take them - #204
Merged
Merged
Conversation
Decoder-based embedding IRs exported before optimum-intel 1.26, such as
Echo9Zulu/Qwen3-Embedding-0.6B-int8_asym-ov (optimum-intel 1.25.2), have
position_ids as a graph input. OVModelForFeatureExtraction.forward() only
passes input_ids and attention_mask (it drops extra kwargs), so:
- GPU: every request fails with "Got unexpected inputs: expecting the
following inputs {'position_ids', 'attention_mask', 'input_ids'}",
even a single string.
- CPU: inference runs on an unset tensor and returns NaN, which then
fails JSON encoding ("Out of range float values are not JSON
compliant: nan").
When the compiled model lists position_ids among its inputs, build them
from the attention mask (cumsum - 1, padding positions set to 1, the
same rule optimum-intel's OVModelForCausalLM uses, so left and right
padding both work) and call the compiled model with all three inputs.
IRs without position_ids (encoder models, current optimum-intel
exports) keep the forward() path unchanged.
Fixes SearchSavior#106.
Claude-Session: https://claude.ai/code/session_01H45h8vWtUhMNST1Fk179WR
Hardening for the position_ids path added in the previous commit:
- Also fill token_type_ids (zeros) and decoder_input_ids when the IR
takes them, as OVModelForFeatureExtraction.forward() does, so an IR
with position_ids plus one of these still gets every input.
- At load, log when an IR takes position_ids, and warn about inputs the
engine cannot fill, with a pointer to re-export.
- Integration test: a padded batch of different lengths instead of one
text, finite unit-length vectors, and a text alone vs in the batch.
The old test (one vector, len > 0) passed on the bug; this one fails
on main with the old Qwen3-Embedding export ("Got unexpected inputs:
expecting ... position_ids").
Checked on both IR layouts of Qwen3-Embedding-0.6B int8: the Echo9Zulu
export (optimum-intel 1.25.2, takes position_ids) and a re-export with
optimum-intel 2.3.0.dev0 (input_ids + attention_mask only, forward()
path).
Claude-Session: https://claude.ai/code/session_01H45h8vWtUhMNST1Fk179WR
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.
TL;DR: Makes the listed Qwen3 embedding model work instead of failing every request.
Fixes #106.
the Qwen3-Embedding export in docs/models.md (Echo9Zulu/Qwen3-Embedding-0.6B-int8_asym-ov) was made with optimum-intel 1.25.2 and has
position_idsas a graph input.OVModelForFeatureExtraction.forward()only passesinput_idsandattention_mask(extra kwargs are dropped), so every request fails, even one string:Got unexpected inputs: expecting the following inputs {'position_ids', 'attention_mask', 'input_ids'} but got ...when the compiled model lists
position_ids, the engine builds it from the attention mask (cumsum - 1, padding set to 1, the rule optimum-intel'sOVModelForCausalLMuses, so left and right padding both work) and calls the compiled model with every inputforward()would have sent plusposition_ids. IRs without it (bert-style, and decoder exports from optimum-intel >= 1.26, after huggingface/optimum-intel#1415) still go throughforward(), nothing changes for them. at load the engine logs when an IR takesposition_idsand warns about any input it can't fill.re-exporting with a current optimum-intel is the other fix (a 2.3.0.dev0 int8 re-export has only
input_ids+attention_mask), so the hf upload / docs/models.md could be updated too. this PR keeps the existing export working.B50, Qwen3-Embedding-0.6B int8, both IR layouts:
position_idspathforward()path, same as mainvs the PyTorch reference (Qwen/Qwen3-Embedding-0.6B fp32, last-token pooling): cosine 0.996-0.999 per text for both exports, model card example query->passage 0.764 / 0.765 vs 0.767.
tests
test_chunk_forward_pass_yields_chunks,test_make_chunks_handles_newlines_and_empty)note: batches with different-length texts still need
"config": {"padding": true}on main; making plain OpenAI requests work is a separate PR (stacked on this one).https://claude.ai/code/session_01H45h8vWtUhMNST1Fk179WR