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

optimize() crashes when constant folding produces a string tensor

オープン
#3,129 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

@nniiovoo がすでに取り組んでいます。

2026年10月26日 から。

  • #3130 @nniiovoo による — オープン

評価

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

調査の方向性

Start with onnxscript.optimizer._constant_folding._prepare_folded_tensor, which the issue identifies as wrapping folded NumPy results with ir.tensor(output_array). Reproduce with the provided constant string tensor model and check that onnxscript.optimizer.optimize() serializes and runs it successfully; account for the open linked pull request when assessing whether work remains.

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

説明

onnxscript.optimizer.optimize() fails on valid models when constant folding produces a string tensor, for example an Identity or Concat on a constant list of class labels.

import numpy as np
import onnx
import onnxruntime as ort

import onnxscript.optimizer

model = onnx.parser.parse_model(
    """
    <ir_version: 8, opset_import: ["" : 18]>
    agraph (int64[1] idx) => (string[1] label)
    <string[3] classes = {"cat", "dog", "bird"}>
    {
        labels = Identity(classes)
        label = Gather(labels, idx)
    }
    """
)


def run(m):
    sess = ort.InferenceSession(m.SerializeToString(), providers=["CPUExecutionProvider"])
    return sess.run(None, {"idx": np.array([2], np.int64)})[0]


print("before optimize:", run(model))
print("after optimize:", run(onnxscript.optimizer.optimize(model)))

Output:

before optimize: ['bird']
...
TypeError: Bitwidth not available for ONNX data type: STRING
...
onnx_ir.passes.PassError: An error occurred when running the '<onnxscript.optimizer._constant_folding.FoldConstantsPass ...>' pass ...

_prepare_folded_tensor wraps the folded numpy result with ir.tensor(output_array). For a string array that gives a numeric Tensor with dtype STRING instead of a StringTensor, and serializing it fails.

Versions: onnxscript main (4002c079), onnx 1.23.2, onnxruntime 1.31.0, onnx_ir 1.0.0 (same with 1.1.0), Python 3.12.15, macOS arm64.

This is separate from #3110, which fixes non-ASCII strings in Constant attributes. I have a small fix and can open a PR.

主要言語
Python
スター
456
フォーク
148
平均マージ
3日 19時間
マージ済み PR(30日)
20

環境構築

はじめの一歩

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

microsoft/onnxscript のほかの issue

microsoft/onnxscript の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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