Polygraphy --load-inputs and inspect data fail with ValueError when a tensor is named Tensor or ndarray
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
Research direction
Start with tools/Polygraphy/polygraphy/json/serde.py, especially Decoder.__call__ around lines 180–185 and the registered names around lines 142–143. Reproduce with from_json(to_json({"ndarray": np.array([1, 2])})) and inspect the failing legacy marker check. Done means saved inputs whose tensor names match registered type names load successfully, and the reported 0-D marker string case no longer raises KeyError.
Written by the indexing model from the issue text.
Description
Description
Polygraphy cannot load JSON data it saved itself when a tensor is named after one of the types it serializes, such as Tensor or ndarray. polygraphy run --save-inputs writes the file, but --load-inputs and polygraphy inspect data on that file fail:
File ".../polygraphy/json/serde.py", line 183, in __call__
type_str in dct and dct[type_str] == constants.LEGACY_TYPE_MARKER
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Decoder.__call__ checks every registered name for the legacy marker string (serde.py#L180-L185). The registered names include the current type names (ndarray, Tensor, RunResults, IterationResult, LazyArray, ...) as well as the legacy __polygraphy_encoded_* ones (serde.py#L142-L143). JSON objects are decoded innermost first, so in a saved feed dict {"Tensor": ...} the value is already a NumPy array when this check runs, and array == "polygraphy_serialized_json_type" compares element-wise.
A 0-d string array equal to the marker is misread as legacy data instead: from_json(to_json({"ndarray": np.array("polygraphy_serialized_json_type")})) raises KeyError: 'array'.
Saved outputs are not affected, because they are stored through LazyArray.
I found this by reading and testing the code.
Environment
TensorRT Version: not needed; the failing path is pure Python (ONNX Runtime backend)
NVIDIA GPU: none
NVIDIA Driver Version: none
CUDA Version: none
CUDNN Version: none
Operating System: Linux x86_64 (Fedora 44)
Python Version (if applicable): 3.12.13
PyTorch Version (if applicable): 2.14.1+cpu (only for the Tensor type registration)
Polygraphy: 0.53.6 from main at 16ed063; NumPy 1.26.4, ONNX 1.23.2, ONNX Runtime 1.31.0
Relevant Files
Model link: generated by the script below.
Steps To Reproduce
Commands or scripts:
# make_model.py: Identity model whose input tensor is named "Tensor"
import onnx
from onnx import TensorProto, helper
graph = helper.make_graph(
[helper.make_node("Identity", ["Tensor"], ["out"])],
"g",
[helper.make_tensor_value_info("Tensor", TensorProto.FLOAT, [1, 4])],
[helper.make_tensor_value_info("out", TensorProto.FLOAT, [1, 4])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 17)])
model.ir_version = 8
onnx.save(model, "model.onnx")
python make_model.py
polygraphy run model.onnx --onnxrt --save-inputs inputs.json # PASSED
polygraphy run model.onnx --onnxrt --load-inputs inputs.json # ValueError above
polygraphy inspect data inputs.json --show-values # ValueError above
Without a model:
import numpy as np
from polygraphy.json import from_json, to_json
from_json(to_json({"ndarray": np.array([1, 2])})) # ValueError
Have you tried the latest release?: Reproduced on main (16ed063, Polygraphy 0.53.6).
Can this model run on other frameworks? The run itself succeeds with ONNX Runtime; only loading the saved JSON fails.
I made this report and directed the investigation, with AI assistance from Claude and GPT-6 Astra.
- Dominant language
- C++
- Stars
- 13.4k
- Forks
- 2.4k
- Avg merge
- 15m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/TensorRT
-
EmbLayerNormVarSeqlenPlugin: dangling pointer and out-of-bounds read during serializationPossibly taken @gabortar claimed this 10 days ago. OpenModule:Plugins
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
onnx-graphsurgeon: Graph.toposort() hits RecursionError when a graph has a local function and an If/Loop nodePossibly taken @gabortar claimed this 10 days ago. OpenModule:GraphSurgeon
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Polygraphy parse_meta accepts a shape with a missing bracketPossibly taken @SashaMIT claimed this 22 days ago. OpenModule:Polygraphy
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
onnx_graphsurgeon: Constant with float8_e4m3fnuz values is exported as FLOAT8E4M3FNPossibly taken @luicarus claimed this 32 days ago. OpenModule:GraphSurgeon
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
Deprecate demoDiffusionMay be free again A pull request for this issue was closed without being merged. OpenModule:Demo
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
foxglove/mcap#1907 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
Documentation
Difficulty 1/5 1-3 hours Newbie friendliness 72/100
qbittorrent/qBittorrent#25127 · 1 comment ·
Maintainers usually reply within 2 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
telegramdesktop/tdesktop#31505 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day