mehrdadh commented on a change in pull request #8715:
URL: https://github.com/apache/tvm/pull/8715#discussion_r688010083
##########
File path: tests/python/unittest/test_crt.py
##########
@@ -219,5 +219,109 @@ def test_platform_timer():
assert len(result.results) == 3
[email protected]_micro
+def test_autotune():
+ """Verify that autotune works with micro."""
+
+ RELAY_MODEL = """
+#[version = "0.0.5"]
+def @main(%data : Tensor[(1, 3, 64, 64), uint8], %weight : Tensor[(8, 3, 5,
5), int8]) {
+ %1 = nn.conv2d(
+ %data,
+ %weight,
+ padding=[2, 2],
+ channels=8,
+ kernel_size=[5, 5],
+ data_layout="NCHW",
+ kernel_layout="OIHW",
+ out_dtype="int32");
+ %1
+}
+"""
+ mod = tvm.parser.fromtext(RELAY_MODEL)
Review comment:
done.
##########
File path: tests/micro/zephyr/test_zephyr.py
##########
@@ -400,5 +396,137 @@ def test_tensors(sess):
test_tensors(sess)
+def _get_conv2d_model(input_shape: tuple):
+ """Build a conv2d operator in Keras and returns an (IRModule,
parameters)"""
+ import tensorflow as tf
+ from tensorflow import keras
+
+ model = keras.models.Sequential()
+ model.add(keras.layers.Conv2D(2, 3, input_shape=input_shape))
+ model.build()
+
+ inputs = {
+ i.name.split(":", 2)[0]: [x if x is not None else 1 for x in
i.shape.as_list()]
+ for i in model.inputs
+ }
+ inputs = {k: [v[0], v[3], v[1], v[2]] for k, v in inputs.items()}
+ mod, params = relay.frontend.from_keras(model, inputs, layout="NCHW")
+ return mod, params
+
+
[email protected]_micro
+def test_autotune_conv2d(temp_dir, platform, west_cmd, tvm_debug):
+ """Test AutoTune for microTVM Zephyr"""
+ model, zephyr_board = PLATFORMS[platform]
+
+ sample = np.random.rand(1, 3, 16, 16)
+ mod, params = _get_conv2d_model((16, 16, 3))
+
+ target = tvm.target.target.micro(model)
+ pass_context = tvm.transform.PassContext(opt_level=3,
config={"tir.disable_vectorize": True})
+ with pass_context:
+ tasks = tvm.autotvm.task.extract_from_program(mod["main"], {}, target)
+ assert len(tasks) > 0
+
+ repo_root = pathlib.Path(
+ subprocess.check_output(["git", "rev-parse", "--show-toplevel"],
encoding="utf-8").strip()
+ )
+ module_loader = tvm.micro.autotvm_module_loader(
+ template_project_dir=repo_root / "apps" / "microtvm" / "zephyr" /
"template_project",
+ project_options={
+ "zephyr_board": zephyr_board,
+ "west_cmd": west_cmd,
+ "verbose": 1,
+ "project_type": "host_driven",
+ },
+ )
+ builder = tvm.autotvm.LocalBuilder(
+ n_parallel=1,
+ build_kwargs={"build_option": {"tir.disable_vectorize": True}},
+ do_fork=False,
+ build_func=tvm.micro.autotvm_build_func,
+ ) # do_fork=False needed to persist stateful builder.
+ runner = tvm.autotvm.LocalRunner(number=1, repeat=1, timeout=0,
module_loader=module_loader)
+
+ measure_option = tvm.autotvm.measure_option(builder=builder, runner=runner)
+
+ log_path = pathlib.Path("zephyr_autotune.log")
+ if log_path.exists():
+ log_path.unlink()
+
+ n_trial = 10
+ for task in tasks:
+ print(f"mehrdad: {task}")
Review comment:
done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]