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 2021/12/03 22:24:33 UTC

[GitHub] [tvm] hogepodge commented on a change in pull request #9633: Tvmc python tutorial

hogepodge commented on a change in pull request #9633:
URL: https://github.com/apache/tvm/pull/9633#discussion_r762321000



##########
File path: gallery/how_to/use_tvms_python_api/tvmc_python.py
##########
@@ -0,0 +1,252 @@
+# 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.
+"""
+Getting Starting using TVMC Python: a high-level API for TVM
+=============================================================
+**Author**:
+`Jocelyn Shiue <https://github.com/CircleSpin>`_,
+
+Welcome to TVMC Python
+======================
+Hi! Here we explain the scripting tool designed for the complete TVM beginner. 🙂 
+
+Before we get started let's get an example model if you don't already have one.
+Follow the steps to download a resnet model via the terminal:
+
+ .. code-block:: bash
+
+     mkdir myscripts
+     cd myscripts
+     wget https://github.com/onnx/models/raw/master/vision/classification/resnet/model/resnet50-v2-7.onnx
+     mv resnet50-v2-7.onnx my_model.onnx
+     touch tvmcpythonintro.py
+
+Let's start editing the python file in your favorite text editor.
+
+################################################################################
+# Step 0: Imports
+# ---------------
+# 
+# .. code-block:: python
+#
+#     from tvm.driver import tvmc
+#
+
+################################################################################
+# Step 1: Load a model
+# --------------------
+#
+# Let's import our model into tvmc. This step converts a machine learning model from 
+# a supported framework into TVM's high level graph representation language called relay. 
+# This is to have a unified starting point for all models in tvm. The frameworks we currently 
+# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
+# 
+# .. code-block:: python
+#      model = tvmc.load('my_model.onnx') #Step 1: Load
+# 
+# If you'd like to see the relay, you can run: 
+# ``model.summary()``
+# 
+# All frameworks support over writing the input shapes with a shape_dict argument. 
+# For most frameworks this is optional but for Pytorch this is necessary. 
+#
+# .. code-block:: python
+#      ### Step 1: Load shape_dict Style 
+#      # shape_dict = {'model_input_name1': [1, 3, 224, 224], 'input2': [1, 2, 3, 4], ...} #example format with random numbers
+#      # model = tvmc.load(model_path, shape_dict=shape_dict) #Step 1: Load + shape_dict
+# 
+# One way to see the model's input/shape_dict is via `netron <https://netron.app/>`_, . After opening the model, 
+# click the first node to see the name(s) and shape(s) in the inputs section.
+
+
+################################################################################
+# Step 2: Compile
+# ----------------
+# Now that our model is in relay, our next step is to compile it to a desired 

Review comment:
       Thinking out loud here, for documentation we should starting thinking about a style guide for named parts of TVM. Should it be `Relay` or `relay`? Our choice should be consistently applied throughout the project.

##########
File path: gallery/how_to/use_tvms_python_api/tvmc_python.py
##########
@@ -0,0 +1,252 @@
+# 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.
+"""
+Getting Starting using TVMC Python: a high-level API for TVM
+=============================================================
+**Author**:
+`Jocelyn Shiue <https://github.com/CircleSpin>`_,
+
+Welcome to TVMC Python
+======================
+Hi! Here we explain the scripting tool designed for the complete TVM beginner. 🙂 
+
+Before we get started let's get an example model if you don't already have one.
+Follow the steps to download a resnet model via the terminal:
+
+ .. code-block:: bash
+
+     mkdir myscripts
+     cd myscripts
+     wget https://github.com/onnx/models/raw/master/vision/classification/resnet/model/resnet50-v2-7.onnx
+     mv resnet50-v2-7.onnx my_model.onnx
+     touch tvmcpythonintro.py
+
+Let's start editing the python file in your favorite text editor.
+
+################################################################################
+# Step 0: Imports
+# ---------------
+# 
+# .. code-block:: python
+#
+#     from tvm.driver import tvmc
+#
+
+################################################################################
+# Step 1: Load a model
+# --------------------
+#
+# Let's import our model into tvmc. This step converts a machine learning model from 
+# a supported framework into TVM's high level graph representation language called relay. 
+# This is to have a unified starting point for all models in tvm. The frameworks we currently 
+# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
+# 
+# .. code-block:: python
+#      model = tvmc.load('my_model.onnx') #Step 1: Load
+# 
+# If you'd like to see the relay, you can run: 
+# ``model.summary()``
+# 
+# All frameworks support over writing the input shapes with a shape_dict argument. 
+# For most frameworks this is optional but for Pytorch this is necessary. 
+#
+# .. code-block:: python
+#      ### Step 1: Load shape_dict Style 
+#      # shape_dict = {'model_input_name1': [1, 3, 224, 224], 'input2': [1, 2, 3, 4], ...} #example format with random numbers
+#      # model = tvmc.load(model_path, shape_dict=shape_dict) #Step 1: Load + shape_dict
+# 
+# One way to see the model's input/shape_dict is via `netron <https://netron.app/>`_, . After opening the model, 
+# click the first node to see the name(s) and shape(s) in the inputs section.
+
+
+################################################################################
+# Step 2: Compile
+# ----------------
+# Now that our model is in relay, our next step is to compile it to a desired 
+# hardware to run on. We refer to this hardware as a target. This compilation process 
+# translates the model from relay into a lower-level language that the 
+# target machine can understand. 

Review comment:
       I like this sentence. :-) 

