Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Polygraphy --load-inputs and inspect data fail with ValueError when a tensor is named Tensor or ndarray

Open Beginner friendly
#4,889 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
ai, backend

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

Module:Polygraphy

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/TensorRT

All issues in NVIDIA/TensorRT

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.