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

Allow the creation of ONNX initializers #965

Merged
merged 9 commits into from
Oct 2, 2018

Conversation

wschin
Copy link
Member

@wschin wschin commented Sep 20, 2018

Related issue: #958.
This PR provides an ability of adding tensors into the initializer list of ONNX model. It may help the conversion of neural network based transforms and transforms which can be decomposed into matrix operators (some constant matrices would be saved as initializers).

@wschin wschin self-assigned this Sep 20, 2018
@wschin wschin added the enhancement New feature or request label Sep 20, 2018
@wschin wschin requested a review from jignparm September 20, 2018 16:33
@wschin wschin changed the title Addinitializer Allow the creation of ONNX initializers Sep 20, 2018
@markusweimer
Copy link
Member

This PR does not reference an issue. Can you please file one and reference it in the PR description?


// Use implementation as in the actual conversion code
var ctx = ctxImpl as OnnxContext;
ctx.AddInitializer(9.4f, "float");
Copy link
Contributor

Choose a reason for hiding this comment

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

ctx.AddInitializer(9.4f, "float"); [](start = 16, length = 34)

var floatScalar = ctx.AddInitializer(9.4f, "float");

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do we need this?

Copy link
Contributor

Choose a reason for hiding this comment

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

it's better than do
var floatScalar = model.Graph.Initializer[0];

If someone decide to change this test, and add one more initializer in the beginning, it will break tests.


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

Copy link
Member Author

@wschin wschin Sep 26, 2018

Choose a reason for hiding this comment

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

ctx.AddInitializer returns the ONNX name of a tensor, not the actual ONNX object.
In addition, the test aims at examining the generated ONNX objects under the real scenario. Getting information before finishing the conversion is not ideal because it means we are checking an intermediate state of a conversion instead of the final state we care the most.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use that name of tensor to access initializer instead of model.Graph.Initalizer[0]?
If yes, i would suggest to use names instead of index.
If no, I find it strange, but i'm ok with current code.


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

@codemzs codemzs requested a review from TomFinley October 2, 2018 16:19
@@ -349,5 +352,77 @@ public ModelArgs(string name, TensorProto.Types.DataType dataType, List<long> di

return new ModelArgs(name, dataType, dimsLocal, dimsParamLocal);
}

// Make long scalar in ONNX from native C# number
public static TensorProto MakeInt64(string name, long value)
Copy link
Member

Choose a reason for hiding this comment

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

(string name, long value) [](start = 43, length = 25)

Can you please add checks? See how above functions do checks. Same for below.

Copy link
Member

@codemzs codemzs left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@Ivanidzo4ka Ivanidzo4ka left a comment

Choose a reason for hiding this comment

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

:shipit:

@vaeksare vaeksare merged commit ff85a5c into dotnet:master Oct 2, 2018
@wschin wschin deleted the addinitializer branch October 8, 2018 16:55
@ghost ghost locked as resolved and limited conversation to collaborators Mar 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants