You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: clamp embedding batch size to the ONNX graph batch axis (#970)
A model registered through TextEmbedding.add_custom_model() against the
Qwen3 causal-LM ONNX weights crashed on any batch larger than one:
onnxruntime ... Shape mismatch attempting to re-use buffer.
{1,1,18,18} != {8,1,18,18}
CustomTextEmbedding inherits OnnxTextEmbedding.embed, whose default is
batch_size=256, while the graph is pinned to a batch of one.
Qwen3TextEmbedding avoided this by hardcoding batch_size=1 in its own
embed; CustomTextEmbedding had no such override.
Read the batch axis from the loaded session instead of hardcoding it:
_detect_static_batch_size() records the literal the graph declares (or
None when the axis is symbolic) at load time, and _embed_documents()
clamps the requested batch size to it on both the sequential and the
worker-pool path. A graph with a dynamic batch axis keeps batching at
the size the caller asked for.
The inputs alone are not authoritative -- the Qwen3 export declares
input_ids as ['batch_size', 'sequence_length'] yet emits
last_hidden_state as [1, 'sequence_length', 1024] -- so the outputs are
inspected as well.
0 commit comments