Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#4,889 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
numpy, python
領域
ai, backend

調査の方向性

まず tools/Polygraphy/polygraphy/json/serde.py を確認し、特に180~185行付近の Decoder.__call__ と、142~143行付近の登録名を調べてください。from_json(to_json({"ndarray": np.array([1, 2])})) で再現し、失敗するレガシーマーカーのチェックを調べてください。テンソル名が登録済みの型名と一致する保存済み入力が正常に読み込まれ、報告された0-Dマーカー文字列のケースで KeyError が発生しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
13.4k
フォーク
2.4k
平均マージ
15分
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/TensorRT のほかの issue

NVIDIA/TensorRT の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。