-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
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"); |
There was a problem hiding this comment.
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");
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).