Skip to content
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
11 changes: 10 additions & 1 deletion python/tvm/driver/tvmc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=redefined-builtin
# pylint: disable=redefined-builtin,wrong-import-position
"""
TVMC - TVM driver command-line interface
"""


class TVMCException(Exception):
"""TVMC Exception"""


class TVMCImportError(TVMCException):
"""TVMC TVMCImportError"""


from . import micro
from . import runner
from . import autotuner
Expand Down
52 changes: 52 additions & 0 deletions python/tvm/driver/tvmc/arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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.
"""
TVMC Argument Parsing
"""

import argparse

from tvm.driver.tvmc import TVMCException


class TVMCSuppressedArgumentParser(argparse.ArgumentParser):
"""
A silent ArgumentParser class.
This class is meant to be used as a helper for creating dynamic parsers in
TVMC. It will create a "supressed" parser based on an existing one (parent)
which does not include a help message, does not print a usage message (even
when -h or --help is passed) and does not exit on invalid choice parse
errors but rather throws a TVMCException so it can be handled and the
dynamic parser construction is not interrupted prematurely.
"""

def __init__(self, parent, **kwargs):
# Don't add '-h' or '--help' options to the newly created parser. Don't print usage message.
# 'add_help=False' won't supress existing '-h' and '--help' options from the parser (and its
# subparsers) present in 'parent'. However that class is meant to be used with the main
# parser, which is created with `add_help=False` - the help is added only later. Hence it
# the newly created parser won't have help options added in its (main) root parser. The
# subparsers in the main parser will eventually have help activated, which is enough for its
# use in TVMC.
super().__init__(parents=[parent], add_help=False, usage=argparse.SUPPRESS, **kwargs)

def exit(self, status=0, message=None):
# Don't exit on error when parsing the command line.
# This won't catch all the errors generated when parsing tho. For instance, it won't catch
# errors due to missing required arguments. But this will catch "error: invalid choice",
# which is what it's necessary for its use in TVMC.
raise TVMCException()
21 changes: 10 additions & 11 deletions python/tvm/driver/tvmc/autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
from tvm.autotvm.tuner import XGBTuner
from tvm.target import Target

from . import common, composite_target, frontends
from .common import TVMCException
from . import TVMCException, composite_target, frontends
from .main import register_parser
from .model import TVMCModel
from .target import generate_target_args, reconstruct_target_args
from .target import target_from_cli, generate_target_args, reconstruct_target_args
from .shape_parser import parse_shape_string
from .transform import convert_graph_layout


# pylint: disable=invalid-name
Expand Down Expand Up @@ -220,7 +221,7 @@ def add_tune_parser(subparsers, _):
"--input-shapes",
help="specify non-generic shapes for model to run, format is "
'"input_name:[dim1,dim2,...,dimn] input_name2:[dim1,dim2]"',
type=common.parse_shape_string,
type=parse_shape_string,
)


Expand Down Expand Up @@ -256,9 +257,7 @@ def drive_tune(args):
logger.info("RPC tracker port: %s", rpc_port)

if not args.rpc_key:
raise common.TVMCException(
"need to provide an RPC tracker key (--rpc-key) for remote tuning"
)
raise TVMCException("need to provide an RPC tracker key (--rpc-key) for remote tuning")
else:
rpc_hostname = None
rpc_port = None
Expand Down Expand Up @@ -376,7 +375,7 @@ def tune_model(
tuning_records : str
The path to the produced tuning log file.
"""
target, extra_targets = common.target_from_cli(target, additional_target_options)
target, extra_targets = target_from_cli(target, additional_target_options)
target, target_host = Target.check_and_update_host_consist(target, target_host)
# TODO(jwfromm) Remove this deepcopy once AlterOpLayout bug that mutates source
# model is fixed. For now, creating a clone avoids the issue.
Expand All @@ -399,7 +398,7 @@ def tune_model(

if rpc_key:
if hostname is None or port is None:
raise common.TVMCException(
raise TVMCException(
"You must provide a hostname and port to connect to a remote RPC device."
)
if isinstance(port, str):
Expand Down Expand Up @@ -520,7 +519,7 @@ def autotvm_get_tuning_tasks(
target, target_host = Target.check_and_update_host_consist(target, target_host)

if alter_layout:
mod = common.convert_graph_layout(mod, alter_layout)
mod = convert_graph_layout(mod, alter_layout)

tasks = autotvm.task.extract_from_program(
mod["main"],
Expand Down Expand Up @@ -569,7 +568,7 @@ def autoscheduler_get_tuning_tasks(
target, target_host = Target.check_and_update_host_consist(target, target_host)

if alter_layout:
mod = common.convert_graph_layout(mod, alter_layout)
mod = convert_graph_layout(mod, alter_layout)

# Extract the tasks
tasks, task_weights = auto_scheduler.extract_tasks(
Expand Down
Loading