Skip to content

Commit 1a01102

Browse files
author
Siyuan Feng
authored
[Doc] Remove MxNet related tutorials (#16572)
* [Doc] Remove MxNet related tutorials As mxnet is retired, we remove related tutorials and scripts first. We will also remove mxnet frontend support in the future
1 parent 274c368 commit 1a01102

22 files changed

+43
-2505
lines changed

apps/benchmark/adreno/adreno_gpu_bench_clml.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,6 @@ def get_network(name, batch_size, dtype="float32"):
8484
net, params = testing.squeezenet.get_workload(
8585
batch_size=batch_size, version=version, dtype=dtype
8686
)
87-
elif name == "mxnet":
88-
# an example for mxnet model
89-
from mxnet.gluon.model_zoo.vision import get_model
90-
91-
block = get_model("resnet18_v1", pretrained=True)
92-
net, params = relay.frontend.from_mxnet(block, shape={"data": input_shape}, dtype=dtype)
93-
net = net["main"]
94-
net = relay.Function(
95-
net.params, relay.nn.softmax(net.body), None, net.type_params, net.attrs
96-
)
97-
net = tvm.IRModule.from_expr(net)
9887
else:
9988
raise ValueError("Unsupported network: " + name)
10089

apps/benchmark/adreno/adreno_gpu_bench_texture.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,6 @@ def get_network(name, batch_size, dtype="float32"):
8383
net, params = testing.squeezenet.get_workload(
8484
batch_size=batch_size, version=version, dtype=dtype
8585
)
86-
elif name == "mxnet":
87-
# an example for mxnet model
88-
from mxnet.gluon.model_zoo.vision import get_model
89-
90-
block = get_model("resnet18_v1", pretrained=True)
91-
net, params = relay.frontend.from_mxnet(block, shape={"data": input_shape}, dtype=dtype)
92-
net = net["main"]
93-
net = relay.Function(
94-
net.params, relay.nn.softmax(net.body), None, net.type_params, net.attrs
95-
)
96-
net = tvm.IRModule.from_expr(net)
9786
else:
9887
raise ValueError("Unsupported network: " + name)
9988

apps/benchmark/util.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,6 @@ def get_network(name, batch_size, dtype="float32"):
7272
net, params = testing.squeezenet.get_workload(
7373
batch_size=batch_size, version=version, dtype=dtype
7474
)
75-
elif name == "mxnet":
76-
# an example for mxnet model
77-
from mxnet.gluon.model_zoo.vision import get_model
78-
79-
block = get_model("resnet18_v1", pretrained=True)
80-
net, params = relay.frontend.from_mxnet(block, shape={"data": input_shape}, dtype=dtype)
81-
net = net["main"]
82-
net = relay.Function(
83-
net.params, relay.nn.softmax(net.body), None, net.type_params, net.attrs
84-
)
85-
net = tvm.IRModule.from_expr(net)
8675
else:
8776
raise ValueError("Unsupported network: " + name)
8877

docs/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ def jupyter_notebook(script_blocks, gallery_conf, target_dir, real_func):
441441
for p in [
442442
tvm_path / "vta" / "tutorials" / "frontend",
443443
tvm_path / "vta" / "tutorials" / "optimize",
444-
tvm_path / "vta" / "tutorials" / "autotvm",
445444
]
446445
)
447446

gallery/how_to/compile_models/from_mxnet.py

Lines changed: 0 additions & 153 deletions
This file was deleted.

gallery/how_to/deploy_models/deploy_model_on_nano.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,22 @@
102102
# -----------------------------
103103
# Back to the host machine, which should have a full TVM installed (with LLVM).
104104
#
105-
# We will use pre-trained model from
106-
# `MXNet Gluon model zoo <https://mxnet.apache.org/api/python/gluon/model_zoo.html>`_.
107-
# You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`.
105+
# We will use pre-trained model from torchvision
108106

109-
import sys
110-
111-
from mxnet.gluon.model_zoo.vision import get_model
107+
import torch
108+
import torchvision
112109
from PIL import Image
113110
import numpy as np
114111