##########
File path: gallery/how_to/use_tvms_python_api/tvmc_python.py
##########
@@ -0,0 +1,252 @@
+# 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.
+"""
+Getting Starting using TVMC Python: a high-level API for TVM
+=============================================================
+**Author**:
+`Jocelyn Shiue <https://github.com/CircleSpin>`_,
+
+Welcome to TVMC Python
+======================
+Hi! Here we explain the scripting tool designed for the complete TVM beginner. 🙂 
+
+Before we get started let's get an example model if you don't already have one.
+Follow the steps to download a resnet model via the terminal:
+
+ .. code-block:: bash
+
+     mkdir myscripts
+     cd myscripts
+     wget https://github.com/onnx/models/raw/master/vision/classification/resnet/model/resnet50-v2-7.onnx
+     mv resnet50-v2-7.onnx my_model.onnx
+     touch tvmcpythonintro.py
+
+Let's start editing the python file in your favorite text editor.
+
+################################################################################
+# Step 0: Imports
+# ---------------
+# 
+# .. code-block:: python
+#
+#     from tvm.driver import tvmc
+#
+
+################################################################################
+# Step 1: Load a model
+# --------------------
+#
+# Let's import our model into tvmc. This step converts a machine learning model from 
+# a supported framework into TVM's high level graph representation language called relay. 
+# This is to have a unified starting point for all models in tvm. The frameworks we currently 
+# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
+# 
+# .. code-block:: python
+#      model = tvmc.load('my_model.onnx') #Step 1: Load
+# 
+# If you'd like to see the relay, you can run: 
+# ``model.summary()``
+# 
+# All frameworks support over writing the input shapes with a shape_dict argument. 
+# For most frameworks this is optional but for Pytorch this is necessary. 

Review comment:
       I would explain why a bit here

##########
File path: gallery/how_to/use_tvms_python_api/tvmc_python.py
##########
@@ -0,0 +1,252 @@
+# 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.
+"""
+Getting Starting using TVMC Python: a high-level API for TVM
+=============================================================
+**Author**:
+`Jocelyn Shiue <https://github.com/CircleSpin>`_,
+
+Welcome to TVMC Python
+======================
+Hi! Here we explain the scripting tool designed for the complete TVM beginner. 🙂 
+
+Before we get started let's get an example model if you don't already have one.
+Follow the steps to download a resnet model via the terminal:
+
+ .. code-block:: bash
+
+     mkdir myscripts
+     cd myscripts
+     wget https://github.com/onnx/models/raw/master/vision/classification/resnet/model/resnet50-v2-7.onnx
+     mv resnet50-v2-7.onnx my_model.onnx
+     touch tvmcpythonintro.py
+
+Let's start editing the python file in your favorite text editor.
+
+################################################################################
+# Step 0: Imports
+# ---------------
+# 
+# .. code-block:: python
+#
+#     from tvm.driver import tvmc
+#
+
+################################################################################
+# Step 1: Load a model
+# --------------------
+#
+# Let's import our model into tvmc. This step converts a machine learning model from 
+# a supported framework into TVM's high level graph representation language called relay. 
+# This is to have a unified starting point for all models in tvm. The frameworks we currently 
+# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
+# 
+# .. code-block:: python
+#      model = tvmc.load('my_model.onnx') #Step 1: Load
+# 
+# If you'd like to see the relay, you can run: 
+# ``model.summary()``
+# 
+# All frameworks support over writing the input shapes with a shape_dict argument. 

Review comment:
       overwriting

##########
File path: gallery/how_to/use_tvms_python_api/tvmc_python.py
##########
@@ -0,0 +1,252 @@
+# 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.
+"""
+Getting Starting using TVMC Python: a high-level API for TVM
+=============================================================
+**Author**:
+`Jocelyn Shiue <https://github.com/CircleSpin>`_,
+
+Welcome to TVMC Python
+======================
+Hi! Here we explain the scripting tool designed for the complete TVM beginner. 🙂 
+
+Before we get started let's get an example model if you don't already have one.
+Follow the steps to download a resnet model via the terminal:
+
+ .. code-block:: bash
+
+     mkdir myscripts
+     cd myscripts
+     wget https://github.com/onnx/models/raw/master/vision/classification/resnet/model/resnet50-v2-7.onnx
+     mv resnet50-v2-7.onnx my_model.onnx
+     touch tvmcpythonintro.py
+
+Let's start editing the python file in your favorite text editor.
+
+################################################################################
+# Step 0: Imports
+# ---------------
+# 
+# .. code-block:: python
+#
+#     from tvm.driver import tvmc
+#
+
+################################################################################
+# Step 1: Load a model
+# --------------------
+#
+# Let's import our model into tvmc. This step converts a machine learning model from 
+# a supported framework into TVM's high level graph representation language called relay. 
+# This is to have a unified starting point for all models in tvm. The frameworks we currently 
+# support are: Keras, ONNX, Tensorflow, TFLite, and PyTorch.
+# 
+# .. code-block:: python
+#      model = tvmc.load('my_model.onnx') #Step 1: Load
+# 
+# If you'd like to see the relay, you can run: 
+# ``model.summary()``
+# 
+# All frameworks support over writing the input shapes with a shape_dict argument. 
+# For most frameworks this is optional but for Pytorch this is necessary. 
+#
+# .. code-block:: python
+#      ### Step 1: Load shape_dict Style 
+#      # shape_dict = {'model_input_name1': [1, 3, 224, 224], 'input2': [1, 2, 3, 4], ...} #example format with random numbers
+#      # model = tvmc.load(model_path, shape_dict=shape_dict) #Step 1: Load + shape_dict
+# 
+# One way to see the model's input/shape_dict is via `netron <https://netron.app/>`_, . After opening the model, 

Review comment:
       Add something like "you can use Netron to investigate the model's input shape if you're unsure of what it is..."




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

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