Qwen3-VL-2B retrieval pair in ONNX

Qwen3-VL-Embedding-2B and Qwen3-VL-Reranker-2B for ONNX Runtime, without PyTorch: texts and images (any size and shape) in one vector space, and a reranker for both. Exported for paperus, a self-hosted research library, where they search papers' passages and figures together; usable on their own.

Files

shared/      vision_encoder_fp16.onnx   the vision encoder (identical in both models)
             embed_tokens_fp16.npy      the token embedding table (identical in both)
             tokenizer.json
embedding/   decoder_fp16.onnx          language model β†’ normalized last-token vector (2048)
             decoder_int8.onnx          the same with 8-bit weights (half the memory)
reranker/    decoder_fp16.onnx          language model β†’ yes-minus-no logit (the score)
             decoder_int8.onnx          the same with 8-bit weights
export/      the export and check scripts

Both models share their vision encoder and token table byte for byte, so one copy serves both.

Inputs

Vision encoder, one image per call: pixel_values (patches Γ— 1536, fp16: 3 channels Γ— 2 frames Γ— 16 Γ— 16, normalized to [-1, 1]), interp_indices and interp_weights (patches Γ— 4: the bilinear resampling of the learned 48 Γ— 48 position grid to the image's grid), position_ids (patches Γ— 2: each patch's row and column). Out: image_features (patches / 4 Γ— 2048) and deepstack_features (3 Γ— patches / 4 Γ— 2048). The grid-dependent inputs are computed outside the graph, so any image size works; patches are ordered in 2 Γ— 2 blocks as in transformers' Qwen2-VL image processor.

Decoders: inputs_embeds (batch Γ— tokens Γ— 2048, fp16: the token table's rows, the image features in place of the image tokens), attention_mask (padding on the left), position_ids (3 Γ— batch Γ— tokens: Qwen3-VL's time / row / column positions), deepstack (3 Γ— batch Γ— tokens Γ— 2048: the DeepStack features at the image tokens, zeros elsewhere). Out: embedding (batch Γ— 2048, normalized) or score (batch).

The token sequences are those of sentence-transformers 5.4 with the models' chat templates; note the embedding model's sequence ends with <|endoftext|>, whose state is the vector. A complete implementation in numpy (image preparation, grid inputs, positions, sequences, batching): paperus_ml/qwen3_vl.py (Apache-2.0).

Agreement with the originals

Against the original models in PyTorch (fp16, sentence-transformers), on figures from physics papers and on English and German texts:

fp16 decoders 8-bit decoders
vision encoder cosine 0.9995–0.99999 (fp16)
embedding, texts cosine 0.9999–1.0001 0.9986–0.9991
embedding, images (image prepared in numpy) 0.998–0.999 0.996–0.997
reranker scores within Β±0.03, same order scores shifted by about +0.19, same order

Differences come from rounding (other kernels, summation order, fp16) and, for images, from resizing with OpenCV instead of torchvision. Vectors from these files should not be mixed with vectors from the originals or from the other decoder file.

Measured in paperus (docs/search.md there): on 3,198 figures of physics papers, searched by how they look, Qwen3-VL-Embedding on the image put the right figure first for 40 % of 65 questions, 62 % with the reranker on the top 20; on 200 questions about the papers' text the pair matched or beat arctic-embed-m-v2 with bge-reranker-v2-m3.

Speed (RTX 2080 SUPER, ONNX Runtime 1.31 CUDA): a query about 15–25 ms; reranking 10 candidates of about 300 tokens 0.33 s. Not faster than PyTorch (within about 10 %); the point is a small runtime without it.

Export

export/export_vision.py and export/export_decoder.py / export/export_reranker.py (transformers 5.22, torch 2.15, ONNX dynamo export) replace the vision encoder's per-segment attention loop by full attention (one image per call), take the grid-dependent tensors as inputs (transformers' vision_utils accepts them precomputed), and take the DeepStack features spread over the sequence. export/quantize.py makes the 8-bit decoders (ONNX Runtime's MatMulNBits, block 128, fp16 compute); plain 4-bit weights lost too much (cosine 0.85–0.92) and are not included. export/check_*.py are the comparisons above.

Licence

Apache-2.0, as the original models (Β© Alibaba Qwen team). The export uses code of Hugging Face transformers (Apache-2.0).

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for headtrick/Qwen3-VL-2B-Retrieval-ONNX

Quantized
(32)
this model