Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

optimize() crashes when constant folding produces a string tensor

Aperta
#3,129 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@nniiovoo ci sta già lavorando.

Dal 26/10/2026.

  • #3130 di @nniiovoo — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
456
Fork
148
Merge medio
3g 13h
PR unite (30g)
21

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/onnxscript

Tutte le issue di microsoft/onnxscript

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.