Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow overriding initializers if IR version < 4 #1324

Merged
merged 4 commits into from
Jul 3, 2019

Conversation

skottmckay
Copy link
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.

@skottmckay skottmckay requested a review from a team as a code owner July 1, 2019 12:09
@skottmckay skottmckay requested a review from linkerzhang July 1, 2019 12:10
@ke1337
Copy link
Contributor

ke1337 commented Jul 2, 2019

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)

@skottmckay
Copy link
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
Contributor

ke1337 commented Jul 3, 2019

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
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)

Copy link
Contributor

@ke1337 ke1337 left a comment

Choose a reason for hiding this comment

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

:shipit:

@skottmckay skottmckay merged commit 9d3b6b3 into master Jul 3, 2019
@skottmckay skottmckay deleted the skottmckay/CleanupInitializerHandling branch July 3, 2019 08:43
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.
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