[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-17 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r490353684



##
File path: python/setup.py
##
@@ -166,7 +166,19 @@ def get_package_data_files():
 ],
 extras_require={
 "test": ["pillow<7", "matplotlib"],
-"extra_feature": ["tornado", "psutil", "xgboost>=1.1.0", "mypy", 
"orderedset"],
+"extra_feature": [
+"tornado",
+"psutil",
+"xgboost>=1.1.0",
+"mypy",
+"orderedset",
+"tensorflow==2.1.0",
+"tflite==2.1.0",

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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-17 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r490341993



##
File path: python/setup.py
##
@@ -166,7 +166,19 @@ def get_package_data_files():
 ],
 extras_require={
 "test": ["pillow<7", "matplotlib"],
-"extra_feature": ["tornado", "psutil", "xgboost>=1.1.0", "mypy", 
"orderedset"],
+"extra_feature": [
+"tornado",
+"psutil",
+"xgboost>=1.1.0",
+"mypy",
+"orderedset",
+"tensorflow==2.1.0",
+"tflite==2.1.0",

Review comment:
   You mean having a separate `extras_require` label, such as `tvmc`, for 
example?
   
   ```
   extras_require={
   "test": ["pillow<7", "matplotlib"],
   "extra_feature": [
   "tornado",
   "psutil",
   "xgboost>=1.1.0",
   "mypy",
   "orderedset",
   ],
   "tvmc": [
   "tensorflow>=2.1.0",
   "tflite>=2.1.0",
   "onnx>=1.7.0",
   "onnxruntime>=1.0.0",
   "torch>=1.4.0",
   "torchvision>=0.5.0",
   ],
   ...
   ```





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-17 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r490139224



##
File path: python/setup.py
##
@@ -163,6 +163,12 @@ def get_package_data_files():
 "attrs",
 "psutil",
 "typed_ast",
+"tensorflow==2.1.0",
+"tflite==2.1.0",

Review comment:
   Moved now.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-17 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r490089308



##
File path: python/setup.py
##
@@ -162,6 +162,12 @@ def get_package_data_files():
 'attrs',
 'psutil',
 'typed_ast',
+'tensorflow==2.1.0',
+'tflite==2.1.0',
+'onnx==1.6.0',
+'onnxruntime==1.0.0',
+'torch==1.4.0',
+'torchvision==0.5.0'

Review comment:
   This is now addressed by a separate comment: 
https://github.com/apache/incubator-tvm/pull/6302#discussion_r489769772
   
   Closing this one.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-12 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r486877881



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,280 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontend_names(),
+help="specify input model format",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+#TODO (@leandron) This is a path to a physical file, but
+# can be improved in future to add integration with a modelzoo
+# or URL, for example.
+parser.add_argument("FILE", help="path to the input model file")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments
+
+Parameters
+--
+args: argparse.Namespace
+Arguments from command line parser.
+
+Returns
+
+int
+Zero if successfully completed
+
+"""
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_code=None,
+target_host=None,
+model_format=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Parameters
+--
+path: str
+Path to a file
+target : str
+The target for which to compile. Can be a plain string or
+a path.
+dump_code : list, optional
+Dump the generated code for the specified source types, on
+the requested target.
+target_host : str, optional
+The target of the host machine if host-side code
+needs to be generated.
+model_format: str, optional
+A string representing a name of a frontend to be used
+tuning_records: str, optional
+Name of the file produced by the tuning to be used during
+compilation.
+alter_layout: str, optional
+The layout to convert the graph to. Note, the convert layout
+   

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-12 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r486877881



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,280 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontend_names(),
+help="specify input model format",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+#TODO (@leandron) This is a path to a physical file, but
+# can be improved in future to add integration with a modelzoo
+# or URL, for example.
+parser.add_argument("FILE", help="path to the input model file")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments
+
+Parameters
+--
+args: argparse.Namespace
+Arguments from command line parser.
+
+Returns
+
+int
+Zero if successfully completed
+
+"""
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_code=None,
+target_host=None,
+model_format=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Parameters
+--
+path: str
+Path to a file
+target : str
+The target for which to compile. Can be a plain string or
+a path.
+dump_code : list, optional
+Dump the generated code for the specified source types, on
+the requested target.
+target_host : str, optional
+The target of the host machine if host-side code
+needs to be generated.
+model_format: str, optional
+A string representing a name of a frontend to be used
+tuning_records: str, optional
+Name of the file produced by the tuning to be used during
+compilation.
+alter_layout: str, optional
+The layout to convert the graph to. Note, the convert layout
+   

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-11 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r487186955



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,280 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontend_names(),
+help="specify input model format",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+#TODO (@leandron) This is a path to a physical file, but
+# can be improved in future to add integration with a modelzoo
+# or URL, for example.
+parser.add_argument("FILE", help="path to the input model file")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments
+
+Parameters
+--
+args: argparse.Namespace
+Arguments from command line parser.
+
+Returns
+
+int
+Zero if successfully completed
+
+"""
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_code=None,
+target_host=None,
+model_format=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Parameters
+--
+path: str
+Path to a file
+target : str
+The target for which to compile. Can be a plain string or
+a path.
+dump_code : list, optional
+Dump the generated code for the specified source types, on
+the requested target.
+target_host : str, optional
+The target of the host machine if host-side code
+needs to be generated.
+model_format: str, optional
+A string representing a name of a frontend to be used
+tuning_records: str, optional
+Name of the file produced by the tuning to be used during
+compilation.
+alter_layout: str, optional
+The layout to convert the graph to. Note, the convert layout
+   

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-11 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r486877881



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,280 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontend_names(),
+help="specify input model format",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+#TODO (@leandron) This is a path to a physical file, but
+# can be improved in future to add integration with a modelzoo
+# or URL, for example.
+parser.add_argument("FILE", help="path to the input model file")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments
+
+Parameters
+--
+args: argparse.Namespace
+Arguments from command line parser.
+
+Returns
+
+int
+Zero if successfully completed
+
+"""
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_code=None,
+target_host=None,
+model_format=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Parameters
+--
+path: str
+Path to a file
+target : str
+The target for which to compile. Can be a plain string or
+a path.
+dump_code : list, optional
+Dump the generated code for the specified source types, on
+the requested target.
+target_host : str, optional
+The target of the host machine if host-side code
+needs to be generated.
+model_format: str, optional
+A string representing a name of a frontend to be used
+tuning_records: str, optional
+Name of the file produced by the tuning to be used during
+compilation.
+alter_layout: str, optional
+The layout to convert the graph to. Note, the convert layout
+   

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-09 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r485735664



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",

Review comment:
   Another option here is to make it mandatory and have no default.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-07 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r484429345



##
File path: python/tvm/driver/tvmc/common.py
##
@@ -17,6 +17,74 @@
 """
 Common utility functions shared by TVMC modules.
 """
+import argparse
+import re
+
+from tvm import relay
+from tvm import transform
 
 class TVMCException(Exception):
 """TVMC Exception"""
+
+
+def convert_graph_layout(mod, desired_layout):

Review comment:
   Good catch, I didn't know that it didn't check for layouts, but 
apparently it won't add anything if it is not needed. So I wrote a few tests 
and even raised #6410 for and issue that was happening.
   
   The new version includes these fixes and tests.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483632719



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments """
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.input_shape,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_sources=None,
+target_host=None,
+model_format=None,
+shapes=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Returns
+---
+graph : str
+A JSON-serialized TVM execution graph.
+lib : tvm.module.Module
+A TVM module containing the compiled functions.
+params : dict
+The parameters (weights) for the TVM module.
+dumps : dict
+Dictionary containing the dumps specified.
+
+"""
+dump_sources = [x.strip() for x in  dump_sources.split(',')] if 
dump_sources else None
+mod, params = frontends.load_model(path, model_format, shapes)
+
+return compile_relay(
+mod,
+params,
+target,
+dump_sources=dump_sources,
+target_host=target_host,
+tuning_records=tuning_records,
+alter_layout=alter_layout,
+)
+
+
+def compile_relay(
+mod,
+params,
+target,
+dump_sources=None,
+target_host=None,
+tuning_records=None,
+

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483632453



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments """
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.input_shape,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_sources=None,
+target_host=None,
+model_format=None,
+shapes=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Returns
+---
+graph : str
+A JSON-serialized TVM execution graph.
+lib : tvm.module.Module
+A TVM module containing the compiled functions.
+params : dict
+The parameters (weights) for the TVM module.
+dumps : dict
+Dictionary containing the dumps specified.
+
+"""
+dump_sources = [x.strip() for x in  dump_sources.split(',')] if 
dump_sources else None
+mod, params = frontends.load_model(path, model_format, shapes)
+
+return compile_relay(
+mod,
+params,
+target,
+dump_sources=dump_sources,
+target_host=target_host,
+tuning_records=tuning_records,
+alter_layout=alter_layout,
+)
+
+
+def compile_relay(
+mod,
+params,
+target,
+dump_sources=None,
+target_host=None,
+tuning_records=None,
+

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483629701



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments """
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.input_shape,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_sources=None,
+target_host=None,
+model_format=None,
+shapes=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Returns
+---
+graph : str
+A JSON-serialized TVM execution graph.
+lib : tvm.module.Module
+A TVM module containing the compiled functions.
+params : dict
+The parameters (weights) for the TVM module.
+dumps : dict
+Dictionary containing the dumps specified.
+
+"""
+dump_sources = [x.strip() for x in  dump_sources.split(',')] if 
dump_sources else None
+mod, params = frontends.load_model(path, model_format, shapes)
+
+return compile_relay(
+mod,
+params,
+target,
+dump_sources=dump_sources,
+target_host=target_host,
+tuning_records=tuning_records,
+alter_layout=alter_layout,
+)
+
+
+def compile_relay(
+mod,
+params,
+target,
+dump_sources=None,
+target_host=None,
+tuning_records=None,
+

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483539205



##
File path: python/tvm/driver/tvmc/frontends.py
##
@@ -0,0 +1,389 @@
+# 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.
+"""
+Provides support to parse models from different frameworks into Relay networks.
+
+Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
+loading the tool.
+"""
+import logging
+import os
+import sys
+from abc import ABC
+from abc import abstractmethod
+from pathlib import Path
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+class Frontend(ABC):
+"""Abstract class for frontend"""
+
+@staticmethod
+@abstractmethod
+def name():
+"""Frontend name"""
+
+@staticmethod
+@abstractmethod
+def suffixes():
+"""File suffixes (extensions) used by this frontend"""
+
+@abstractmethod
+def load(self, path, shapes):
+"""Load network"""
+
+
+def import_keras():
+""" Lazy import function for Keras"""
+# Keras writes the message "Using TensorFlow backend." to stderr
+# Redirect stderr during the import to disable this
+stderr = sys.stderr
+sys.stderr = open(os.devnull, "w")
+try:
+# pylint: disable=C0415
+import tensorflow as tf
+from tensorflow import keras
+
+return tf, keras
+finally:
+sys.stderr = stderr
+
+
+class KerasFrontend(Frontend):
+""" Keras frontend for TVMC """
+
+@staticmethod
+def name():
+return "keras"
+
+@staticmethod
+def suffixes():
+return ["h5"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import numpy as np
+from tvm import relay
+
+# pylint: disable=C0103
+tf, keras = import_keras()
+
+if shapes:
+raise TVMCException(
+"--input-shape is not supported for {}".format(self.name())
+)
+
+# tvm build currently imports keras directly instead of 
tensorflow.keras
+try:
+model = keras.models.load_model(path)
+except ValueError as err:
+raise TVMCException(str(err))
+
+# There are two flavours of keras model, sequential and
+# functional, TVM expects a functional model, so convert
+# if required:
+if self.is_sequential_p(model):
+model = self.sequential_to_functional(model)
+
+in_shapes = []
+for layer in model._input_layers:
+if tf.executing_eagerly():
+in_shapes.append(
+tuple(dim if dim is not None else 1 for dim in 
layer.input.shape)
+)
+else:
+in_shapes.append(
+tuple(
+dim.value if dim.value is not None else 1
+for dim in layer.input.shape
+)
+)
+
+inputs = [
+np.random.uniform(size=shape, low=-1.0, high=1.0) for shape in 
in_shapes
+]
+shape_dict = {name: x.shape for (name, x) in zip(model.input_names, 
inputs)}
+return relay.frontend.from_keras(model, shape_dict, layout="NHWC")
+
+def is_sequential_p(self, model):
+_, keras = import_keras()
+return isinstance(model, keras.models.Sequential)
+
+def sequential_to_functional(self, model):
+_, keras = import_keras()
+assert self.is_sequential_p(model)
+input_layer = 
keras.layers.Input(batch_shape=model.layers[0].input_shape)
+prev_layer = input_layer
+for layer in model.layers:
+prev_layer = layer(prev_layer)
+model = keras.models.Model([input_layer], [prev_layer])
+return model
+
+
+class OnnxFrontend(Frontend):
+""" ONNX frontend for TVMC """
+
+@staticmethod
+def name():
+return "onnx"
+
+@staticmethod
+def suffixes():
+return ["onnx"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import onnx
+from tvm import relay
+
+if shapes:
+raise TVMCException(
+"--input-shape is not supported for 

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483539372



##
File path: python/tvm/driver/tvmc/frontends.py
##
@@ -0,0 +1,389 @@
+# 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.
+"""
+Provides support to parse models from different frameworks into Relay networks.
+
+Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
+loading the tool.
+"""
+import logging
+import os
+import sys
+from abc import ABC
+from abc import abstractmethod
+from pathlib import Path
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+class Frontend(ABC):
+"""Abstract class for frontend"""
+
+@staticmethod
+@abstractmethod
+def name():
+"""Frontend name"""
+
+@staticmethod
+@abstractmethod
+def suffixes():
+"""File suffixes (extensions) used by this frontend"""
+
+@abstractmethod
+def load(self, path, shapes):
+"""Load network"""

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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483539088



##
File path: python/tvm/driver/tvmc/frontends.py
##
@@ -0,0 +1,389 @@
+# 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.
+"""
+Provides support to parse models from different frameworks into Relay networks.
+
+Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
+loading the tool.
+"""
+import logging
+import os
+import sys
+from abc import ABC
+from abc import abstractmethod
+from pathlib import Path
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+class Frontend(ABC):
+"""Abstract class for frontend"""
+
+@staticmethod
+@abstractmethod
+def name():
+"""Frontend name"""
+
+@staticmethod
+@abstractmethod
+def suffixes():
+"""File suffixes (extensions) used by this frontend"""
+
+@abstractmethod
+def load(self, path, shapes):
+"""Load network"""
+
+
+def import_keras():
+""" Lazy import function for Keras"""
+# Keras writes the message "Using TensorFlow backend." to stderr
+# Redirect stderr during the import to disable this
+stderr = sys.stderr
+sys.stderr = open(os.devnull, "w")
+try:
+# pylint: disable=C0415
+import tensorflow as tf
+from tensorflow import keras
+
+return tf, keras
+finally:
+sys.stderr = stderr
+
+
+class KerasFrontend(Frontend):
+""" Keras frontend for TVMC """
+
+@staticmethod
+def name():
+return "keras"
+
+@staticmethod
+def suffixes():
+return ["h5"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import numpy as np
+from tvm import relay
+
+# pylint: disable=C0103
+tf, keras = import_keras()
+
+if shapes:
+raise TVMCException(
+"--input-shape is not supported for {}".format(self.name())
+)
+
+# tvm build currently imports keras directly instead of 
tensorflow.keras
+try:
+model = keras.models.load_model(path)
+except ValueError as err:
+raise TVMCException(str(err))
+
+# There are two flavours of keras model, sequential and
+# functional, TVM expects a functional model, so convert
+# if required:
+if self.is_sequential_p(model):
+model = self.sequential_to_functional(model)
+
+in_shapes = []
+for layer in model._input_layers:
+if tf.executing_eagerly():
+in_shapes.append(
+tuple(dim if dim is not None else 1 for dim in 
layer.input.shape)
+)
+else:
+in_shapes.append(
+tuple(
+dim.value if dim.value is not None else 1
+for dim in layer.input.shape
+)
+)
+
+inputs = [
+np.random.uniform(size=shape, low=-1.0, high=1.0) for shape in 
in_shapes
+]
+shape_dict = {name: x.shape for (name, x) in zip(model.input_names, 
inputs)}
+return relay.frontend.from_keras(model, shape_dict, layout="NHWC")
+
+def is_sequential_p(self, model):
+_, keras = import_keras()
+return isinstance(model, keras.models.Sequential)
+
+def sequential_to_functional(self, model):
+_, keras = import_keras()
+assert self.is_sequential_p(model)
+input_layer = 
keras.layers.Input(batch_shape=model.layers[0].input_shape)
+prev_layer = input_layer
+for layer in model.layers:
+prev_layer = layer(prev_layer)
+model = keras.models.Model([input_layer], [prev_layer])
+return model
+
+
+class OnnxFrontend(Frontend):
+""" ONNX frontend for TVMC """
+
+@staticmethod
+def name():
+return "onnx"
+
+@staticmethod
+def suffixes():
+return ["onnx"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import onnx
+from tvm import relay
+
+if shapes:
+raise TVMCException(
+"--input-shape is not supported for 

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483520459



##
File path: python/tvm/driver/tvmc/frontends.py
##
@@ -0,0 +1,389 @@
+# 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.
+"""
+Provides support to parse models from different frameworks into Relay networks.
+
+Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
+loading the tool.
+"""
+import logging
+import os
+import sys
+from abc import ABC
+from abc import abstractmethod
+from pathlib import Path
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+class Frontend(ABC):
+"""Abstract class for frontend"""
+
+@staticmethod
+@abstractmethod
+def name():
+"""Frontend name"""
+
+@staticmethod
+@abstractmethod
+def suffixes():
+"""File suffixes (extensions) used by this frontend"""
+
+@abstractmethod
+def load(self, path, shapes):
+"""Load network"""
+
+
+def import_keras():
+""" Lazy import function for Keras"""
+# Keras writes the message "Using TensorFlow backend." to stderr
+# Redirect stderr during the import to disable this
+stderr = sys.stderr
+sys.stderr = open(os.devnull, "w")
+try:
+# pylint: disable=C0415
+import tensorflow as tf
+from tensorflow import keras
+
+return tf, keras
+finally:
+sys.stderr = stderr
+
+
+class KerasFrontend(Frontend):
+""" Keras frontend for TVMC """
+
+@staticmethod
+def name():
+return "keras"
+
+@staticmethod
+def suffixes():
+return ["h5"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import numpy as np
+from tvm import relay

Review comment:
   Done

##
File path: python/tvm/driver/tvmc/frontends.py
##
@@ -0,0 +1,389 @@
+# 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.
+"""
+Provides support to parse models from different frameworks into Relay networks.
+
+Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
+loading the tool.
+"""
+import logging
+import os
+import sys
+from abc import ABC
+from abc import abstractmethod
+from pathlib import Path
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+class Frontend(ABC):
+"""Abstract class for frontend"""
+
+@staticmethod
+@abstractmethod
+def name():
+"""Frontend name"""
+
+@staticmethod
+@abstractmethod
+def suffixes():
+"""File suffixes (extensions) used by this frontend"""
+
+@abstractmethod
+def load(self, path, shapes):
+"""Load network"""
+
+
+def import_keras():
+""" Lazy import function for Keras"""
+# Keras writes the message "Using TensorFlow backend." to stderr
+# Redirect stderr during the import to disable this
+stderr = sys.stderr
+sys.stderr = open(os.devnull, "w")
+try:
+# pylint: disable=C0415
+import tensorflow as tf
+from tensorflow import keras
+
+return tf, keras
+finally:
+sys.stderr = stderr
+
+
+class KerasFrontend(Frontend):
+""" Keras frontend for TVMC """
+
+@staticmethod
+def name():
+return "keras"
+
+@staticmethod
+def suffixes():
+return ["h5"]
+
+def load(self, path, shapes):
+# pylint: disable=C0415
+import numpy as np
+from tvm import relay
+
+# pylint: disable=C0103
+tf, 

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483511867



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments """
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.input_shape,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_sources=None,
+target_host=None,
+model_format=None,
+shapes=None,
+tuning_records=None,
+alter_layout=None,
+):

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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483509079



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")

Review comment:
   The description will be present in my next commit. I added a TODO for 
modelzoo integration.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-04 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483508754



##
File path: python/tvm/driver/tvmc/common.py
##
@@ -17,6 +17,74 @@
 """
 Common utility functions shared by TVMC modules.
 """
+import argparse
+import re
+
+from tvm import relay
+from tvm import transform
 
 class TVMCException(Exception):
 """TVMC Exception"""
+
+
+def convert_graph_layout(mod, desired_layout):
+"""Alter the layout of the input graph.
+
+Parameters
+--
+mod : tvm.relay.Module
+The relay module to convert.
+desired_layout : str
+The layout to convert to.
+
+Returns
+---
+mod : tvm.relay.Module
+The converted module.
+"""
+
+# Assume for the time being that graphs only have
+# conv2d as heavily-sensitive operators.
+desired_layouts = {
+"nn.conv2d": [desired_layout, "default"],
+"qnn.conv2d": [desired_layout, "default"],
+}
+
+# Convert the layout of the graph where possible.
+seq = transform.Sequential(
+[
+relay.transform.RemoveUnusedFunctions(),
+relay.transform.ConvertLayout(desired_layouts),
+]
+)
+with transform.PassContext(opt_level=3):
+return seq(mod)
+
+
+def parse_input_shapes(shapes_str):
+""" Parsing function for tensor shape syntax. """
+shapes = []
+# Split up string into comma seperated sections ignoring commas in ()s
+match = re.findall(r"(\(.*?\)|.+?),?", shapes_str)
+if match:
+for inp in match:
+# Test for and remove brackets
+shape = re.match(r"\((.*)\)", inp)
+if shape and shape.lastindex == 1:
+# Remove white space and extract numbers
+strshape = shape[1].replace(" ", "").split(",")
+try:
+shapes.append([int(i) for i in strshape])
+except ValueError:
+raise argparse.ArgumentTypeError(
+f"expected numbers in shape '{shape[1]}'"

Review comment:
   This function will not be present in the next review of this patch, so 
I'll mark this as solved, and also check for f-string usage.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-03 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r483100119



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",

Review comment:
   Thanks @masahi - it seems it works, so I'm removing the `--input-shape`





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-03 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r482965966



##
File path: python/tvm/driver/tvmc/common.py
##
@@ -17,6 +17,74 @@
 """
 Common utility functions shared by TVMC modules.
 """
+import argparse
+import re
+
+from tvm import relay
+from tvm import transform
 
 class TVMCException(Exception):
 """TVMC Exception"""
+
+
+def convert_graph_layout(mod, desired_layout):
+"""Alter the layout of the input graph.
+
+Parameters
+--
+mod : tvm.relay.Module
+The relay module to convert.
+desired_layout : str
+The layout to convert to.
+
+Returns
+---
+mod : tvm.relay.Module
+The converted module.
+"""
+
+# Assume for the time being that graphs only have
+# conv2d as heavily-sensitive operators.
+desired_layouts = {
+"nn.conv2d": [desired_layout, "default"],
+"qnn.conv2d": [desired_layout, "default"],
+}
+
+# Convert the layout of the graph where possible.
+seq = transform.Sequential(
+[
+relay.transform.RemoveUnusedFunctions(),
+relay.transform.ConvertLayout(desired_layouts),
+]
+)
+with transform.PassContext(opt_level=3):
+return seq(mod)
+
+
+def parse_input_shapes(shapes_str):
+""" Parsing function for tensor shape syntax. """
+shapes = []
+# Split up string into comma seperated sections ignoring commas in ()s
+match = re.findall(r"(\(.*?\)|.+?),?", shapes_str)
+if match:
+for inp in match:
+# Test for and remove brackets
+shape = re.match(r"\((.*)\)", inp)
+if shape and shape.lastindex == 1:
+# Remove white space and extract numbers
+strshape = shape[1].replace(" ", "").split(",")
+try:
+shapes.append([int(i) for i in strshape])
+except ValueError:
+raise argparse.ArgumentTypeError(
+f"expected numbers in shape '{shape[1]}'"

Review comment:
   There is a chance, if I manage to improve the way PyTorch auto-discover 
input shapes, this will not be needed anymore. I'll leave it open for now.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-03 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r482858084



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",

Review comment:
   To follow-up on this: for other frontends we have functions that will 
discover the input shapes. For PyTorch we didn't find a way to do a similar 
function. If we find a way to collect that information from the model, we can 
remove all this logic and simplify the command line.
   
   @masahi would you have an idea on how to get the input shapes from a given 
PyTorch model, programatically?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-03 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r482858084



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",

Review comment:
   To follow-up on this: for other frontends we have functions that will 
discover the input shapes. For PyTorch we didn't find a way to do a similar 
function. If we find a way to collect that information from the model, we can 
remove all this logic and simplify the command line.
   
   @masahi would you have idea on how to get the input shapes from a given 
PyTorch model, programatically?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-09-03 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r482832429



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,305 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import logging
+import os.path
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm.contrib import cc
+from tvm.contrib import util
+
+from . import common, frontends
+from .main import register_parser
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to generate target libraries, e.g. 
'aarch64-linux-gnu-gcc'",
+)
+parser.add_argument(
+"--dump-code",
+metavar="FORMAT",
+default="",
+help="comma separarated list of formats to export, e.g. 'asm,ll,relay' 
"
+)
+parser.add_argument(
+"--model-format",
+choices=frontends.get_frontends(),
+help="specify input model format",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="module.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--target",
+help="compilation target as plain string, inline JSON or path to a 
JSON file",
+required=True
+)
+parser.add_argument(
+"--tuning-records",
+metavar="PATH",
+default="",
+help="path to an auto-tuning log file from AutoTVM"
+)
+parser.add_argument(
+"--desired-layout",
+choices=["NCHW", "NHWC"],
+default=None,
+help="change the data layout of the whole graph",
+)
+parser.add_argument(
+"-v", "--verbose", action="count", default=0, help="increase verbosity"
+)
+parser.add_argument("FILE")
+
+
+def drive_compile(args):
+""" Invoke tvmc.compiler module with command line arguments """
+
+graph, lib, params, dumps = compile_model(
+args.FILE,
+args.target,
+args.dump_code,
+"",
+args.model_format,
+args.input_shape,
+args.tuning_records,
+args.tensor_layout,
+)
+
+if dumps:
+save_dumps(args.output, dumps)
+
+save_module(args.output, graph, lib, params, args.cross_compiler)
+return 0
+
+
+def compile_model(
+path,
+target,
+dump_sources=None,
+target_host=None,
+model_format=None,
+shapes=None,
+tuning_records=None,
+alter_layout=None,
+):
+"""Compile a model from a supported framework into a TVM module.
+
+This function takes a union of the arguments of both frontends.load_model
+and compiler.compile_relay. The resulting TVM module can be executed using
+the graph runtime.
+
+Returns
+---
+graph : str
+A JSON-serialized TVM execution graph.
+lib : tvm.module.Module
+A TVM module containing the compiled functions.
+params : dict
+The parameters (weights) for the TVM module.
+dumps : dict
+Dictionary containing the dumps specified.
+
+"""
+dump_sources = [x.strip() for x in  dump_sources.split(',')] if 
dump_sources else None
+mod, params = frontends.load_model(path, model_format, shapes)
+
+return compile_relay(
+mod,
+params,
+target,
+dump_sources=dump_sources,
+target_host=target_host,
+tuning_records=tuning_records,
+alter_layout=alter_layout,
+)
+
+
+def compile_relay(
+mod,
+params,
+target,
+dump_sources=None,
+target_host=None,
+tuning_records=None,
+

[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479369876



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,

Review comment:
   This is now removed.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479369467



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",

Review comment:
   I'm clarifying this and will reply soon.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479369247



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",

Review comment:
   I called it `module.tar` now, but I'm not very happy with that name. Do 
you have a suggestion?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479368959



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",

Review comment:
   Example added.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479368782



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",
+type=parse_target,
+action="append",
+metavar="TARGET[,TARGET]...",
+help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default 
llvm",
+)
+parser.add_argument("--tuner-file", default="", help="tuner file")
+parser.add_argument(
+"--alter-layout",

Review comment:
   It is now called `--desired-layout`





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479368531



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",

Review comment:
   We now have only one target that connects directly to the Python target 
API from #6315.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-28 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r479367226



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}

Review comment:
   TODO added





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-27 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r478604162



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]

Review comment:
   This is basically the same Target discussion. Lets keep it here: 
https://github.com/apache/incubator-tvm/pull/6302#discussion_r476606729

##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):

Review comment:
   Target discussion: 
https://github.com/apache/incubator-tvm/pull/6302#discussion_r476606729





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-27 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r478598548



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",
+type=parse_target,
+action="append",
+metavar="TARGET[,TARGET]...",
+help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default 
llvm",
+)
+parser.add_argument("--tuner-file", default="", help="tuner file")

Review comment:
   I think it is more aligned with the underlying API. Will update this 
soon.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-27 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r478586988



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",
+type=parse_target,
+action="append",
+metavar="TARGET[,TARGET]...",
+help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default 
llvm",
+)
+parser.add_argument("--tuner-file", default="", help="tuner file")

Review comment:
   Will that make more sense if we call it `--tuning-records` ?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-27 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r478580880



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"

Review comment:
   I was going to open an issue, but in the end I think we can open this 
discussion as an RFC to get a common understanding.
   
   
https://discuss.tvm.ai/t/rfc-savetofile-file-name-format-expected-behavior/7741
   
   I will put a `TODO` in the sources and just connect it to the current APIs, 
so that we can move forward.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-26 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r477133826



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",

Review comment:
   This boils down to the [Target 
discussion](https://discuss.tvm.ai/t/rfc-tvm-target-specification/6844/52). 
With recent changes, it makes sense to point only one target, from the user 
point of view, and leave the JSON descriptions of targets deal with details.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-26 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r477131644



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",

Review comment:
   I see what you mean and I agree - I'll remove that and we can re-add in 
case we need in future. Happy also to hear @jroesch's thoughts.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-26 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r477130487



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",

Review comment:
   Yes, that is the case. We try guessing the framework from a list of 
known extensions per frontend. So in my next update, this will be renamed.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-21 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474781346



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"

Review comment:
   I agree that `--dump-code` is more meaningful than the previous one and 
will change that.
   
   About the dump formats, the intention was to have a set of supported 
formats, considering the supported targets (which were previously all around 
llvm), so they don't make sense anymore, considering we're integrating with a 
more generic view of TVM targets. This is mainly why it looks confusing.
   
   There were two practical issues that I noticed during my tests:
   1) it is not possible to anticipate which formats are supported, without 
knowing the target implementation (in TVM) in great detail
   2) There is also no consistency in the way targets deal with invalid 
requests for unsupported formats: some will break, some will give the same 
sources with whatever format you ask.
   
   Both things will need fixing to provide better usability for the end-user. 
I'll see at least to create issues for them, so we don't lose track.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-21 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474733982



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):

Review comment:
   Yeah, this will be removed and be used according to the improvements we 
will have from the Target Specification RFC.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-21 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474731434



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",
+type=parse_target,
+action="append",
+metavar="TARGET[,TARGET]...",
+help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default 
llvm",
+)
+parser.add_argument("--tuner-file", default="", help="tuner file")
+parser.add_argument(
+"--alter-layout",

Review comment:
   I'm not sure about `--desire-layout`. I was checking and it seems some 
there is not a broadly adopted name for this. TensorFlow call it "data layout", 
some nvidia docs would call it "tensor layout", pytorch call it "memory 
format", for example.
   
   Among these, I think "tensor layout" is the most descriptive in my opinion. 
What do you think?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474080780



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,

Review comment:
   My comments 
https://github.com/apache/incubator-tvm/pull/6302#discussion_r473176259





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474062879



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",

Review comment:
   The context about "sanitization" is:
   - "not sanitized": In case you have an error on TVM when importing the 
model, it will show you the error directly from TVM.
   - "sanitized": in case of error, the command line driver wil encapsulate the 
original error into a `TVMCException`, meaning it will be display only the 
shorter error message, without the whole stack trace, for example
   
   That said, maybe we can come up together with a better name for this option. 
Any thoughts?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474062879



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",

Review comment:
   You're right. I'll remove the `--no-sanitize-diagnostics` to make it 
simpler, and improve the help message.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474055620



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}

Review comment:
   @junrushao1994 is there a way to obtain a list of all the registered 
targets so that we can offer that list in the `python -m tvm.driver.tvmc 
compile --help`, rather than the user needing to guess what is the expected 
target tag for the actual hardware they got?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474056126



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"

Review comment:
   I'll leave it here for now, as I'm trying to clarify how to get a list 
of targets somewhere else.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474045263



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",
+choices=frontends.get_frontends(),
+help="specify input language",
+)
+parser.add_argument(
+"--input-shape",
+type=common.parse_input_shapes,
+metavar="INPUT_SHAPE,[INPUT_SHAPE]...",
+help="for pytorch, e.g. '(1,3,224,224)'",
+)
+parser.add_argument(
+"-o",
+"--output",
+default="a.tar",
+help="output the compiled module to an archive",
+)
+parser.add_argument(
+"--sanitize-diagnostics",
+action="store_true",
+default=True,
+dest="sanitize_diagnostics",
+help="enable diagnostic sanitization",
+)
+parser.add_argument(
+"--no-sanitize-diagnostics",
+action="store_false",
+dest="sanitize_diagnostics",
+help="disable diagnostic sanitization",
+)
+parser.add_argument(
+"--target",
+type=parse_target,
+action="append",
+metavar="TARGET[,TARGET]...",
+help=f"compilation target(s): {', '.join(VALID_TARGETS)}, default 
llvm",
+)
+parser.add_argument("--tuner-file", default="", help="tuner file")

Review comment:
   This is the output file (the log) from the tuning process, so that 
transfer learning can be used. I'll make that simpler to understand in the 
`help` description.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474039627



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]

Review comment:
   I agree that maintaining tables in two places is not a good idea. On the 
other hand, I couldn't find a way to list all currently registered targets. Any 
idea on that can be 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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474039627



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]

Review comment:
   I agree that maintaining tables in two places is not a good idea. On the 
other hand, I couldn't find a way to list all currently registered target. Any 
idea on that can be 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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474014203



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",

Review comment:
   I agree that `--language` doesn't seem the best option here. Discussing 
with @mbaret, we came up with the idea of changing it to `--model-format 
{keras, onnx, ...}`. What do you think?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r474014203



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}
+
+#  A list of valid targets (including aliases) to be used in "--target"
+VALID_TARGETS = ["aarch64", "llvm"]
+
+DEFAULT_TARGET = "llvm"
+DUMP_FORMATS = ["relay", "ll", "asm"]
+
+
+def parse_target(targets_str):
+""" Parsing function for comma separated target syntax. """
+targets = targets_str.split(",")
+for target in targets:
+if target not in VALID_TARGETS:
+raise argparse.ArgumentTypeError(f"unrecognized target: {target}")
+return targets
+
+
+@register_parser
+def add_compile_parser(subparsers):
+""" Include parser for 'compile' subcommand """
+
+parser = subparsers.add_parser("compile", help="compile a model")
+parser.set_defaults(func=drive_compile)
+parser.add_argument(
+"--cross-compiler",
+default="",
+help="the cross compiler to use to generate target libraries",
+)
+parser.add_argument(
+"--dump-codegen", default="", choices=DUMP_FORMATS, help="dump 
generated code"
+)
+parser.add_argument(
+"--language",

Review comment:
   I agree that `--language` doesn't seem the best option here. Discussing 
with @mbaret, we came up with the idea of changing it to `--model-format`. What 
do you think?





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r473811542



##
File path: python/tvm/driver/tvmc/compiler.py
##
@@ -0,0 +1,407 @@
+# 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.
+"""
+Provides support to compile networks both AOT and JIT.
+"""
+import argparse
+import logging
+import tarfile
+from pathlib import Path
+
+import tvm
+from tvm import autotvm
+from tvm import relay
+from tvm._ffi.runtime_ctypes import TVMContext
+from tvm.contrib import cc
+from tvm.contrib import util
+from tvm.relay.op.contrib import get_pattern_table
+
+from . import common, frontends
+from .main import register_parser
+
+# A dictionary of target aliases to simplify the command lines provided by end 
users
+TARGET_ALIASES = {
+"aarch64": "llvm -device=arm_cpu -mtriple=aarch64-linux-gnu -mattr=+neon"
+}

Review comment:
   It is really a consequence of the original development being on a 
separate repo, and making sure we have access to the targets we wanted for our 
testing purposes.
   
   Now, it makes much more sense to go the way you suggest, I'll change that.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [incubator-tvm] leandron commented on a change in pull request #6302: [tvmc] command line driver 'compile' (part 2/4)

2020-08-20 Thread GitBox


leandron commented on a change in pull request #6302:
URL: https://github.com/apache/incubator-tvm/pull/6302#discussion_r473810441



##
File path: python/tvm/driver/tvmc/__init__.py
##
@@ -14,3 +14,8 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+
+from .compiler import add_compile_parser

Review comment:
   Makes sense. Just to be certain I'm getting the compiler module I want, 
I'll change it to `from . import compiler`.





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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org