BatchNormalization layer with training_mode=1 results in incorrect ONNX model

オープン
#2,969 コメント 4 件 リアクション 1 件 担当者 2 名 GitHub で見る

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

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

2026年8月4日 から。

  • #2988 @copilot-swe-agent による — マージされずにクローズ

評価

この issue はまだ評価されていません。

説明

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

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

環境構築

はじめの一歩

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

microsoft/onnxscript のほかの issue

microsoft/onnxscript の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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