Skip to content

Commit

Permalink
Fix how_to/compile_models to work in Colab
Browse files Browse the repository at this point in the history
  • Loading branch information
guberti committed Dec 14, 2022
1 parent fa60de8 commit 0367b41
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 29 deletions.
7 changes: 3 additions & 4 deletions gallery/how_to/compile_models/from_coreml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
This article is an introductory tutorial to deploy CoreML models with Relay.
For us to begin with, coremltools module is required to be installed.
A quick solution is to install via pip
To begin, we must install coremltools and Apache TVM:
.. code-block:: bash
pip install -U coremltools --user
%%shell
pip install apache-tvm coremltools
or please refer to official site
https://github.com/apple/coremltools
Expand Down
5 changes: 3 additions & 2 deletions gallery/how_to/compile_models/from_darknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
.. code-block:: bash
pip install cffi
pip install opencv-python
%%shell
pip install apache-tvm cffi opencv-python
"""

# sphinx_gallery_start_ignore
Expand Down
10 changes: 5 additions & 5 deletions gallery/how_to/compile_models/from_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
=====================
**Author**: `Yuwei Hu <https://Huyuwei.github.io/>`_
This article is an introductory tutorial to deploy keras models with Relay.
This article is an introductory tutorial to deploy Keras models with Relay.
For us to begin with, keras should be installed.
Tensorflow is also required since it's used as the default backend of keras.
Expand All @@ -28,8 +28,8 @@
.. code-block:: bash
pip install -U keras --user
pip install -U tensorflow --user
%%shell
pip install apache-tvm keras tensorflow
or please refer to official site
https://keras.io/#installation
Expand Down Expand Up @@ -102,8 +102,8 @@
shape_dict = {"input_1": data.shape}
mod, params = relay.frontend.from_keras(keras_resnet50, shape_dict)
# compile the model
target = "cuda"
dev = tvm.cuda(0)
target = "llvm"
dev = tvm.cpu(0)

# TODO(mbs): opt_level=3 causes nn.contrib_conv2d_winograd_weight_transform
# to end up in the module which fails memory validation on cuda most likely
Expand Down
11 changes: 5 additions & 6 deletions gallery/how_to/compile_models/from_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
This article is an introductory tutorial to deploy mxnet models with Relay.
For us to begin with, mxnet module is required to be installed.
A quick solution is
To begin, we must install `mxnet` and `apache-tvm`:
.. code-block:: bash
pip install mxnet --user
%%shell
pip install apache-tvm mxnet
or please refer to official installation guide.
https://mxnet.apache.org/versions/master/install/index.html
Expand Down Expand Up @@ -102,7 +101,7 @@ def transform_image(image):

######################################################################
# now compile the graph
target = "cuda"
target = tvm.target.Target("llvm")
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(func, target, params=params)

Expand All @@ -112,7 +111,7 @@ def transform_image(image):
# Now, we would like to reproduce the same forward computation using TVM.
from tvm.contrib import graph_executor

dev = tvm.cuda(0)
dev = tvm.cpu(0)
dtype = "float32"
m = graph_executor.GraphModule(lib["default"](dev))
# set inputs
Expand Down
9 changes: 5 additions & 4 deletions gallery/how_to/compile_models/from_oneflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
.. code-block:: bash
%%shell
pip install apache-tvm
pip install flowvision==0.1.0
python3 -m pip install -f https://release.oneflow.info oneflow==0.7.0+cpu
pip install -f https://release.oneflow.info oneflow==0.7.0+cpu
or please refer to official site:
https://github.com/Oneflow-Inc/oneflow
Expand Down Expand Up @@ -113,7 +115,7 @@ def build(self, x):
# Relay Build
# -----------
# Compile the graph to llvm target with given input specification.
target = tvm.target.Target("llvm", host="llvm")
target = tvm.target.Target("llvm")
dev = tvm.cpu(0)
with tvm.transform.PassContext(opt_level=3):
lib = relay.build(mod, target=target, params=params)
Expand All @@ -122,9 +124,8 @@ def build(self, x):
# Execute the portable graph on TVM
# ---------------------------------
# Now we can try deploying the compiled model on target.
target = "cuda"
with tvm.transform.PassContext(opt_level=10):
intrp = relay.build_module.create_executor("graph", mod, tvm.cuda(0), target)
intrp = relay.build_module.create_executor("graph", mod, tvm.cpu(0), target)

print(type(img))
print(img.shape)
Expand Down
3 changes: 2 additions & 1 deletion gallery/how_to/compile_models/from_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
.. code-block:: bash
pip install --user onnx onnxoptimizer
%%shell
pip install apache-tvm onnx onnxoptimizer
or please refer to official site.
https://github.com/onnx/onnx
Expand Down
6 changes: 4 additions & 2 deletions gallery/how_to/compile_models/from_paddle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
**Author**: `Ziyuan Ma <https://github.com/ZiyuanMa/>`_
This article is an introductory tutorial to deploy PaddlePaddle models with Relay.
For us to begin with, PaddlePaddle>=2.1.3 is required to be installed.
To begin, we'll install Apache TVM and PaddlePaddle>=2.1.3.
A quick solution is
.. code-block:: bash
%%shell
pip install apache-tvm
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
or please refer to official site.
For more details, refer to the official install instructions at:
https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/linux-pip.html
"""

Expand Down
2 changes: 2 additions & 0 deletions gallery/how_to/compile_models/from_pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
.. code-block:: bash
%%shell
pip install apache-tvm
pip install torch==1.7.0
pip install torchvision==0.8.1
Expand Down
5 changes: 5 additions & 0 deletions gallery/how_to/compile_models/from_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
For us to begin with, tensorflow python module is required to be installed.
.. code-block:: bash
%%bash
pip install apache-tvm tensorflow
Please refer to https://www.tensorflow.org/install
"""

Expand Down
5 changes: 2 additions & 3 deletions gallery/how_to/compile_models/from_tflite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
.. code-block:: bash
# install tflite
pip install tflite==2.1.0 --user
%%shell
pip install apache-tvm tflite==2.1.0
or you could generate TFLite package yourself. The steps are the following:
Expand Down
4 changes: 2 additions & 2 deletions gallery/how_to/work_with_microtvm/micro_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#
# .. code-block:: bash
#
# %%bash
# %%shell
# pip install -q tensorflow tflite
# pip install -q tlcpack-nightly -f https://tlcpack.ai/wheels
# apt-get -qq install imagemagick curl
Expand Down Expand Up @@ -504,7 +504,7 @@ def representative_dataset():
#
# .. code-block:: bash
#
# %%bash
# %%shell
# mkdir -p ~/tests
# curl "https://i.imgur.com/JBbEhxN.png" -o ~/tests/car_224.png
# convert ~/tests/car_224.png -resize 64 ~/tests/car_64.png
Expand Down

0 comments on commit 0367b41

Please sign in to comment.