You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2020/07/22 16:27:15 UTC

[GitHub] [incubator-tvm] leandron opened a new pull request #6112: TVMC - a command line driver for TVM

leandron opened a new pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112


   TVMC - a command line driver for TVM
    * Introduce a command line driver to compile, run and tune models, using TVM graph runtime
    * tvmc tests and integrate tvmc with regular linting, testing, CI and build scripts
    * RFC: https://discuss.tvm.ai/t/rfc-a-tvm-command-line-interface/5165 and more discussion at https://discuss.tvm.ai/t/usability-idea-create-a-command-line-compiler-that-would-perform-common-build-tasks-out-of-the-box/5129


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
leandron commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-671292078


   > The command name`tvmc` sounds strange, it is not immediately obvious what the c stands for. Can the shell command be called just `tvm compile` `tvm tune` etc. same as [aws cli](https://aws.amazon.com/cli/) or [github cli](https://github.com/cli/cli).
   
   This is open for discussion - for the moment I'm keeping the original name of the work `tvmc`, but I'm happy to consider other options (including `tvm`).


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r470713940



##########
File path: tvmc/README.md
##########
@@ -0,0 +1,122 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVMC
+
+```tvmc``` is a tool that provides useful command line invocations to compile,
+run and tune models using TVM graph runtime.
+
+In order to compile and tune, ```tvmc``` takes a model file and parameters as inputs,
+and outputs a TAR file that contains the TVM modules that represent the
+input model, graph and weights, for the required target. Target can be native or
+cross-compiled.
+
+When running a given model, ```tvmc``` expects a compiled model and input tensor values, so
+that it can produce the outputs, when running on the required target, local or remote.
+
+This document presents an overview and a short tutorial about ```tvmc```.
+
+## Installation
+
+```tvmc``` is a Python tool and - provided TVM and dependencies are available - it can be
+installed in various ways.
+
+The recommended way to install ```tvmc``` is via it's ```setuptools``` configuration file,
+located at ```tvm/tvmc/setup.py```. To do that, go to the the TVM directory and run the
+installation command, as described below:
+
+    cd tvm/tvmc
+    python setup.py install
+
+The command above should install everything needed to get started with ```tvmc```, including
+all the the supported frontends.
+
+Once ```tvmc``` is installed, the main entry-point is the ```tvmc``` command line. A set of
+sub-commands are available, to run the specific tasks offered by ```tvmc```: ```tune```,
+```compile``` and ```run```.
+
+The simplest way to get more information about a specific sub-command is ```tvmc <subcommand>
+-- help```.
+
+    tvmc compile --help
+
+##  Usage
+
+Now, let's compile a network and generate a few predictions using ```tvmc```.
+
+As described above, in order to compile a model using ```tvmc```, the first thing we need is
+a model file. For the sake of this example, let's use a MobileNet V1 model, in TFLite format.
+More information about the model is available on
+[this page](https://www.tensorflow.org/lite/guide/hosted_models).
+
+To download and un-compress the ```.tgz``` file (34Mb), so that we can access the TFLite model,
+run the command lines below:
+
+    wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz
+    tar xvzf mobilenet_v1_1.0_224_quant.tgz
+
+With these commands, we should be able to provide the MobileNet V1 file (```mobilenet_v1_1.0_224_quant.tflite```)
+to ```tvmc```, and obtain our TVM compiled model as an output. To do that, run the
+following command line:
+
+    tvmc compile -v mobilenet_v1_1.0_224_quant.tflite -o compiled_model.tar
+
+As an output, you will notice a ```compiled_model.tar```, in the same directory.
+
+Now it is time to feed the model with some input, that will generate a prediction using TVM.
+As models are very diverse in terms of input formats and the source of those inputs (images, streams,
+sensors, sound, to name a few), ```tvmc``` supports ```.npz``` (serialized NumPy arrays) as the
+main format for ```tvmc run```. To learn more about the ```.npz``` format, please read the
+[documentation](https://numpy.org/doc/stable/reference/generated/numpy.savez.html) on NumPy website.
+
+MobileNet V1 expects a ```(224, 224, 3)``` input tensor. The Python code snippet below, can be used
+as an example on how to convert a PNG file into a ```.npz``` file in the expected shape.
+The example below uses [PIL](https://pillow.readthedocs.io/en/stable/) and
+[NumPy](https://numpy.org) functions to import the image and generate the expected file.
+
+    from tvm.contrib.download import download_testdata
+    from PIL import Image
+    import numpy as np
+
+    cat_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
+    image_path = download_testdata(cat_url, 'imagenet_cat.png', module='data')
+    resized_image = Image.open(image_path).resize((224, 224))
+    image_data = np.asarray(resized_image).astype("float32")
+    image_data = np.expand_dims(image_data, axis=0)
+
+    np.savez("imagenet_cat", input=image_data)

Review comment:
       The specific points discussed here will make more sense in the next PR, when introducing the `compile` subcommand, so I'll mark it as resolved 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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468086427



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="tvm compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    # TODO: subparsers will come in follow-up patches (@leandron)
+    _ = parser.add_subparsers(title="commands")
+
+    args = parser.parse_args(argv)
+    if args.verbose > 4:
+        args.verbose = 4
+
+    logging.getLogger().setLevel(40 - args.verbose * 10)
+
+    if args.version:
+        version = pkg_resources.get_distribution("tvm").version
+        sys.stdout.write("%s\n" % version)
+        return 0
+
+    if not hasattr(args, "func"):
+        parser.error("missing subcommand")

Review comment:
       Sure, I'll add a small placeholder example, so that in the specific (real) subparsers we can review the whole funcionality.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on a change in pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r458934696



##########
File path: Jenkinsfile
##########
@@ -167,6 +167,7 @@ stage('Build') {
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta_tsim.sh"
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_golang.sh"
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_rust.sh"
+          sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_tvmc.sh"

Review comment:
       NOTE: changes to the Jenkinsfile won't be immediately reflected, for now, set the sh file to a blank file, and then we can turn in on as a followup PR

##########
File path: tvmc/README.md
##########
@@ -0,0 +1,122 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVMC
+
+```tvmc``` is a tool that provides useful command line invocations to compile,
+run and tune models using TVM graph runtime.
+
+In order to compile and tune, ```tvmc``` takes a model file and parameters as inputs,
+and outputs a TAR file that contains the TVM modules that represent the
+input model, graph and weights, for the required target. Target can be native or
+cross-compiled.
+
+When running a given model, ```tvmc``` expects a compiled model and input tensor values, so
+that it can produce the outputs, when running on the required target, local or remote.
+
+This document presents an overview and a short tutorial about ```tvmc```.
+
+## Installation
+
+```tvmc``` is a Python tool and - provided TVM and dependencies are available - it can be
+installed in various ways.
+
+The recommended way to install ```tvmc``` is via it's ```setuptools``` configuration file,
+located at ```tvm/tvmc/setup.py```. To do that, go to the the TVM directory and run the
+installation command, as described below:
+
+    cd tvm/tvmc
+    python setup.py install
+
+The command above should install everything needed to get started with ```tvmc```, including
+all the the supported frontends.
+
+Once ```tvmc``` is installed, the main entry-point is the ```tvmc``` command line. A set of
+sub-commands are available, to run the specific tasks offered by ```tvmc```: ```tune```,
+```compile``` and ```run```.
+
+The simplest way to get more information about a specific sub-command is ```tvmc <subcommand>
+-- help```.
+
+    tvmc compile --help
+
+##  Usage
+
+Now, let's compile a network and generate a few predictions using ```tvmc```.
+
+As described above, in order to compile a model using ```tvmc```, the first thing we need is
+a model file. For the sake of this example, let's use a MobileNet V1 model, in TFLite format.
+More information about the model is available on
+[this page](https://www.tensorflow.org/lite/guide/hosted_models).
+
+To download and un-compress the ```.tgz``` file (34Mb), so that we can access the TFLite model,
+run the command lines below:
+
+    wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz
+    tar xvzf mobilenet_v1_1.0_224_quant.tgz
+
+With these commands, we should be able to provide the MobileNet V1 file (```mobilenet_v1_1.0_224_quant.tflite```)
+to ```tvmc```, and obtain our TVM compiled model as an output. To do that, run the
+following command line:
+
+    tvmc compile -v mobilenet_v1_1.0_224_quant.tflite -o compiled_model.tar
+
+As an output, you will notice a ```compiled_model.tar```, in the same directory.
+
+Now it is time to feed the model with some input, that will generate a prediction using TVM.
+As models are very diverse in terms of input formats and the source of those inputs (images, streams,
+sensors, sound, to name a few), ```tvmc``` supports ```.npz``` (serialized NumPy arrays) as the
+main format for ```tvmc run```. To learn more about the ```.npz``` format, please read the
+[documentation](https://numpy.org/doc/stable/reference/generated/numpy.savez.html) on NumPy website.
+
+MobileNet V1 expects a ```(224, 224, 3)``` input tensor. The Python code snippet below, can be used
+as an example on how to convert a PNG file into a ```.npz``` file in the expected shape.
+The example below uses [PIL](https://pillow.readthedocs.io/en/stable/) and
+[NumPy](https://numpy.org) functions to import the image and generate the expected file.
+
+    from tvm.contrib.download import download_testdata
+    from PIL import Image
+    import numpy as np
+
+    cat_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
+    image_path = download_testdata(cat_url, 'imagenet_cat.png', module='data')
+    resized_image = Image.open(image_path).resize((224, 224))
+    image_data = np.asarray(resized_image).astype("float32")
+    image_data = np.expand_dims(image_data, axis=0)
+
+    np.savez("imagenet_cat", input=image_data)

Review comment:
       Let us consider move it to a sub-namespace of the TVM itself, say, 
   
   ```bash
   python -m tvm.driver
   ```
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron edited a comment on pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron edited a comment on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-671295731


   @comaniac here is a new version of this patch with only the minimal code to enable the command line. Follow up patches, that I will send after this, will deal with `compile`, `run` and `tune` functionalities.
   
   So, here is a checklist:
   - [x]  tvmc enablement (this)
   - [ ] `compile`
   - [ ] `run`
   - [ ]  `tune`
   - [ ] Tutorial


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on a change in pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
tqchen commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r461721804



##########
File path: tvmc/README.md
##########
@@ -0,0 +1,122 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVMC
+
+```tvmc``` is a tool that provides useful command line invocations to compile,
+run and tune models using TVM graph runtime.
+
+In order to compile and tune, ```tvmc``` takes a model file and parameters as inputs,
+and outputs a TAR file that contains the TVM modules that represent the
+input model, graph and weights, for the required target. Target can be native or
+cross-compiled.
+
+When running a given model, ```tvmc``` expects a compiled model and input tensor values, so
+that it can produce the outputs, when running on the required target, local or remote.
+
+This document presents an overview and a short tutorial about ```tvmc```.
+
+## Installation
+
+```tvmc``` is a Python tool and - provided TVM and dependencies are available - it can be
+installed in various ways.
+
+The recommended way to install ```tvmc``` is via it's ```setuptools``` configuration file,
+located at ```tvm/tvmc/setup.py```. To do that, go to the the TVM directory and run the
+installation command, as described below:
+
+    cd tvm/tvmc
+    python setup.py install
+
+The command above should install everything needed to get started with ```tvmc```, including
+all the the supported frontends.
+
+Once ```tvmc``` is installed, the main entry-point is the ```tvmc``` command line. A set of
+sub-commands are available, to run the specific tasks offered by ```tvmc```: ```tune```,
+```compile``` and ```run```.
+
+The simplest way to get more information about a specific sub-command is ```tvmc <subcommand>
+-- help```.
+
+    tvmc compile --help
+
+##  Usage
+
+Now, let's compile a network and generate a few predictions using ```tvmc```.
+
+As described above, in order to compile a model using ```tvmc```, the first thing we need is
+a model file. For the sake of this example, let's use a MobileNet V1 model, in TFLite format.
+More information about the model is available on
+[this page](https://www.tensorflow.org/lite/guide/hosted_models).
+
+To download and un-compress the ```.tgz``` file (34Mb), so that we can access the TFLite model,
+run the command lines below:
+
+    wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz
+    tar xvzf mobilenet_v1_1.0_224_quant.tgz
+
+With these commands, we should be able to provide the MobileNet V1 file (```mobilenet_v1_1.0_224_quant.tflite```)
+to ```tvmc```, and obtain our TVM compiled model as an output. To do that, run the
+following command line:
+
+    tvmc compile -v mobilenet_v1_1.0_224_quant.tflite -o compiled_model.tar
+
+As an output, you will notice a ```compiled_model.tar```, in the same directory.
+
+Now it is time to feed the model with some input, that will generate a prediction using TVM.
+As models are very diverse in terms of input formats and the source of those inputs (images, streams,
+sensors, sound, to name a few), ```tvmc``` supports ```.npz``` (serialized NumPy arrays) as the
+main format for ```tvmc run```. To learn more about the ```.npz``` format, please read the
+[documentation](https://numpy.org/doc/stable/reference/generated/numpy.savez.html) on NumPy website.
+
+MobileNet V1 expects a ```(224, 224, 3)``` input tensor. The Python code snippet below, can be used
+as an example on how to convert a PNG file into a ```.npz``` file in the expected shape.
+The example below uses [PIL](https://pillow.readthedocs.io/en/stable/) and
+[NumPy](https://numpy.org) functions to import the image and generate the expected file.
+
+    from tvm.contrib.download import download_testdata
+    from PIL import Image
+    import numpy as np
+
+    cat_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
+    image_path = download_testdata(cat_url, 'imagenet_cat.png', module='data')
+    resized_image = Image.open(image_path).resize((224, 224))
+    image_data = np.asarray(resized_image).astype("float32")
+    image_data = np.expand_dims(image_data, axis=0)
+
+    np.savez("imagenet_cat", input=image_data)

Review comment:
       I agree it makes sense to declare extra set of dependencies, these are the deps we setup the frontend anyway




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
comaniac commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-663678802


   Thanks for the PR! Since CLI itself serves as an infra, it would be better to break this PR to a series of PRs like the following:
   
   - PR1: The basic CLI infra mainly including 1) CLI setup, 2) the registration mechanism, and 3) the document.
   - PR2: CLI -- compile.
   - PR3: CLI -- run.
   - PR4: CLI -- tune.
   
   In this way, people can focus on the overall CLI infra in the first PR. Once everyone is happy with it, the rest PRs would have a much clearer scope. For example, "CLI -- compile" would attract people who are familiar with compilation flow. In this way, we can expect the following advantages:
   
   1. We can focus on what functions/options should be included in a scope.
   2. We can focus on the implementation of those functions/options in each scope. For example, I've seen many redundant/similar functions implemented in `tvmc` and I believe some of them should reuse the existing ones in TVM.
   3. The CLI PRs can be sent and reviewed in parallel, and they won't block each other.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-663667667


   cc @merrymercy @jroesch @ajtulloch @comaniac 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468076880



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="tvm compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    # TODO: subparsers will come in follow-up patches (@leandron)
+    _ = parser.add_subparsers(title="commands")
+
+    args = parser.parse_args(argv)
+    if args.verbose > 4:
+        args.verbose = 4
+
+    logging.getLogger().setLevel(40 - args.verbose * 10)
+
+    if args.version:
+        version = pkg_resources.get_distribution("tvm").version
+        sys.stdout.write("%s\n" % version)
+        return 0
+
+    if not hasattr(args, "func"):
+        parser.error("missing subcommand")

Review comment:
       Since you don't have any subparser in this PR, I guess you will require each subparser to define an argument `func` and set its default value to the entry function. IIUC, this is a pure internal error and the error message has to be improved.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468109265



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="tvm compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    # TODO: subparsers will come in follow-up patches (@leandron)
+    _ = parser.add_subparsers(title="commands")
+
+    args = parser.parse_args(argv)
+    if args.verbose > 4:
+        args.verbose = 4
+
+    logging.getLogger().setLevel(40 - args.verbose * 10)
+
+    if args.version:
+        version = pkg_resources.get_distribution("tvm").version
+        sys.stdout.write("%s\n" % version)
+        return 0
+
+    if not hasattr(args, "func"):
+        parser.error("missing subcommand")

Review comment:
       make sense.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] comaniac commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468122151



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def add_help_parser(subparsers):
+    """ Include parser for 'help' subcommand """
+
+    parser = subparsers.add_parser("help", help="show help page")
+    # 'func' points to a function that will receive all the arguments
+    # provided by the user. This is the only required attribute
+    parser.set_defaults(func=drive_help)
+
+
+def drive_help(args):
+    """ Show help page """
+
+    print("This is a placeholder command. Args = {0}".format(args))
+
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="TVM compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    subparsers = parser.add_subparsers(title="commands")
+
+    add_help_parser(subparsers)

Review comment:
       Based on this I imagine we will have the following in the future:
   ```python
   add_help_parser(subparsers)
   add_compile_parser(subparsers)
   add_tune_parser(subparsers)
   # ...
   ```
   
   And maybe we will have something like `tvmc/compile.py`, and have `from compile import add_compile_parser` in this file.
   
   IIUC, we can setup a registration mechanism as follow, although I'm not sure if it's overkilled:
   
   In `main.py`:
   
   ```python
   REGISTERED_PARSER = []
   def register_parser(make_subparser):
       REGISTERED_PARSER.append(make_subparser)
       return make_subparser
   
   def _main(argv):
       subparser = parser.add_subparsers()
       for make_subparser in REGISTERED_PARSER:
         make_subparser(subparser)
   ```
   
   In `compile.py`:
   
   ```python
   from main import register_parser
   
   @register_parser
   def _compile_parser(main_subparser):
       subparser = main_subparser.add_parser('compile', help='...')
       # ...
   ```
   
   In this way, we don't need to touch `main.py` anymore when we add a new subparser.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen merged pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
tqchen merged pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-671295731


   @comaniac here is a new version of this patch with only the minimal code to enable the command line. Follow up patches, that I will send after this, will deal with `compile`, `run` and `tune` functionalities.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
leandron commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-668637049


   > Thanks for the PR! Since CLI itself serves as an infra, it would be better to break this PR to a series of PRs like the following:
   
   Sure @comaniac, will do.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r469256872



##########
File path: Jenkinsfile
##########
@@ -167,6 +167,7 @@ stage('Build') {
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_vta_tsim.sh"
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_golang.sh"
           sh "${docker_run} ${ci_cpu} ./tests/scripts/task_rust.sh"
+          sh "${docker_run} ${ci_cpu} ./tests/scripts/task_python_tvmc.sh"

Review comment:
       with the new approach, `tvmc` tests will be embedded on `tvm` python  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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
leandron commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-662561133


   If possible, I'll be presenting a live demo today on the "Online Compiler Chat".


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] LiyouZhou edited a comment on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
LiyouZhou edited a comment on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-670047293


   The command name`tvmc` sounds strange, it is not immediately obvious what the c stands for. Can the shell command be called just `tvm compile` `tvm tune` etc. same as [aws cli](https://aws.amazon.com/cli/) or [github cli](https://github.com/cli/cli).


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468454560



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def add_help_parser(subparsers):
+    """ Include parser for 'help' subcommand """
+
+    parser = subparsers.add_parser("help", help="show help page")
+    # 'func' points to a function that will receive all the arguments
+    # provided by the user. This is the only required attribute
+    parser.set_defaults(func=drive_help)
+
+
+def drive_help(args):
+    """ Show help page """
+
+    print("This is a placeholder command. Args = {0}".format(args))
+
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="TVM compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    subparsers = parser.add_subparsers(title="commands")
+
+    add_help_parser(subparsers)

Review comment:
       I think it works. It just moves some logic that was concentrated in `main`, to the respective subcommand implementer files such as `compile.py` and `runner.py` (to come in next PRs, once this gets merged).
   
   I will update it accordingly.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] LiyouZhou commented on pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
LiyouZhou commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-670047293


   The command name`tvmc` sounds strange, it is not immediately obvious what the c stands for. Can the shell command be called just `tvm compile` `tvm tune` etc. Like [aws cli](https://aws.amazon.com/cli/) or [github cli](https://github.com/cli/cli).


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-673171327


   cc @jroesch @yzhliu @icemelon9 @junrushao1994 


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r461597250



##########
File path: tvmc/README.md
##########
@@ -0,0 +1,122 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVMC
+
+```tvmc``` is a tool that provides useful command line invocations to compile,
+run and tune models using TVM graph runtime.
+
+In order to compile and tune, ```tvmc``` takes a model file and parameters as inputs,
+and outputs a TAR file that contains the TVM modules that represent the
+input model, graph and weights, for the required target. Target can be native or
+cross-compiled.
+
+When running a given model, ```tvmc``` expects a compiled model and input tensor values, so
+that it can produce the outputs, when running on the required target, local or remote.
+
+This document presents an overview and a short tutorial about ```tvmc```.
+
+## Installation
+
+```tvmc``` is a Python tool and - provided TVM and dependencies are available - it can be
+installed in various ways.
+
+The recommended way to install ```tvmc``` is via it's ```setuptools``` configuration file,
+located at ```tvm/tvmc/setup.py```. To do that, go to the the TVM directory and run the
+installation command, as described below:
+
+    cd tvm/tvmc
+    python setup.py install
+
+The command above should install everything needed to get started with ```tvmc```, including
+all the the supported frontends.
+
+Once ```tvmc``` is installed, the main entry-point is the ```tvmc``` command line. A set of
+sub-commands are available, to run the specific tasks offered by ```tvmc```: ```tune```,
+```compile``` and ```run```.
+
+The simplest way to get more information about a specific sub-command is ```tvmc <subcommand>
+-- help```.
+
+    tvmc compile --help
+
+##  Usage
+
+Now, let's compile a network and generate a few predictions using ```tvmc```.
+
+As described above, in order to compile a model using ```tvmc```, the first thing we need is
+a model file. For the sake of this example, let's use a MobileNet V1 model, in TFLite format.
+More information about the model is available on
+[this page](https://www.tensorflow.org/lite/guide/hosted_models).
+
+To download and un-compress the ```.tgz``` file (34Mb), so that we can access the TFLite model,
+run the command lines below:
+
+    wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz
+    tar xvzf mobilenet_v1_1.0_224_quant.tgz
+
+With these commands, we should be able to provide the MobileNet V1 file (```mobilenet_v1_1.0_224_quant.tflite```)
+to ```tvmc```, and obtain our TVM compiled model as an output. To do that, run the
+following command line:
+
+    tvmc compile -v mobilenet_v1_1.0_224_quant.tflite -o compiled_model.tar
+
+As an output, you will notice a ```compiled_model.tar```, in the same directory.
+
+Now it is time to feed the model with some input, that will generate a prediction using TVM.
+As models are very diverse in terms of input formats and the source of those inputs (images, streams,
+sensors, sound, to name a few), ```tvmc``` supports ```.npz``` (serialized NumPy arrays) as the
+main format for ```tvmc run```. To learn more about the ```.npz``` format, please read the
+[documentation](https://numpy.org/doc/stable/reference/generated/numpy.savez.html) on NumPy website.
+
+MobileNet V1 expects a ```(224, 224, 3)``` input tensor. The Python code snippet below, can be used
+as an example on how to convert a PNG file into a ```.npz``` file in the expected shape.
+The example below uses [PIL](https://pillow.readthedocs.io/en/stable/) and
+[NumPy](https://numpy.org) functions to import the image and generate the expected file.
+
+    from tvm.contrib.download import download_testdata
+    from PIL import Image
+    import numpy as np
+
+    cat_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
+    image_path = download_testdata(cat_url, 'imagenet_cat.png', module='data')
+    resized_image = Image.open(image_path).resize((224, 224))
+    image_data = np.asarray(resized_image).astype("float32")
+    image_data = np.expand_dims(image_data, axis=0)
+
+    np.savez("imagenet_cat", input=image_data)

Review comment:
       We considered that choice of "inside or outside the existing tvm/python", as well as the decision to publish the command line in the same Python package as TVM or in a different one.
   
   The main reason for the current choice, is to have a different (more comprehensive) set of Python dependencies, that would allow the user to have everything they need to run tuning, compilations and predictions, without the need of installing and thinking about ad-hoc dependencies, such as tensorflow, tflite, keras, onnx, pytorch, etc.
   
   As you can see on the proposed `setup.py`, we add the dependencies for all the supported frontends, which I understand are intentionally left out the current TVM Python package.
   
   What do you think? I suggest, if we are to move the driver to be inside the TVM package, would you agree with having the `tvm.driver` with a set of _optional dependencies_[1] (it is a feature from `setuptools`), so that we can provide a simple way for the end user to install these dependencies? Otherwise, I would suggest we keep them as separate packages.
   
   [1] https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] tqchen commented on pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
tqchen commented on pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#issuecomment-674555908


   Thanks @leandron @comaniac this PR is now merged


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r465129667



##########
File path: tvmc/README.md
##########
@@ -0,0 +1,122 @@
+<!--- Licensed to the Apache Software Foundation (ASF) under one -->
+<!--- or more contributor license agreements.  See the NOTICE file -->
+<!--- distributed with this work for additional information -->
+<!--- regarding copyright ownership.  The ASF licenses this file -->
+<!--- to you under the Apache License, Version 2.0 (the -->
+<!--- "License"); you may not use this file except in compliance -->
+<!--- with the License.  You may obtain a copy of the License at -->
+
+<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
+
+<!--- Unless required by applicable law or agreed to in writing, -->
+<!--- software distributed under the License is distributed on an -->
+<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
+<!--- KIND, either express or implied.  See the License for the -->
+<!--- specific language governing permissions and limitations -->
+<!--- under the License. -->
+
+# TVMC
+
+```tvmc``` is a tool that provides useful command line invocations to compile,
+run and tune models using TVM graph runtime.
+
+In order to compile and tune, ```tvmc``` takes a model file and parameters as inputs,
+and outputs a TAR file that contains the TVM modules that represent the
+input model, graph and weights, for the required target. Target can be native or
+cross-compiled.
+
+When running a given model, ```tvmc``` expects a compiled model and input tensor values, so
+that it can produce the outputs, when running on the required target, local or remote.
+
+This document presents an overview and a short tutorial about ```tvmc```.
+
+## Installation
+
+```tvmc``` is a Python tool and - provided TVM and dependencies are available - it can be
+installed in various ways.
+
+The recommended way to install ```tvmc``` is via it's ```setuptools``` configuration file,
+located at ```tvm/tvmc/setup.py```. To do that, go to the the TVM directory and run the
+installation command, as described below:
+
+    cd tvm/tvmc
+    python setup.py install
+
+The command above should install everything needed to get started with ```tvmc```, including
+all the the supported frontends.
+
+Once ```tvmc``` is installed, the main entry-point is the ```tvmc``` command line. A set of
+sub-commands are available, to run the specific tasks offered by ```tvmc```: ```tune```,
+```compile``` and ```run```.
+
+The simplest way to get more information about a specific sub-command is ```tvmc <subcommand>
+-- help```.
+
+    tvmc compile --help
+
+##  Usage
+
+Now, let's compile a network and generate a few predictions using ```tvmc```.
+
+As described above, in order to compile a model using ```tvmc```, the first thing we need is
+a model file. For the sake of this example, let's use a MobileNet V1 model, in TFLite format.
+More information about the model is available on
+[this page](https://www.tensorflow.org/lite/guide/hosted_models).
+
+To download and un-compress the ```.tgz``` file (34Mb), so that we can access the TFLite model,
+run the command lines below:
+
+    wget https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz
+    tar xvzf mobilenet_v1_1.0_224_quant.tgz
+
+With these commands, we should be able to provide the MobileNet V1 file (```mobilenet_v1_1.0_224_quant.tflite```)
+to ```tvmc```, and obtain our TVM compiled model as an output. To do that, run the
+following command line:
+
+    tvmc compile -v mobilenet_v1_1.0_224_quant.tflite -o compiled_model.tar
+
+As an output, you will notice a ```compiled_model.tar```, in the same directory.
+
+Now it is time to feed the model with some input, that will generate a prediction using TVM.
+As models are very diverse in terms of input formats and the source of those inputs (images, streams,
+sensors, sound, to name a few), ```tvmc``` supports ```.npz``` (serialized NumPy arrays) as the
+main format for ```tvmc run```. To learn more about the ```.npz``` format, please read the
+[documentation](https://numpy.org/doc/stable/reference/generated/numpy.savez.html) on NumPy website.
+
+MobileNet V1 expects a ```(224, 224, 3)``` input tensor. The Python code snippet below, can be used
+as an example on how to convert a PNG file into a ```.npz``` file in the expected shape.
+The example below uses [PIL](https://pillow.readthedocs.io/en/stable/) and
+[NumPy](https://numpy.org) functions to import the image and generate the expected file.
+
+    from tvm.contrib.download import download_testdata
+    from PIL import Image
+    import numpy as np
+
+    cat_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
+    image_path = download_testdata(cat_url, 'imagenet_cat.png', module='data')
+    resized_image = Image.open(image_path).resize((224, 224))
+    image_data = np.asarray(resized_image).astype("float32")
+    image_data = np.expand_dims(image_data, axis=0)
+
+    np.savez("imagenet_cat", input=image_data)

Review comment:
       I was working on this in the last days and in recent discussions realised that only moving the driver (a.k.a. `tvmc`) into `tvm.driver`, without sorting out the global TVM dependency issues, is not a good solution for the end-user.
   
   The target here is to get into a situation, in which `pip install tvm` or `pip install tvmc` gives you a fully functional TVM out-of-the-box. This is not the case if we define a set of _optional dependencies_. My original suggestion is not good enough to solve that, and the user will get a broken CLI-frontend if dependencies are not there.
   
   It is not good practice to request the user to manually install dependencies for supported frontends, that are required for the driver to work.
   
   Based on that, I see two options:
   
   1) move `tvmc` into `tvm.driver` (as sugested here) and sort out dependencies on the global TVM Python package (add frontends such as tensorflow and onnx as dependencies) <-- my favourite, can deal with the pull request to update dependencies
   
   2) separate packages for `tvm` and `tvmc`. `tvmc` includes all the frontends plus `tvm` as a dependency. Rely on tests to make sure main TVM doesn't break the driver.
   
   I'm happy to hear alternatives that would preserve functionality, reduce the complexity of installing TVM and provide a smooth end-user usage, as proposed here




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [incubator-tvm] leandron commented on a change in pull request #6112: TVMC - a command line driver for TVM (Part 1)

Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #6112:
URL: https://github.com/apache/incubator-tvm/pull/6112#discussion_r468104675



##########
File path: python/tvm/driver/tvmc/main.py
##########
@@ -0,0 +1,74 @@
+#!/usr/bin/env python
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+TVMC - TVM driver command-line interface
+"""
+import argparse
+import logging
+import sys
+
+import pkg_resources
+
+from tvm.driver.tvmc.common import TVMCException
+
+
+def _main(argv):
+    """ TVM command line interface. """
+
+    parser = argparse.ArgumentParser(
+        prog='tvmc',
+        formatter_class=argparse.RawDescriptionHelpFormatter,
+        description="tvm compiler driver",
+        epilog=__doc__,
+    )
+    parser.add_argument(
+        "-v", "--verbose", action="count", default=0, help="increase verbosity"
+    )
+    parser.add_argument(
+        "--version", action="store_true", help="print the version and exit"
+    )
+
+    # TODO: subparsers will come in follow-up patches (@leandron)
+    _ = parser.add_subparsers(title="commands")
+
+    args = parser.parse_args(argv)
+    if args.verbose > 4:
+        args.verbose = 4
+
+    logging.getLogger().setLevel(40 - args.verbose * 10)
+
+    if args.version:
+        version = pkg_resources.get_distribution("tvm").version
+        sys.stdout.write("%s\n" % version)
+        return 0
+
+    if not hasattr(args, "func"):
+        parser.error("missing subcommand")

Review comment:
       Reading that again, it seems most cases will be covered by `argparse` and that should really be an assert, because lacking a `func` only is expected to happen during development.




----------------------------------------------------------------
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:
users@infra.apache.org