From d7fd677e64131d278e753d0ba0c6ee57e78b41c5 Mon Sep 17 00:00:00 2001 From: Animesh Jain Date: Mon, 30 Sep 2019 22:26:46 +0000 Subject: [PATCH] [Relay][Topi] Disable conv NHWC pack int8. --- .../python/relay/test_backend_compile_engine.py | 16 ++++++++++++++++ topi/python/topi/x86/conv2d.py | 15 +++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/python/relay/test_backend_compile_engine.py b/tests/python/relay/test_backend_compile_engine.py index b1f41a43148c..43090eea15f0 100644 --- a/tests/python/relay/test_backend_compile_engine.py +++ b/tests/python/relay/test_backend_compile_engine.py @@ -93,9 +93,25 @@ def test_compile_full(): relay.build(mod, 'llvm') +def test_compile_nhwc_pack(): + data = relay.var("data", shape=(1, 1, 1, 1024), dtype="uint8") + weight = relay.var("weight", shape=(1, 1, 1024, 1001), dtype="int8") + p2 = relay.var("p2", shape=(1, 1, 1, 1), dtype="int32") + conv = relay.nn.conv2d(data, weight, kernel_size=(1, 1), data_layout="NHWC", + kernel_layout="HWIO", out_dtype="int32") + multiply = relay.multiply(relay.const(-22, dtype='int32'), p2) + tile = relay.tile(multiply, reps=(1, 1, 1, 1001)) + subtract = relay.subtract(conv, tile) + + func = subtract + mod = relay.Function(relay.analysis.free_vars(func), func) + relay.build(mod, target="llvm") + + if __name__ == "__main__": test_compile_engine() test_compile_placeholder_bypass() test_compile_injective_with_tuple() test_compile_tuple_dup() test_compile_full() + test_compile_nhwc_pack() diff --git a/topi/python/topi/x86/conv2d.py b/topi/python/topi/x86/conv2d.py index e7c57e049a7c..925cb37d9e47 100644 --- a/topi/python/topi/x86/conv2d.py +++ b/topi/python/topi/x86/conv2d.py @@ -110,12 +110,15 @@ def _declaration_conv(cfg, data, kernel, strides, padding, dilation, layout, out kh, kw, _, _ = get_const_tuple(kernel.shape) if layout == 'HWCN': return nn.conv2d_hwcn(data, kernel, strides, padding, dilation, out_dtype) - elif layout == 'NHWC' and kh == 1 and kw == 1 and kernel.dtype == "int8": - if cfg.is_fallback: - _get_default_config(cfg, data, kernel, strides, padding, out_dtype, False, layout) - # specialize for INT8 1X1 conv on X86 - return conv2d_avx_1x1._declaration_conv_nhwc_pack(cfg, data, kernel, strides, - padding, dilation, out_dtype) + # FIXME - https://github.com/dmlc/tvm/issues/4122 + # _declaration_conv_nhwc_pack expects kernel layout to be HWOI. However, the tests use HWIO + # layout. Commenting until we have clarity about the nhwc_pack implementation from the author. + # elif layout == 'NHWC' and kh == 1 and kw == 1 and kernel.dtype == "int8": + # if cfg.is_fallback: + # _get_default_config(cfg, data, kernel, strides, padding, out_dtype, False, layout) + # # specialize for INT8 1X1 conv on X86 + # return conv2d_avx_1x1._declaration_conv_nhwc_pack(cfg, data, kernel, strides, + # padding, dilation, out_dtype) elif layout == 'NHWC': return nn.conv2d_nhwc(data, kernel, strides, padding, dilation, out_dtype) raise ValueError("not support this layout {} yet".format(layout))