Skip to content

Commit

Permalink
fix a typo in a branch and add a test that hits it
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew committed Jul 27, 2021
1 parent 4017c89 commit 4e307d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/tvm/relay/transform/fake_quantization_to_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def bias_add(expr, type_map):
b_t.zero_point,
in_scale,
in_zero_point,
out_dtype=xt.dtype,
out_dtype=x_t.dtype,
)
out = relay.op.nn.bias_add(x, b, **expr.attrs)
return [out, x_t]
Expand Down
21 changes: 21 additions & 0 deletions tests/python/relay/test_pass_fake_quantization_to_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ def test_fake_transpose_quantize_conv_bias_add():
compare_fq_to_int(op, [x_np, w_np, bias_np])


def test_fake_transpose_quantize_conv_bias_add_mismatch():
x = relay.var("x", shape=[1, 224, 224, 3], dtype="int8")
w = relay.var("w", shape=[16, 3, 5, 5], dtype="int8")
bias = relay.var("bias", shape=[16], dtype="int32")
one = relay.const(1.0)
two = relay.const(2.0)
zero = relay.const(0)

x = relay.qnn.op.dequantize(x, relay.const(2.0), zero)
x = relay.transpose(x, [0, 3, 1, 2])
op = relay.op.nn.conv2d(x, relay.qnn.op.dequantize(w, relay.const(0.5), zero))
op = relay.op.nn.bias_add(op, relay.qnn.op.dequantize(bias, two, zero))
op = relay.qnn.op.quantize(op, one, zero)

x_np = np.random.randint(-128, 127, size=[1, 224, 224, 3], dtype="int8")
w_np = np.random.randint(-128, 127, size=[16, 3, 5, 5], dtype="int8")
bias_np = np.random.randint(-32768, 32767, size=[16], dtype="int32")

compare_fq_to_int(op, [x_np, w_np, bias_np])


def test_fake_quantize_maxpool():
x = relay.var("x", shape=[1, 3, 224, 224], dtype="int8")

Expand Down

0 comments on commit 4e307d4

Please sign in to comment.