ONNX export failed for Qwen/Qwen3-Embedding-0.6B with "invalid unordered_map<K, T> key"

Hello everyone,

I am trying to export the “Qwen/Qwen3-Embedding-0.6B” model to ONNX using the “optimum” library. According to the Optimum documentation, the “Qwen3” architecture is supported for ONNX export.

However, the export process fails with a error: “invalid unordered_map<K, T> key”

from optimum.exporters.onnx import main_export
import os

model_id = "Qwen/Qwen3-Embedding-0.6B"
output_dir = "qwen3_embedding_onnx_from_script"
os.makedirs(output_dir, exist_ok=True)

print(f"start export '{model_id}' ")

try:
    main_export(
        model_id,
        output=output_dir,
        task="feature-extraction",
        trust_remote_code=True,
        opset=20
    )
    print(f"Model '{model_id}' finish '{output_dir}'")

except Exception as e:
    print(f"error: {e}")
  • I have tried using both task='feature-extraction' and task='default' (by letting optimum infer it automatically).
  • Both attempts result in the same invalid unordered_map<K, T> key error.
1 Like

This seems pretty difficult to get working. I failed too. I don’t want to reinstall PyTorch…:sob:

# pip install -U optimum[onnxruntime]
# pip install -U accelerate transformers sentence-transformers

from optimum.exporters.onnx import main_export
import os

model_id = "Qwen/Qwen3-Embedding-0.6B"
output_dir = "qwen3_embedding_onnx_from_script"
os.makedirs(output_dir, exist_ok=True)

print(f"start export '{model_id}' ")

try:
    main_export(
        model_id,
        output=output_dir,
        task="feature-extraction",
        trust_remote_code=True,
        opset=20 # opset=17 with PyTorch 1.x may work? https://huggingface.co/zhiqing/Qwen3-Embedding-0.6B-ONNX/discussions/1 https://github.com/pytorch/pytorch/issues/120559
        # With 2.x, "error: Exporting the operator 'aten::__ior_' to ONNX opset version 20 is not supported."
    )
    print(f"Model '{model_id}' finish '{output_dir}'")

except Exception as e:
    print(f"error: {e}")

invalid unordered_map<K, T> key error.

Seems 2.x issue, too…

1 Like

Probably, if a parameter that forces attn_implementation="eager" at model.from_pretrained() part is implemented in Exporter, it will work with PyTorch 2.x as well…

Thank you for your help! Unfortunately, your suggestions didn’t work:

  1. Tried attn_implementation=“eager” - same “invalid unordered_map<K, T> key” error
  2. Tested opset from 16 to 20 - identical results
  3. Tried different export approaches (ORTModelForFeatureExtraction, torch.onnx.export) - same failure everywhere

It seems the issue is deeper at the compatibility level between Qwen3 architecture and current PyTorch/ONNX versions. (((((

1 Like

Yeah, the error was indeed tied to torch 2.6.0. I installed this combo: pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1, and the issue is gone—thanks for the heads-up! Man, I’m so fed up with these constant PyTorch “rollercoasters” (((

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.