-
Notifications
You must be signed in to change notification settings - Fork 341
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
Decompose DepthToSpace operator. #910
Conversation
Signed-off-by: Ettore Tiotto <[email protected]>
@etiotto It seems DepthToSpace needs input shape to be rewritten. In such a case, Could you please enable end-to-end tests for DepthToSpace in |
Signed-off-by: Ettore Tiotto <[email protected]>
@tungld thanks for the code review. I have implemented the canonicalization code in |
@etiotto |
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.
Please comment on the source of all the changes in the ONNXOps.td.inc, as it is a auto-generated file.
@@ -821,7 +821,7 @@ def ONNXConvTransposeOp:ONNX_Op<"ConvTranspose", | |||
"output_shape can also be explicitly specified in which case pads values are auto generated using these equations:" | |||
"" | |||
" total_padding[i] = stride[i] * (input_size[i] - 1) + output_padding[i] + ((kernel_shape[i] - 1) * dilations[i] + 1) - output_shape[i]" | |||
" If (auto_pads != SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/2)" | |||
" If (auto_pads == SAME_UPPER): pads[start_i] = total_padding[i]/2; pads[end_i] = total_padding[i] - (total_padding[i]/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.
Could you comment on the source of all these text changes in the ONNXOPS.td.inc?
@@ -353,7 +353,7 @@ | |||
OpsWithCanonicalizer = ['Add', 'Constant', 'Identity', 'Cast', 'Transpose', | |||
'Dropout', 'Shape', 'Size', 'GlobalAveragePool', | |||
'GlobalMaxPool', 'SqueezeV11', 'UnsqueezeV11', | |||
'Squeeze', 'Unsqueeze', 'Reshape'] | |||
'Squeeze', 'Unsqueeze', 'Reshape', 'DepthToSpace'] |
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.
Nit, if you put down new code, would be good to alphabetize this list.
@etiotto Is the PR still needed? I see it having conflict, failure. Please close or update. |
This approach is no longer needed. The DepthToSpace operator has been implemented via the other PRs associated with work item #927. Closing. |
// Canonicalization for ONNXDepthToSpaceOp | ||
// Rewrite: | ||
// output = onnx.depthToSpace(x, bs, mode=[DCR|CRD]) | ||
// [B, C, H, W] = x.shape |
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.
What if x has known dim (-1)?
It seems to me that we can have two rules for different mode.
For mode==DCR, the rule can be (not precisely) written as following to handle non constant shape with just rule. Doable?
def DecomposeDepthToSpacePattern : Pat<`
((ONNXDepthToSpaceOp:$res $x, $bsAttr, $modeAttr),
((ONNXShape:$shape $x),
(ONNXConcat:$newshape (ONNXClip $shape 0),
(ONNXConstant $bsAttr),
(ONNXConstant $bsAttr),
(ONNXDiv (ONNXClip $shape 1), Constant($bsAttr*$bsAttr)),
(ONNXClip $shape 2),
(ONNXClip $shape 3)),
ONNXReshape $x $newShape)
[($modeAttr == "DCR")]>
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.
@etiotto should we reopen this PR to avoid lowering DepthToSpace to krnl?
Currently we lower There are 2 cases to consider, when all dimensions of the shape for I think the current approach is reasonable. It allows reuse of the code we already have to lower |
This PR decomposes the ONNX DepthToSpace operator into reshape+transpose+reshape as documented by https://github.com/onnx/onnx/blob/master/docs/Operators.md#DepthToSpace