Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relay][Topi] Disable conv NHWC pack int8. #4038

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/python/relay/test_backend_compile_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
15 changes: 9 additions & 6 deletions topi/python/topi/x86/conv2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down