anijain2305 commented on a change in pull request #7613: URL: https://github.com/apache/tvm/pull/7613#discussion_r590766417
########## File path: src/relay/qnn/op/simulated_dequantize.cc ########## @@ -0,0 +1,80 @@ +/* + * 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 src/relay/qnn/op/simulated_dequantize.cc + * \brief QNN simulated dequantize operator. Mimics the behavior + * of QNN dequantize in floating point with added flexibility. + */ + +#include <tvm/relay/analysis.h> +#include <tvm/relay/op_attr_types.h> +#include <tvm/relay/qnn/attrs.h> + +#include "../../transforms/pattern_utils.h" +#include "../utils.h" + +namespace tvm { +namespace relay { +namespace qnn { + +bool SimulatedDequantizeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs, + const TypeReporter& reporter) { + // types = [data_type, datatype_type, scale_type, zp_type, ret_type] + ICHECK_EQ(types.size(), 5); + const auto* data = types[0].as<TensorTypeNode>(); + const auto* dtype = types[1].as<TensorTypeNode>(); + + if ((data == nullptr) || (dtype == nullptr)) { + return false; + } + + // assign output type + reporter->Assign(types[4], TensorType(data->shape, data->dtype)); Review comment: @mbrookhart are you talking about requantize operation? For your example of quantization of int32 -> int8, is the input a quantized tensor with scale and zero point, or just a plain int32 tensor. * If it is just a plain int32 tensor, should we even quantize it? From definition standpoint, the quantize (dequantize) has input (output) always as `float32` datatype. * However, if the input is a quantized integer representation, then you are doing a `requantize` operation (which in this case can be represented by a sequence of simulated_quantize - simulated_dequantize op). ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
