leandron commented on a change in pull request #7641: URL: https://github.com/apache/tvm/pull/7641#discussion_r593247554
########## File path: tutorials/get_started/auto_tuning_with_python.py ########## @@ -0,0 +1,446 @@ +# 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. +""" +Compiling and Optimizing a Model with the Python AutoScheduler +============================================================== +**Author**: +`Chris Hoge <https://github.com/hogepodge>`_ + +In the `TVMC Tutorial <>`_, we covered how to compile, run, and tune a +pre-trained vision model, ResNet-50-v2 using the command line interface for +TVM, TVMC. TVM is more that just a command-line tool though, it is an +optimizing framework with APIs available for a number of different languages +that gives you tremendous flexibility in working with machine learning models. + +In this tutorial we will cover the same ground we did with TVMC, but show how +it is done with the Python API. Upon completion of this section, we will ahve +used the Python API for TVM to accomplish the following tasks: + +* Compile a pre-trained ResNet 50 v2 model for the TVM runtime. +* Run a real image through the compiled model, and interpret the output and model + performance. +* Tune the model that model on a CPU using TVM. +* Re-compile an optimized model using the tuning data collected by TVM. +* Run the image through the optimized model, and compare the output and model + performance. + +The goal of this section is to give you an overview of TVM's capabilites and +how to use them through the Python API. +""" + +################################################################################ +# TVM is a deep learning compiler framework, with a number of different modules +# available for working with deep learning models and operators. In this +# tutorial we will work through how to load, compile, and optimize a model +# using the Python API. +# +# We begin by importing a number of dependencies, including ``onnx`` for +# loading and converting the model, helper utilities for downloading test data, +# the Python Image Library for working with the image data, ``numpy`` for pre +# and post-processing of the image data, the TVM Relay framework, and the TVM +# Graph Runtime. +# + +import onnx +from tvm.contrib.download import download_testdata +from PIL import Image +import numpy as np +import tvm.relay as relay +import tvm +from tvm.contrib import graph_runtime +import timeit Review comment: Maybe, for clarity, lazy import `timeit` it when you're discussing performance, similar to what it is done in the training section? (see comments below, mentioning specific points) ---------------------------------------------------------------- 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: [email protected]
