Polygraphy --load-inputs and inspect data fail with ValueError when a tensor is named Tensor or ndarray
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
調査の方向性
まず 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 の本文から書いたものです。
説明
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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
NVIDIA/TensorRT のほかの issue
-
EmbLayerNormVarSeqlenPlugin: dangling pointer and out-of-bounds read during serialization対応中かも @gabortar が 9 日前に担当しました。 オープンModule:Plugins
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
onnx-graphsurgeon: Graph.toposort() hits RecursionError when a graph has a local function and an If/Loop node対応中かも @gabortar が 10 日前に担当しました。 オープンModule:GraphSurgeon
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
Polygraphy parse_meta accepts a shape with a missing bracket対応中かも @SashaMIT が 22 日前に担当しました。 オープンModule:Polygraphy
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
onnx_graphsurgeon: Constant with float8_e4m3fnuz values is exported as FLOAT8E4M3FN対応中かも @luicarus が 32 日前に担当しました。 オープンModule:GraphSurgeon
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
Deprecate demoDiffusion再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンModule:Demo
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
NVIDIA/TensorRT の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
foxglove/mcap#1907 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
telegramdesktop/tdesktop#31505 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
ll-builder shell completions omit existing lockfile commands and --locked対応中かも @project-nju-learner が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
OpenAtom-Linyaps/linyaps#2291 ·
メンテナーはふだん 1 日以内に返信