Skip to content

Commit 9eb0a1c

Browse files
author
Matthew
committed
fix axis normalization
1 parent f67c38a commit 9eb0a1c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/relay/qnn/op/dequantize.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ bool DequantizeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
5454
const auto* dequantize_attrs = attrs.as<DequantizeAttrs>();
5555
int axis = dequantize_attrs->axis;
5656
auto rank = static_cast<int>(data->shape.size());
57+
axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis;
5758

5859
// If zero point and scale are scalar then axis doesnt matter.
5960
bool scale_is_scalar = (types[1].as<TensorTypeNode>())->shape.size() == 0;
6061
bool zp_is_scalar = (types[2].as<TensorTypeNode>())->shape.size() == 0;
6162

6263
if (!(scale_is_scalar && zp_is_scalar)) {
63-
axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis;
6464
ICHECK_LT(axis, rank > 0 ? rank : 1) << "axis " << dequantize_attrs->axis << " is out of range";
6565
ICHECK_GE(axis, 0) << "axis " << dequantize_attrs->axis << " is out of range";
6666
}

src/relay/qnn/op/quantize.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ bool QuantizeRel(const Array<Type>& types, int num_inputs, const Attrs& attrs,
5252
const auto* quantize_attrs = attrs.as<QuantizeAttrs>();
5353
int axis = quantize_attrs->axis;
5454
auto rank = static_cast<int>(data->shape.size());
55+
axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis;
5556

5657
// If zero point and scale are scalar then axis doesnt matter.
5758
bool scale_is_scalar = (types[1].as<TensorTypeNode>())->shape.size() == 0;
5859
bool zp_is_scalar = (types[2].as<TensorTypeNode>())->shape.size() == 0;
5960

6061
if (!(scale_is_scalar && zp_is_scalar)) {
61-
axis = (axis < 0) ? ((rank > 0) ? data->shape.size() + axis : 0) : axis;
6262
ICHECK_LT(axis, rank > 0 ? rank : 1) << "axis " << quantize_attrs->axis << " is out of range";
6363
ICHECK_GE(axis, 0) << "axis " << quantize_attrs->axis << " is out of range";
6464
}

0 commit comments

Comments
 (0)