diff --git a/python/tvm/autotvm/task/relay_integration.py b/python/tvm/autotvm/task/relay_integration.py index 11f40ed62756..c5e7694017a1 100644 --- a/python/tvm/autotvm/task/relay_integration.py +++ b/python/tvm/autotvm/task/relay_integration.py @@ -130,6 +130,10 @@ def extract_from_multiple_program(mods, params, target, target_host=None, ops=No assert isinstance( mod, tvm.IRModule ), "only support relay Module or Function to be tuned" + + with target: + mod = tvm.relay.transform.AlterOpLayout()(mod) + relay.backend.te_compiler.get().clear() # wrap build call in thread to avoid multiprocessing problems build_thread = threading.Thread(target=_lower, args=(mod, target, param)) diff --git a/tests/python/relay/test_autotvm_task_extraction.py b/tests/python/relay/test_autotvm_task_extraction.py index 83480a044f45..7092d71849b5 100644 --- a/tests/python/relay/test_autotvm_task_extraction.py +++ b/tests/python/relay/test_autotvm_task_extraction.py @@ -122,6 +122,22 @@ def get_net(batch, in_dim, out_dim, dtype, out_dtype): assert len(tasks) == 1 and tasks[0].name == "dense_int8.cuda" +def test_task_extraction_for_dense_int8_vnni(): + target = "llvm -mcpu=cascadelake" + + def get_net(batch, in_dim, out_dim, dtype_input, dtype_weight, out_dtype): + data = tvm.relay.var("data", shape=[batch, in_dim], dtype=dtype_input) + weight = tvm.relay.var("weight", shape=[out_dim, in_dim], dtype=dtype_weight) + out = relay.nn.dense(data, weight, out_dtype=out_dtype) + mod, params = relay.testing.create_workload(out) + return mod, params + + mod, params = get_net(1, 16, 32, "uint8", "int8", "int32") + tasks = autotvm.task.extract_from_program(mod, target=target, params=params) + assert len(tasks) == 1 and tasks[0].name == "dense_vnni.x86" + + if __name__ == "__main__": test_task_extraction() test_task_extraction_for_dense_int8_cuda() + test_task_extraction_for_dense_int8_vnni()