diff --git a/src/relay/qnn/op/quantize.cc b/src/relay/qnn/op/quantize.cc index 1a4c853d8929..e8f2e98d7394 100644 --- a/src/relay/qnn/op/quantize.cc +++ b/src/relay/qnn/op/quantize.cc @@ -55,8 +55,23 @@ bool QuantizeRel(const Array& types, int num_inputs, const Attrs& attrs, axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis; // If zero point and scale are scalar then axis doesnt matter. - bool scale_is_scalar = (types[1].as())->shape.size() == 0; - bool zp_is_scalar = (types[2].as())->shape.size() == 0; + bool scale_is_scalar, zp_is_scalar; + + if (auto ttype = types[1].as()) { + scale_is_scalar = ttype->shape.size() == 0; + } else { + ICHECK(types[1].as()) + << "Quantize: expect to be TensorType but get " << types[1]; + return false; + } + + if (auto ttype = types[2].as()) { + zp_is_scalar = ttype->shape.size() == 0; + } else { + ICHECK(types[2].as()) + << "Quantize: expect to be TensorType but get " << types[2]; + return false; + } if (!(scale_is_scalar && zp_is_scalar)) { ICHECK_LT(axis, rank > 0 ? rank : 1) << "axis " << quantize_attrs->axis << " is out of range";