Skip to content

Fix decoder reranker export in seq-cls class - #1508

Open
Ibrahim AlRayes (IbrahimRayes) wants to merge 1 commit into
qualcomm:mainfrom
IbrahimRayes:fix/qwen3-embedding-export
Open

Ibrahim AlRayes (IbrahimRayes) wants to merge 1 commit into
qualcomm:mainfrom
IbrahimRayes:fix/qwen3-embedding-export

Conversation

@IbrahimRayes

Copy link
Copy Markdown
Contributor

Summary

Decoder-only rerankers such as Qwen3-Reranker (the *ForSequenceClassification form vLLM uses for task: "score") fail to export with QEFFAutoModelForSequenceClassification. This PR fixes that and adds CPU coverage for decoder-based embedding and reranker models.

Related to #1445. The Qwen3-Embedding IndexError reported there does not reproduce on main (transformers 5.19 no longer has the failing sdpa_mask branch); the release-branch fix will be a separate PR.

Root cause

  1. __init__ sets config.use_cache = True (Adding support of QEFFAutoModelForSequenceClassification #729), so decoder heads return a DynamicCache, which the TorchScript tracer rejects.
  2. TF upgrade to 5.19.0 #1287 added FP16ClipTransform without SplitTensorsTransform, so weights are inlined and models over 2 GB produce an unloadable ONNX (Qwen3-Reranker-0.6B, and BAAI/bge-reranker-v2-m3 on current main). Add SplitTensorsTransform to QEFFAutoModel to prevent >2GB protobuf export issue #950 fixed the same issue for QEFFAutoModel.

Fix

  • use_cache = False (a single-pass classifier needs no cache).
  • _onnx_transforms = [FP16ClipTransform, SplitTensorsTransform], as in QEFFAutoModel.

Tests

  • New test_qwen3_embedding_and_reranker_cpu_parity_and_export: tiny Qwen3 through QEFFAutoModel and QEFFAutoModelForSequenceClassification, HF vs QEff vs ORT (atol 1e-5), weights stored as external data. seq_classification fails on main without the fix and passes with it.
  • Proxy-policy test updated (Split always on). New reproducer scenario qwen3-embedding-export; the export runner now passes model_api="embedding" to QEFFAutoModel.
  • Full test_model_quickcheck.py: 286 passed vs 284 on main, same 26 offline-download failures on both. Ruff clean.

Validation (vs HF fp32, 20 texts / 20 pairs)

Model ONNX Runtime AI 100 (1 SoC, fp16)
Qwen3-Embedding-0.6B (QEFFAutoModel) min cosine 1.000000 min cosine 0.999984
Qwen3-Reranker-0.6B (seq-cls) max abs diff 3.7e-8 8.8e-6, same ranking
bge-reranker-v2-m3 (seq-cls) 1.4e-5 (did not load before) not run

Known limitation

generate right-pads with 0, not pad_token_id; decoder rerankers need inputs pre-padded with the tokenizer's pad id.

Signed-off-by: Ibrahim Alrayes <ialrayes@qti.qualcomm.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant