From 41cef56857200b4bd8d0ea600e0ee1822db8b827 Mon Sep 17 00:00:00 2001 From: anwang2009 Date: Wed, 8 Sep 2021 22:57:25 -0700 Subject: [PATCH] [ONNX] Support depth_to_space op for FQ2I (#8966) * WIP support per-channel quantization * more WIP * More WIP * fix issue with per-channel bias_add * Fix fake quantize tests (#4) * Fixed fake quantize issues. * Formatting. * Cleanup unused imports * Fix real int8 tests. * Add Relu * One more little one (#5) * Fixed fake quantize issues. * Formatting. * Cleanup unused imports * Fix real int8 tests. * Fix requantize shape bug. * Non-working Per-channel Dense * Fix legalization for non spatial operators. (#6) * Fix legalization for non spatial operators. * Fix axis checks for end2end functionality. * fix axis normalization fix lint fix lint again * Per channel fq2i (#8) * WIP support per-channel quantization * more WIP * More WIP * fix issue with per-channel bias_add * Fix fake quantize tests (#4) * Fixed fake quantize issues. * Formatting. * Cleanup unused imports * Fix real int8 tests. * Add Relu * One more little one (#5) * Fixed fake quantize issues. * Formatting. * Cleanup unused imports * Fix real int8 tests. * Fix requantize shape bug. * Non-working Per-channel Dense * Fix legalization for non spatial operators. (#6) * Fix legalization for non spatial operators. * Fix axis checks for end2end functionality. * fix axis normalization fix lint fix lint again * Fix bug in requantize dimension expansion. * Format. Co-authored-by: Josh Fromm * respond to review comments * start dtos * wip depth_to_space * dtos ident Co-authored-by: Matthew Co-authored-by: Josh Fromm --- .../relay/transform/fake_quantization_to_integer.py | 1 + .../relay/test_pass_fake_quantization_to_integer.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/python/tvm/relay/transform/fake_quantization_to_integer.py b/python/tvm/relay/transform/fake_quantization_to_integer.py index 6032dbf92dbc..0ed75191c40d 100644 --- a/python/tvm/relay/transform/fake_quantization_to_integer.py +++ b/python/tvm/relay/transform/fake_quantization_to_integer.py @@ -87,6 +87,7 @@ def identity(expr, type_map): register_unary_identity("expand_dims") register_unary_identity("nn.max_pool2d") register_unary_identity("nn.batch_flatten") +register_unary_identity("nn.depth_to_space") @register_fake_quantization_to_integer("nn.avg_pool2d") diff --git a/tests/python/relay/test_pass_fake_quantization_to_integer.py b/tests/python/relay/test_pass_fake_quantization_to_integer.py index 7ede17d07d99..3680310b4f92 100644 --- a/tests/python/relay/test_pass_fake_quantization_to_integer.py +++ b/tests/python/relay/test_pass_fake_quantization_to_integer.py @@ -501,3 +501,16 @@ def test_fake_quantize_pad(): x_np = np.random.randint(-25, 25, size=[1, 383, 128], dtype="int8") compare_fq_to_int(op, [x_np]) + + +def test_fake_quantize_depth_to_space(): + x = relay.var("x", shape=[1, 3, 224, 224], dtype="int8") + + zero = relay.const(0) + x = relay.qnn.op.dequantize(x, relay.const(2.0), zero) + op = relay.op.nn.depth_to_space(x, 4) + op = relay.qnn.op.quantize(op, relay.const(2.0), zero) + + x_np = np.random.randint(-128, 127, size=[1, 3, 224, 224], dtype="int8") + + compare_fq_to_int(op, [x_np])