115112
# one line to get the model
116-
try:
117-
block = get_model("resnet18_v1", pretrained=True)
118-
except RuntimeError:
119-
print("Downloads from mxnet no longer supported", file=sys.stderr)
120-
sys.exit(0)
113+
model_name = "resnet18"
114+
model = getattr(torchvision.models, model_name)(pretrained=True)
115+
model = model.eval()
116+
117+
# We grab the TorchScripted model via tracing
118+
input_shape = [1, 3, 224, 224]
119+
input_data = torch.randn(input_shape)
120+
scripted_model = torch.jit.trace(model, input_data).eval()
121121

122122
######################################################################
123123
# In order to test our model, here we download an image of cat and
@@ -158,9 +158,9 @@ def transform_image(image):
158158
# Now we would like to port the Gluon model to a portable computational graph.
159159
# It's as easy as several lines.
160160

161-
# We support MXNet static graph(symbol) and HybridBlock in mxnet.gluon
162-
shape_dict = {"data": x.shape}
163-
mod, params = relay.frontend.from_mxnet(block, shape_dict)
161+
input_name = "input0"
162+
shape_list = [(input_name, x.shape)]
163+
mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)
164164
# we want a probability so add a softmax operator
165165
func = mod["main"]
166166
func = relay.Function(func.params, relay.nn.softmax(func.body), None, func.type_params, func.attrs)
@@ -241,7 +241,7 @@ def transform_image(image):
241241

242242
module = runtime.GraphModule(rlib["default"](dev))
243243
# set input data
244-
module.set_input("data", tvm.nd.array(x.astype("float32")))
244+
module.set_input(input_name, tvm.nd.array(x.astype("float32")))
245245
# run
246246
module.run()
247247
# get output

gallery/how_to/deploy_models/deploy_model_on_rasp.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,22 @@
9595
# -----------------------------
9696
# Back to the host machine, which should have a full TVM installed (with LLVM).
9797
#
98-
# We will use pre-trained model from
99-
# `MXNet Gluon model zoo <https://mxnet.apache.org/api/python/gluon/model_zoo.html>`_.
100-
# You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`.
98+
# We will use pre-trained model from torchvision
10199

102-
import sys
103-
104-
from mxnet.gluon.model_zoo.vision import get_model
100+
import torch
101+
import torchvision
105102
from PIL import Image
106103
import numpy as np
107104

108105
# one line to get the model
109-
try:
110-
block = get_model("resnet18_v1", pretrained=True)
111-
except RuntimeError:
112-
print("Downloads from mxnet no longer supported", file=sys.stderr)
113-
sys.exit(0)
106+
model_name = "resnet18"
107+
model = getattr(torchvision.models, model_name)(pretrained=True)
108+
model = model.eval()
109+
110+
# We grab the TorchScripted model via tracing
111+
input_shape = [1, 3, 224, 224]
112+
input_data = torch.randn(input_shape)
113+
scripted_model = torch.jit.trace(model, input_data).eval()
114114

115115
######################################################################
116116
# In order to test our model, here we download an image of cat and
@@ -148,12 +148,12 @@ def transform_image(image):
148148
synset = eval(f.read())
149149

150150
######################################################################
151-
# Now we would like to port the Gluon model to a portable computational graph.
151+
# Now we would like to port the PyTorch model to a portable computational graph.
152152
# It's as easy as several lines.
153153

154-
# We support MXNet static graph(symbol) and HybridBlock in mxnet.gluon
155-
shape_dict = {"data": x.shape}
156-
mod, params = relay.frontend.from_mxnet(block, shape_dict)
154+
input_name = "input0"
155+
shape_list = [(input_name, x.shape)]
156+
mod, params = relay.frontend.from_pytorch(scripted_model, shape_list)
157157
# we want a probability so add a softmax operator
158158
func = mod["main"]
159159
func = relay.Function(func.params, relay.nn.softmax(func.body), None, func.type_params, func.attrs)
@@ -226,7 +226,7 @@ def transform_image(image):
226226
dev = remote.cpu(0)
227227
module = runtime.GraphModule(rlib["default"](dev))
228228
# set input data
229-
module.set_input("data", tvm.nd.array(x.astype("float32")))
229+
module.set_input(input_name, tvm.nd.array(x.astype("float32")))
230230
# run
231231
module.run()
232232
# get output

0 commit comments

Comments
 (0)