Skip to content

Custom ONNX metadata unreadable for PaddlePaddle PIR-mode models #529

@Goldziher

Description

@Goldziher

Summary

session.metadata().custom_keys() returns an empty list and session.metadata().custom("character") returns an empty string when loading PaddlePaddle PIR-mode exported ONNX models that contain custom metadata.

The same models loaded via Python's onnxruntime.InferenceSession correctly return the metadata through session.get_modelmeta().custom_metadata_map.

Reproduction

Model: en_PP-OCRv4_rec_infer.onnx (PaddleOCR v4 recognition model exported with PIR mode, ~7.7MB)

Rust (ort 2.0.0-rc.11, load-dynamic feature, onnxruntime 1.24.1):

let session = Session::builder()?.commit_from_file("en_PP-OCRv4_rec_infer.onnx")?;
let metadata = session.metadata()?;
println!("{:?}", metadata.custom_keys());   // prints: []
println!("{:?}", metadata.custom("character")); // prints: Some("")

Python (onnxruntime 1.21.0):

import onnxruntime as ort
session = ort.InferenceSession("en_PP-OCRv4_rec_infer.onnx")
meta = session.get_modelmeta().custom_metadata_map
print(len(meta["character"]))  # prints: 190 (correct)

Environment

  • ort 2.0.0-rc.11 with load-dynamic feature
  • Tested with onnxruntime 1.23.2 and 1.24.1 — same result
  • macOS (aarch64) and Linux (x86_64)
  • Model exported by PaddlePaddle in PIR mode (paddle2onnx)

Notes

The metadata is present in the ONNX protobuf — Python reads it fine. The issue appears to be in how ort surfaces custom metadata entries from the C API. Standard metadata fields (producer, description, etc.) read correctly; only the custom key-value map is affected.

Workaround: ship the dictionary as a separate file and load it outside the ONNX model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions