Skip to content

Disallow overriding initializers if IR version < 4 - #1324

Merged
Scott McKay (skottmckay) merged 4 commits into
masterfrom
skottmckay/CleanupInitializerHandling
Jul 3, 2019
Merged

Disallow overriding initializers if IR version < 4 #1324
Scott McKay (skottmckay) merged 4 commits into
masterfrom
skottmckay/CleanupInitializerHandling

Conversation

@skottmckay

Copy link
Copy Markdown
Contributor

Description:

  • Disallow overriding an initializer via a graph input if the IR version is < 4. This enforces an implicit assumption that initializers should be treated as constant, and allows constant folding to be done on a model with an older IR version.
  • Separate constant and overridable initializers so that it's clear which ones constant folding can utilize.
  • Update Graph to not add all initializers to the graph inputs when the graph is manually created (i.e. not loaded from a GraphProto) and the IR version is >= 4.

Motivation and Context
In order to do constant folding we need to know which initializers can be treated as constant and which are overridable. All initializers were required to have a matching graph input prior to IR version 4, technically making all of them overridable. The intention however was for them to be treated as constants, and this change enforces that intent.

The benefit of doing so is that constant folding will work for models with IR version < 4. The cost is that if someone is actually overriding an initializer they will need to update the IR version of their model to version 4 in order to keep doing so. The belief is that this is a very small subset of usage (e.g. models involving feeding in a truncated sequence) and the cost to update that small subset is warranted by the benefit of constant folding being able to be enabled on all older models without them needing an IR version update.

Comment thread onnxruntime/core/framework/session_state.cc Outdated
Comment thread onnxruntime/core/framework/session_state_initializer.cc Outdated
Comment thread onnxruntime/core/framework/session_state_initializer.cc Outdated
Comment thread onnxruntime/core/graph/graph_utils.cc Outdated
Comment thread onnxruntime/core/graph/graph_utils.cc Outdated
Comment thread onnxruntime/core/optimizer/constant_folding.cc
Comment thread onnxruntime/core/session/inference_session.cc Outdated
Comment thread onnxruntime/core/session/inference_session.cc Outdated
@ke1337

Ke Deng (ke1337) commented Jul 2, 2019

Copy link
Copy Markdown
Contributor

CodeFlow for GitHub does not download executable files. If you trust this file and would like to run it, please download it yourself through GitHub.

should the model file named .pb like others in the folder? #ByDesign


Refers to: onnxruntime/test/testdata/optional_inputs_ir3.onnx:1 in f54e356. [](commit_id = f54e356, deletion_comment = False)

Comment thread onnxruntime/core/graph/graph.cc
Comment thread onnxruntime/core/graph/graph_utils.cc Outdated
@skottmckay

Copy link
Copy Markdown
Contributor Author

CodeFlow for GitHub does not download executable files. If you trust this file and would like to run it, please download it yourself through GitHub.

The general pattern is to use .onnx for a model and .pb for test input/expected output. As these are models .onnx seemed more appropriate (and provides a signal you could view it in something like netron if you wanted).


In reply to: 507772523 [](ancestors = 507772523)


Refers to: onnxruntime/test/testdata/optional_inputs_ir3.onnx:1 in f54e356. [](commit_id = f54e356, deletion_comment = False)

@ke1337

Copy link
Copy Markdown
Contributor

CodeFlow for GitHub does not download executable files. If you trust this file and would like to run it, please download it yourself through GitHub.

netron seems to treat both .pb and .onnx as onnx models. I think what you said is good to differentiate .onnx and .pb, for model and tensor separately. We may have a separate PR later to rename the .pb models in this folder.


In reply to: 507870064 [](ancestors = 507870064,507772523)


Refers to: onnxruntime/test/testdata/optional_inputs_ir3.onnx:1 in f54e356. [](commit_id = f54e356, deletion_comment = False)

@skottmckay

Copy link
Copy Markdown
Contributor Author

CodeFlow for GitHub does not download executable files. If you trust this file and would like to run it, please download it yourself through GitHub.

I'll go over them later today to cleanup in a separate PR


In reply to: 507903578 [](ancestors = 507903578,507870064,507772523)


Refers to: onnxruntime/test/testdata/optional_inputs_ir3.onnx:1 in f54e356. [](commit_id = f54e356, deletion_comment = False)

@ke1337 Ke Deng (ke1337) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@skottmckay
Scott McKay (skottmckay) merged commit 9d3b6b3 into master Jul 3, 2019
@skottmckay
Scott McKay (skottmckay) deleted the skottmckay/CleanupInitializerHandling branch July 3, 2019 08:43
Scott McKay (skottmckay) added a commit that referenced this pull request Sep 12, 2019
Description:

Disallow overriding an initializer via a graph input if the IR version is < 4. This enforces an implicit assumption that initializers should be treated as constant, and allows constant folding to be done on a model with an older IR version.
Separate constant and overridable initializers so that it's clear which ones constant folding can utilize.
Update Graph to not add all initializers to the graph inputs when the graph is manually created (i.e. not loaded from a GraphProto) and the IR version is >= 4.
Motivation and Context
In order to do constant folding we need to know which initializers can be treated as constant and which are overridable. All initializers were required to have a matching graph input prior to IR version 4, technically making all of them overridable. The intention however was for them to be treated as constants, and this change enforces that intent.

The benefit of doing so is that constant folding will work for models with IR version < 4. The cost is that if someone is actually overriding an initializer they will need to update the IR version of their model to version 4 in order to keep doing so. The belief is that this is a very small subset of usage (e.g. models involving feeding in a truncated sequence) and the cost to update that small subset is warranted by the benefit of constant folding being able to be enabled on all older models without them needing an IR version update.
Scott McKay (skottmckay) added a commit that referenced this pull request Sep 16, 2019
Description:

Disallow overriding an initializer via a graph input if the IR version is < 4. This enforces an implicit assumption that initializers should be treated as constant, and allows constant folding to be done on a model with an older IR version.
Separate constant and overridable initializers so that it's clear which ones constant folding can utilize.
Update Graph to not add all initializers to the graph inputs when the graph is manually created (i.e. not loaded from a GraphProto) and the IR version is >= 4.
Motivation and Context
In order to do constant folding we need to know which initializers can be treated as constant and which are overridable. All initializers were required to have a matching graph input prior to IR version 4, technically making all of them overridable. The intention however was for them to be treated as constants, and this change enforces that intent.

The benefit of doing so is that constant folding will work for models with IR version < 4. The cost is that if someone is actually overriding an initializer they will need to update the IR version of their model to version 4 in order to keep doing so. The belief is that this is a very small subset of usage (e.g. models involving feeding in a truncated sequence) and the cost to update that small subset is warranted by the benefit of constant folding being able to be enabled on all older models without them needing an IR version update.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants