BatchNormalization layer with training_mode=1 results in incorrect ONNX model

Aperta
#2,969 4 commenti 1 reazione 2 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

@justinchuby ci sta già lavorando.

Dal 4/8/2026.

  • #2988 di @copilot-swe-agent — chiusa senza merge

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

converting the attached ONNX model with the following script:

from onnxscript import ir
from onnxscript.optimizer import optimize

ir_model = ir.load("input.onnx")
optimized_model = optimize(ir_model)
ir.save(optimized_model, "output.onnx")

generates an ONNX model that does not abide by the ONNX spec.

BatchNormalization layer "/bn1/BatchNormalization" has training_mode=1 set. It has 3 outputs, but the last two are not used. Because they are unused, https://github.com/onnx/ir-py/blob/v0.2.1/src/onnx_ir/passes/common/unused_removal.py#L46-L50 clears the output names and training_mode attribute. While I don't like the notion of unnamed outputs to mean unused, it is an accepted way in ONNX. Later on during optimization, at https://github.com/microsoft/onnxscript/blob/v0.7.0/onnxscript/optimizer/_optimizer.py#L68, new names get reassigned to these outputs, resulting in the following graph snippet:

Image

This graph now has a BatchNormaliztion node, with training_mode=0, with 3 outputs. This is incorrect per spec: "When training_mode=False, extra outputs are invalid." in https://onnx.ai/onnx/operators/onnx__BatchNormalization.html#batchnormalization-15.

I filed this bug with onnxscript, even though the name-clearing happens in onnx-ir.

relevant versions:

onnx                          1.21.0
onnx-ir                       0.2.1
onnxscript                    0.7.1

input.onnx.zip

Lingua principale
Python
Stelle
457
Fork
149
Merge medio
3g 20h
PR unite (30g)
22

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.