-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[RELAY][PASS] FoldScaleAxis Backward #2024
Conversation
@jroesch @ZihengJiang @yzhliu @zhiics @FrozenGene @merrymercy @srkreddy1238 @masahi please review |
call->args[1]->type_as<TensorTypeNode>()->shape, | ||
weight_layout, kOIHW); | ||
return is_const_int(wshape[0], param->groups) && | ||
is_const_int(wshape[1], 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.
Could we use is_const_int(wshape[0], param->groups)
to check depthwise convolution? In theory, wshape[1] could be not equal to 1, although TF / MXNet / Caffe and so on frontends will make it be 1 even though the depth channel multiplier not be 1 (such as 0.25)
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.
The current code makes the assumption of input and output groups being even, and the special logic relies on this
A better approach would enhance the Conv2D code itself to handle general group convolution, which should not be too hard as a followup contribution from anyone in the community:)
return CallNode::make(call->op, {input}, call->attrs, call->type_args); | ||
} | ||
|
||
RELAY_REGISTER_OP("nn.relu") |
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.
How about add clip
operator like relu
? Like Tensorflow frontend or Keras frontend, which use clip
to implement relu6
operator.
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.
clip can be supported, this PR mainly introduces the scaffolding of things necessary, with new folder infrastructure, we can support clip as well as other operators(flatten, transpose) by more registrations
src/relay/pass/fold_scale_axis.cc
Outdated
// - Prepare phase: backward propagation of demand. | ||
// - Transform phase: forward transformation, | ||
// | ||
// Similarly, borward folding process is done in two steps: |
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.
backward
class BackwardTransformer; | ||
|
||
/*! | ||
* \brief Preparation function for for pass scale backward. |
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
Thanks, @masahi @FrozenGene I have updated the PR according to your comments |
Thanks @FrozenGene @masahi , this is merged. Followup PRs to support more ops(clip) and grouped conv is more than welcomed! |
This is a followup of #2020 , this PR implemented the infrastructure to do backward folding of scale on axis.
Goal
Fold the scaling of axis(usually caused by BatchNorm) into weight of conv2d in the past. For example
Old:
Transformed:
Further constant folding can fold the multiplication and we remove the scaling in the network.
The Algorithm
The general idea is similar to the Forward algorithm. We pass additional argument
(axes, scale)
, when doing transformation, to request the result to satisfyThe problem is again we don;t want to blindly propagate scale backward it won't get consumed. So we run a forward "preparation phase", which propagates the demand of the potential axes scaling.
The new pass is more general than the FoldScaleAxis in nnvm