Add eliminate_initializer_from_input pass - #325
Open
take-cheeze wants to merge 1 commit into
Open
Conversation
IR<4 exports (e.g. the onnx-caffe2 models in the ONNX Model Zoo) list every initializer in graph.input as well. ONNX treats an initializer that is also a graph input as an overridable default rather than a constant, so Graph::is_constant_initializer -- and hence IsConstantTensor -- reports the weights as non-constant. That silently disables every constant-dependent pass (fuse_bn_into_conv, fuse_add_bias_into_conv, fuse_matmul_add_bias_into_gemm, constant folding, ...), so these models leave the optimizer completely unchanged. Add a pass that removes an initializer's redundant graph.input entry (keeping the initializer), i.e. normalises the legacy graph to the IR>=4 form, and register it so it runs before the constant-dependent fusions. Verified on onnxmodelzoo/resnet101-v1-7 (IR version 3, 588 initializers all listed as inputs): with the inputs stripped, fuse_bn_into_conv folds all 104 BatchNormalization nodes it previously left untouched, matching onnxslim's output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CzPBPhoPYRKPVcjZcVFy5h Signed-off-by: take-cheeze <takechi101010@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IR<4 exports (e.g. the onnx-caffe2 models in the ONNX Model Zoo) list every initializer in graph.input as well. ONNX treats an initializer that is also a graph input as an overridable default rather than a constant, so Graph::is_constant_initializer -- and hence IsConstantTensor -- reports the weights as non-constant. That silently disables every constant-dependent pass (fuse_bn_into_conv, fuse_add_bias_into_conv,
fuse_matmul_add_bias_into_gemm, constant folding, ...), so these models leave the optimizer completely unchanged.
Add a pass that removes an initializer's redundant graph.input entry (keeping the initializer), i.e. normalises the legacy graph to the IR>=4 form, and register it so it runs before the constant-dependent fusions.
Verified on onnxmodelzoo/resnet101-v1-7 (IR version 3, 588 initializers all listed as inputs): with the inputs stripped, fuse_bn_into_conv folds all 104 BatchNormalization nodes it previously left untouched, matching onnxslim's output.
Claude-Session: https://claude.ai/code/session_01CzPBPhoPYRKPVcjZcVFy5h