-
Notifications
You must be signed in to change notification settings - Fork 2.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
Support fusing 3D Conv with Add/Mul. #23
Conversation
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.
continue; | ||
} | ||
conv_B = std::make_unique<Initializer>(conv_B_tensor_proto); | ||
} | ||
|
||
// Calculate new value of initializers of conv node | ||
conv_W->scale_by_axis(*mul_B, 1); | ||
// Caculate new value of initializers of conv node |
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.
Caculate->Calculate
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.
Good catch. Thanks!
conv_W_tensor_proto->dims_size() < 4 || | ||
!(mul_B_tensor_proto->dims_size() == 0 || | ||
(mul_B_tensor_proto->dims_size() == conv_W_tensor_proto->dims_size() - 1 && | ||
conv_W_tensor_proto->dims(0) == mul_B_tensor_proto->dims(0)))) { |
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.
Does this have the same problem as the conv_add_fusion where the other dims of the multiplier should be 1?
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.
Yeah, it is better to check it.
if (conv_B->size() != add_B->size()) { | ||
continue; | ||
} | ||
// Caculate new value of initializers of conv node |
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.
Caculate->Calculate
onnxruntime/core/graph/initializer.h
Outdated
@@ -255,13 +255,13 @@ class Initializer final { | |||
switch (data_type_) { | |||
case ONNX_NAMESPACE::TensorProto_DataType_FLOAT: { | |||
for (int i = 0; i < size_; i++) { | |||
data<float>()[i] *= other.data<float>()[i]; | |||
data<float>()[i] *= other.data<float>()[other.size() == 1 ? 0 : i]; |
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.
These helpers are a little weird with the broadcasting rules. mul now behaves different than add/sub/etc. Maybe just have a scale_by_scalar to handle the case for now?
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.
Agree. The PR is updated. Please review it! Thanks!
ca5452a
to
66f89ce
Compare
With this PR, the subgraph 3D Conve->Add->Mul in Resnet3D can be fused into one 3D Conv.
4ac0998
to
5f87427
Compare
|
@weixingzhang its good for merge now |
…obuf_status Create a mapping from ONNX Runtime Status to Protobuf Status
With this PR, the subgraph 3D Conve->Add->Mul in Resnet3D can be fused into one 3D Conv.