Skip to content

Commit c216cbe

Browse files
authored
[Bugfix] Fix qnn.quantize type func with incomplete type (#11124)
1 parent c8d2283 commit c216cbe

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/relay/qnn/op/quantize.cc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,23 @@ bool QuantizeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
5555
axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis;
5656

5757
// If zero point and scale are scalar then axis doesnt matter.
58-
bool scale_is_scalar = (types[1].as<TensorTypeNode>())->shape.size() == 0;
59-
bool zp_is_scalar = (types[2].as<TensorTypeNode>())->shape.size() == 0;
58+
bool scale_is_scalar, zp_is_scalar;
59+
60+
if (auto ttype = types[1].as<TensorTypeNode>()) {
61+
scale_is_scalar = ttype->shape.size() == 0;
62+
} else {
63+
ICHECK(types[1].as<IncompleteTypeNode>())
64+
<< "Quantize: expect to be TensorType but get " << types[1];
65+
return false;
66+
}
67+
68+
if (auto ttype = types[2].as<TensorTypeNode>()) {
69+
zp_is_scalar = ttype->shape.size() == 0;
70+
} else {
71+
ICHECK(types[2].as<IncompleteTypeNode>())
72+
<< "Quantize: expect to be TensorType but get " << types[2];
73+
return false;
74+
}
6075

6176
if (!(scale_is_scalar && zp_is_scalar)) {
6277
ICHECK_LT(axis, rank > 0 ? rank : 1) << "axis " << quantize_attrs->axis << " is out of range";

0 commit comments

Comments
 (0)