mehrdadh commented on a change in pull request #9584:
URL: https://github.com/apache/tvm/pull/9584#discussion_r758661331
##########
File path: python/tvm/micro/project.py
##########
@@ -56,6 +56,17 @@ def read(self, n, timeout_sec):
return self._api_client.read_transport(n, timeout_sec)["data"]
+def prepare_options(received_options: dict, all_options: dict) -> dict:
Review comment:
Thanks for this suggestion. This could be a solution to this problem, my
only issue is that if project is able to find the projectOption and user also
wants to force it to use something else, this won't work. wdyt?
##########
File path: tests/micro/common/test_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import pytest
+import subprocess
+import shlex
+import sys
+import logging
+import tempfile
+import pathlib
+import sys
+import os
+
+import tvm
+from tvm.contrib.download import download_testdata
+from tvm.relay.backend import Executor, Runtime
+
+from ..zephyr.test_utils import ZEPHYR_BOARDS
+from ..arduino.test_utils import ARDUINO_BOARDS
+
+TVMC_COMMAND = [sys.executable, "-m", "tvm.driver.tvmc"]
+
+MODEL_URL =
"https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/micro_speech/micro_speech.tflite"
+MODEL_FILE = "micro_speech.tflite"
+
+
+def _run_tvmc(cmd_args: list, *args, **kwargs):
Review comment:
currently there's a bug for `tvmc micro` when I use this function. I
couldn't figure out the issue. I added a todo to replace this function and will
file an issue later.
We're trying to fix tvmc micro for nightly build before the conference, so I
suggest we have it as it is and change the test function in a follow up PR?
##########
File path: apps/microtvm/arduino/template_project/microtvm_api_server.py
##########
@@ -71,14 +71,15 @@ class BoardAutodetectFailed(Exception):
PROJECT_OPTIONS = [
server.ProjectOption(
"arduino_board",
- required=["build", "flash", "open_transport"],
+ required=["generate_project", "build", "flash", "open_transport"],
Review comment:
You're right, it's only required in Zephyr. Removed it.
##########
File path: apps/microtvm/arduino/template_project/microtvm_api_server.py
##########
@@ -71,14 +71,15 @@ class BoardAutodetectFailed(Exception):
PROJECT_OPTIONS = [
server.ProjectOption(
"arduino_board",
- required=["build", "flash", "open_transport"],
+ required=["generate_project", "build", "flash", "open_transport"],
choices=list(BOARD_PROPERTIES),
type="str",
help="Name of the Arduino board to build for.",
),
server.ProjectOption(
"arduino_cli_cmd",
- required=["build", "flash", "open_transport"],
+ optional=["build", "flash", "open_transport"],
Review comment:
shouldn't that be optional since it has default value?
##########
File path: apps/microtvm/arduino/template_project/microtvm_api_server.py
##########
@@ -248,7 +249,10 @@ def _convert_includes(self, project_dir, source_dir):
for ext in ("c", "h", "cpp"):
for filename in source_dir.rglob(f"*.{ext}"):
with filename.open() as file:
- lines = file.readlines()
+ try:
+ lines = file.readlines()
+ except:
Review comment:
I got this error:
```
The following error occured on the Project API server side:
calling method generate_project: JSON-RPC error # -32000: calling method
generate_project
Traceback (most recent call last):
File "/home/mhessar/tvm/python/tvm/micro/project_api/server.py", line 481,
in serve_one_request # <--- Outermost server-side stack frame
self._dispatch_request(request)
File "/home/mhessar/tvm/python/tvm/micro/project_api/server.py", line 593,
in _dispatch_request
return_value = dispatch_method(**params)
File "/home/mhessar/tvm/python/tvm/micro/project_api/server.py", line 625,
in _dispatch_generate_project
options,
File
"/home/mhessar/tvm/build/microtvm_template_projects/arduino/microtvm_api_server.py",
line 364, in generate_project
self._convert_includes(project_dir, source_dir)
File
"/home/mhessar/tvm/build/microtvm_template_projects/arduino/microtvm_api_server.py",
line 253, in _convert_includes
lines = file.readlines()
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 104:
ordinal not in range(128)
```
Not sure why we don't get this error on Arduino tests on CI and now we get
it using TVMC.
##########
File path: tests/micro/arduino/test_utils.py
##########
@@ -0,0 +1,101 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import json
+import pathlib
+import requests
+import datetime
+
+import tvm.micro
+import tvm.target.target
+from tvm.micro import project
+from tvm import relay
+from tvm.relay.backend import Executor, Runtime
+
+
+TEMPLATE_PROJECT_DIR =
pathlib.Path(tvm.micro.get_microtvm_template_projects("arduino"))
+
+BOARDS = TEMPLATE_PROJECT_DIR / "boards.json"
+
+
+def arduino_boards() -> dict:
+ """Returns a dict mapping board to target model"""
+ with open(BOARDS) as f:
+ board_properties = json.load(f)
+
+ boards_model = {board: info["model"] for board, info in
board_properties.items()}
+ return boards_model
+
+
+ARDUINO_BOARDS = arduino_boards()
+
+
+def make_workspace_dir(test_name, board):
+ filepath = pathlib.Path(__file__)
+ board_workspace = (
+ filepath.parent
+ / f"workspace_{test_name}_{board}"
+ / datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
+ )
+
+ number = 0
+ while board_workspace.exists():
+ number += 1
+ board_workspace = pathlib.Path(str(board_workspace) + f"-{number}")
+ board_workspace.parent.mkdir(exist_ok=True, parents=True)
+ t = tvm.contrib.utils.tempdir(board_workspace)
+ # time.sleep(200)
Review comment:
this was there from before, will remove it.
##########
File path: tests/micro/common/test_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import pytest
+import subprocess
+import shlex
+import sys
+import logging
+import tempfile
+import pathlib
+import sys
+import os
+
+import tvm
+from tvm.contrib.download import download_testdata
+from tvm.relay.backend import Executor, Runtime
+
+from ..zephyr.test_utils import ZEPHYR_BOARDS
+from ..arduino.test_utils import ARDUINO_BOARDS
+
+TVMC_COMMAND = [sys.executable, "-m", "tvm.driver.tvmc"]
+
+MODEL_URL =
"https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/micro_speech/micro_speech.tflite"
+MODEL_FILE = "micro_speech.tflite"
+
+
+def _run_tvmc(cmd_args: list, *args, **kwargs):
+ """Run a tvmc command and return the results"""
+ cmd_args_list = TVMC_COMMAND + cmd_args
+ cwd_str = "" if "cwd" not in kwargs else f" (in cwd: {kwargs['cwd']})"
+ logging.debug("run%s: %s", cwd_str, " ".join(shlex.quote(a) for a in
cmd_args_list))
+ return subprocess.check_call(cmd_args_list, *args, **kwargs)
+
+
+def _get_target_and_platform(board: str):
+ if board in ZEPHYR_BOARDS.keys():
+ target_model = ZEPHYR_BOARDS[board]
+ platform = "zephyr"
+ elif board in ARDUINO_BOARDS.keys():
+ target_model = ARDUINO_BOARDS[board]
+ platform = "arduino"
+ else:
+ raise ValueError(f"Board {board} is not supported.")
+
+ target = tvm.target.target.micro(target_model)
+ return str(target), platform
+
+
[email protected]_micro
+def test_tvmc_exist(board):
+ cmd_result = _run_tvmc(["micro", "-h"])
+ assert cmd_result == 0
+
+
[email protected]_micro
+def test_tvmc_model_build_only(board):
+ target, platform = _get_target_and_platform(board)
+
+ model_path = model_path = download_testdata(MODEL_URL, MODEL_FILE,
module="data")
+ temp_dir = pathlib.Path(tempfile.mkdtemp())
+ tar_path = str(temp_dir / "model.tar")
+ project_dir = str(temp_dir / "project")
+
+ runtime = str(Runtime("crt"))
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]