Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
CMSC5743 Lab 06TVM Tutorial-2 Materials
Yang BAIDepartment of Computer Science & EngineeringChinese University of Hong [email protected]
December 3, 2021
1 TVM Installation
2 Compile PyTorch Model by TVM
3 Homework
Outline
2/19
TVM Installation
• Recommended System: MAC OS or Linux.
• LLVM 9.0+
• git clone –recursive https://github.com/apache/tvm tvm
• mkdir build
• cp cmake/config.cmake build
• open the LLVM option
• cmake ..
• make -j10
TVM Installation
4/19
• vim ~/.bashrc or ~/.bash_profile
• export TVM_HOME=/Users/baiyang/Documents/Project/tvm
• export PYTHONPATH=$TVM_HOME/python:$PYTHONPATH
TVM Environment Setup
5/19
• pip install torch==1.7.0
• pip install torchvision==0.8.1
PyTorch and PIL Installation
6/19
• import tvm
• tvm.__version__
• from PIL import Image
• import torch
• import torchvision
Verify the correct installaltion
7/19
Compile PyTorch Model by TVM
• Load a pretrained PyTorch model
• Load a test image
• Import the graph to Relay
• Relay Build
• Execute the portable graph on TVM
• Look up synset name
Compile PyTorch Model by TVM
9/19
TVM Overview
10/19
• resnet18
• torchvision
Load a pretrained PyTorch model
11/19
• img_url
• Preprocess the image and convert to tensor
Load a test image
12/19
• relay.frontend.from_pytorch
• relay.frontend.from_tensorflow
• relay.frontend.from_mxnet
• relay.frontend.onnx
Import the graph to Relay
13/19
• target
• target_host
• relay.build
Relay Build
14/19
• Set inputs
• Execute
• Get outputs
Execute the portable graph on TVM
15/19
• imagenet_synsets.txt
• Get top-1 result for TVM
• Get top-1 result for PyTorch
• Convert input to PyTorch variable and get PyTorch result for comparison
Look up synset name
16/19
Homework
• Change the img_path in your datapath and get the correct recognition
• Change the model_name in torchvision
• Record the final prediction of your change
Homwork
18/19
THANK YOU!