bgawrych commented on a change in pull request #20817: URL: https://github.com/apache/incubator-mxnet/pull/20817#discussion_r804426557
########## File path: src/operator/quantization/dnnl/dnnl_quantized_transpose.cc ########## @@ -0,0 +1,93 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * \file dnnl_quantized_transpose.cc + * \author: Rafal Litka, [email protected] + */ +#if MXNET_USE_ONEDNN == 1 +#include "../../nn/dnnl/dnnl_transpose-inl.h" +#include "../../tensor/matrix_op-inl.h" + +namespace mxnet { +namespace op { + +inline static bool QuantizedTransposeStorageType(const nnvm::NodeAttrs& attrs, + const int dev_mask, + DispatchMode* dispatch_mode, + std::vector<int>* in_attrs, + std::vector<int>* out_attrs) { + CHECK_EQ(in_attrs->size(), 3U); + CHECK_EQ(out_attrs->size(), 3U); + return DNNLStorageType(attrs, dev_mask, true, dispatch_mode, in_attrs, out_attrs); +} + +bool SupportDNNLQuantizedTranspose(const NDArray& data) { + auto data_ndim = data.shape().ndim(); + + if (data_ndim > 4 || data_ndim == 0 || data.shape().Size() == 0) + return false; + + return true; +} +template<class ParamType> +static void DNNLQuantizedTransposeForward(const nnvm::NodeAttrs& attrs, + const OpContext& ctx, + const std::vector<NDArray>& inputs, + const std::vector<OpReqType>& req, + const std::vector<NDArray>& outputs) { + CHECK(inputs[0].dtype() == mshadow::kUint8 || inputs[0].dtype() == mshadow::kInt8) + << "dnnl_quantized_transpose only supports uint8 and int8 as input type"; + if (req[0] == kNullOp) { + return; + } + CHECK_EQ(inputs.size(), 3U); + CHECK_EQ(outputs.size(), 3U); + if (SupportDNNLQuantizedTranspose(inputs[0])) { + DNNLRun(DNNLTransposeForward<ParamType>, attrs, ctx, inputs[0], req[0], outputs[0]); + } else { + FallBackCompute(UnaryOp::IdentityCompute<cpu>, attrs, ctx, inputs, req, outputs); Review comment: Why it is fallback to IdentityCompute - I think it should be fallback to NumpyTranspose<cpu> / Transpose<cpu> ########## File path: tests/python/dnnl/subgraphs/test_conv_subgraph.py ########## @@ -72,6 +72,26 @@ def forward(self, x): net = Conv() check_fusion(net, data_shape, attr) [email protected]_np [email protected]('data_shape', DATA_SHAPE) [email protected]('use_bias', [True, False]) +def test_conv_transpose_conv(use_bias, data_shape): + + class Conv_Transpose_Conv(nn.HybridBlock): + def __init__(self, **kwargs): + super(Conv_Transpose_Conv, self).__init__(**kwargs) + self.conv0 = nn.Conv2D(channels=64, kernel_size=(3, 3), strides=1, use_bias=use_bias) + self.conv1 = nn.Conv2D(channels=32, kernel_size=(5, 5), strides=1, use_bias=use_bias) + + def forward(self, x): + out = self.conv0(x) + out = mx.np.transpose(out, axes=[0,1,3,2]) + out = self.conv1(out) + return out + + attr = {'conv': []} + net = Conv_Transpose_Conv() + check_fusion(net, data_shape, attr) Review comment: I think in this case check_quantize call should be used - probably you can check if transpose was quantized by adding it's name to attr dict -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
