-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Add a contrib operator for Constant #15993
base: master
Are you sure you want to change the base?
Conversation
@mxnet-label-bot add [Operator, pr-awaiting-review, ONNX] |
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.
For performance optimization purpose, I think it's better to have constant
against with variable
. Make constant
as a operator is an option, but the question is, how to set the value for it? Especially when the value is not a broad casted value.
One of the main reasons for adding this as an operator was for ONNX conversion. I tried blockgrad with constant initializer - but it dint convert well. |
executor = constant_op.simple_bind(ctx=cpu()) | ||
executor.forward(is_train=True) | ||
executor.outputs | ||
[ -1. 2.] |
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.
Here's the most confusing part. I assume v1 is the shape of constant output, but where to specify the output value? On the other words, why the output is [-1, 2]?
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.
v1 is the value we want to store. since this operator is a constant, the output is equal to the input ([-1,2])
I mean, If we did some constant folding optimization in the graph, and generate a new tensor which is not filled with same values. For example,
For this code, that scale multiply will execute many times during each iteration of inference. Because weight and scale are all constant, so we can fold them before inference, and use a constant node to replace the folded result in the graph. The value holding by constant node is vary, which can't be generated with simple pattern. |
can you reference this issue in the PR description - #6087 |
0d56c81
to
c06d1db
Compare
@ZhennanQin which operator is currently used in this scenario? |
Description
MXNet doesn't have a constant op for sym API (similar to gluon.constant). The closest is to map it to BlockGrad as discussed in #6087. It would be useful to have a constant operator in general, and it is also required to convert Pytorch models to MXNet through ONNX.
Adding support for this operator here.
Checklist
Essentials
Please feel free to remove inapplicable items for your PR.
Changes
Comments