diff --git a/gallery/how_to/compile_models/from_mxnet.py b/gallery/how_to/compile_models/from_mxnet.py index 0694d2aed081..132f098d9291 100644 --- a/gallery/how_to/compile_models/from_mxnet.py +++ b/gallery/how_to/compile_models/from_mxnet.py @@ -37,6 +37,7 @@ # sphinx_gallery_start_ignore # sphinx_gallery_requires_cuda = True # sphinx_gallery_end_ignore +import sys import mxnet as mx import tvm import tvm.relay as relay @@ -51,7 +52,12 @@ from PIL import Image from matplotlib import pyplot as plt -block = get_model("resnet18_v1", pretrained=True) +try: + block = get_model("resnet18_v1", pretrained=True) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) + img_url = "https://github.com/dmlc/mxnet.js/blob/main/data/cat.png?raw=true" img_name = "cat.png" synset_url = "".join( diff --git a/gallery/how_to/deploy_models/deploy_model_on_nano.py b/gallery/how_to/deploy_models/deploy_model_on_nano.py index abd0b3fab61d..761187e2d711 100644 --- a/gallery/how_to/deploy_models/deploy_model_on_nano.py +++ b/gallery/how_to/deploy_models/deploy_model_on_nano.py @@ -106,12 +106,18 @@ # `MXNet Gluon model zoo `_. # You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`. +import sys + from mxnet.gluon.model_zoo.vision import get_model from PIL import Image import numpy as np # one line to get the model -block = get_model("resnet18_v1", pretrained=True) +try: + block = get_model("resnet18_v1", pretrained=True) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) ###################################################################### # In order to test our model, here we download an image of cat and diff --git a/gallery/how_to/deploy_models/deploy_model_on_rasp.py b/gallery/how_to/deploy_models/deploy_model_on_rasp.py index de4ed9aff074..5196ae9ce1c6 100644 --- a/gallery/how_to/deploy_models/deploy_model_on_rasp.py +++ b/gallery/how_to/deploy_models/deploy_model_on_rasp.py @@ -99,12 +99,18 @@ # `MXNet Gluon model zoo `_. # You can found more details about this part at tutorial :ref:`tutorial-from-mxnet`. +import sys + from mxnet.gluon.model_zoo.vision import get_model from PIL import Image import numpy as np # one line to get the model -block = get_model("resnet18_v1", pretrained=True) +try: + block = get_model("resnet18_v1", pretrained=True) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) ###################################################################### # In order to test our model, here we download an image of cat and diff --git a/gallery/how_to/deploy_models/deploy_quantized.py b/gallery/how_to/deploy_models/deploy_quantized.py index f1b45dd7c158..2cdb7da5f84c 100644 --- a/gallery/how_to/deploy_models/deploy_quantized.py +++ b/gallery/how_to/deploy_models/deploy_quantized.py @@ -27,6 +27,9 @@ Relay, quantize the Relay model and then perform the inference. """ +import logging +import os +import sys import tvm from tvm import te @@ -34,8 +37,7 @@ import mxnet as mx from tvm.contrib.download import download_testdata from mxnet import gluon -import logging -import os + batch_size = 1 model_name = "resnet18_v1" @@ -157,7 +159,11 @@ def run_inference(mod): def main(): - mod, params = get_model() + try: + mod, params = get_model() + except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + return mod = quantize(mod, params, data_aware=True) run_inference(mod) diff --git a/gallery/how_to/extend_tvm/bring_your_own_datatypes.py b/gallery/how_to/extend_tvm/bring_your_own_datatypes.py index f5ff89717c1a..e502aff3e013 100644 --- a/gallery/how_to/extend_tvm/bring_your_own_datatypes.py +++ b/gallery/how_to/extend_tvm/bring_your_own_datatypes.py @@ -58,6 +58,8 @@ # -------------------- # # We'll begin by writing a simple program in TVM; afterwards, we will re-write it to use custom datatypes. +import sys + import tvm from tvm import relay @@ -253,7 +255,11 @@ def get_cat_image(): return np.asarray(img, dtype="float32") -module, params = get_mobilenet() +try: + module, params = get_mobilenet() +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) ###################################################################### # It's easy to execute MobileNet with native TVM: diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py b/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py index adc9c9fbb2e8..0b59038f19a7 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_arm.py @@ -49,6 +49,7 @@ import numpy as np import os +import sys import tvm from tvm import relay, auto_scheduler @@ -264,9 +265,13 @@ def get_network(name, batch_size, layout="NHWC", dtype="float32", use_sparse=Fal # Extract tasks from the network print("Get model...") -mod, params, input_shape, output_shape = get_network( - network, batch_size, layout, dtype=dtype, use_sparse=use_sparse -) +try: + mod, params, input_shape, output_shape = get_network( + network, batch_size, layout, dtype=dtype, use_sparse=use_sparse + ) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) print("Extract tasks...") tasks, task_weights = auto_scheduler.extract_tasks(mod["main"], params, target) diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py b/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py index 670996410359..41e7e8fb41b9 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py @@ -44,7 +44,7 @@ __name__ == "__main__":` block. """ - +import sys import numpy as np import tvm @@ -152,7 +152,11 @@ def get_network(name, batch_size, layout="NHWC", dtype="float32"): # Extract tasks from the network print("Extract tasks...") -mod, params, input_shape, output_shape = get_network(network, batch_size, layout, dtype=dtype) +try: + mod, params, input_shape, output_shape = get_network(network, batch_size, layout, dtype=dtype) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) tasks, task_weights = auto_scheduler.extract_tasks(mod["main"], params, target) for idx, task in enumerate(tasks): diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py b/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py index ab754ea30ff3..1c531a530303 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_mali.py @@ -44,6 +44,8 @@ __name__ == "__main__":` block. """ +import os +import sys import numpy as np @@ -51,7 +53,7 @@ from tvm import relay, auto_scheduler import tvm.relay.testing from tvm.contrib import graph_executor -import os + ################################################################# # Define a Network @@ -169,7 +171,11 @@ def get_network(name, batch_size, layout="NHWC", dtype="float32"): # Extract tasks from the network print("Extract tasks...") -mod, params, input_shape, output_shape = get_network(network, batch_size, layout, dtype=dtype) +try: + mod, params, input_shape, output_shape = get_network(network, batch_size, layout, dtype=dtype) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) tasks, task_weights = auto_scheduler.extract_tasks(mod["main"], params, target) for idx, task in enumerate(tasks): diff --git a/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py b/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py index 6eb1b79bfe0a..96df3942ab91 100644 --- a/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py +++ b/gallery/how_to/tune_with_autoscheduler/tune_network_x86.py @@ -45,6 +45,7 @@ __name__ == "__main__":` block. """ +import sys import numpy as np @@ -168,13 +169,18 @@ def get_network(name, batch_size, layout="NHWC", dtype="float32", use_sparse=Fal # Extract tasks from the network print("Get model...") -mod, params, input_shape, output_shape = get_network( - network, - batch_size, - layout, - dtype=dtype, - use_sparse=use_sparse, -) +try: + mod, params, input_shape, output_shape = get_network( + network, + batch_size, + layout, + dtype=dtype, + use_sparse=use_sparse, + ) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) + print("Extract tasks...") tasks, task_weights = auto_scheduler.extract_tasks(mod["main"], params, target) diff --git a/rust/tvm/examples/resnet/build.rs b/rust/tvm/examples/resnet/build.rs index 9e3a76433ffc..45e4d6d658d5 100644 --- a/rust/tvm/examples/resnet/build.rs +++ b/rust/tvm/examples/resnet/build.rs @@ -21,6 +21,10 @@ use anyhow::{Context, Result}; use std::{io::Write, path::Path, process::Command}; fn main() -> Result<()> { + // Currently disabled, as it depends on the no-longer-supported + // mxnet repo to download resnet. + + /* let out_dir = std::env::var("CARGO_MANIFEST_DIR")?; let python_script = concat!(env!("CARGO_MANIFEST_DIR"), "/src/build_resnet.py"); let synset_txt = concat!(env!("CARGO_MANIFEST_DIR"), "/synset.txt"); @@ -53,5 +57,7 @@ fn main() -> Result<()> { ); println!("cargo:rustc-link-search=native={}", out_dir); + */ + Ok(()) } diff --git a/rust/tvm/examples/resnet/src/main.rs b/rust/tvm/examples/resnet/src/main.rs index c22d55f2e4da..0ea8c4cf8bb5 100644 --- a/rust/tvm/examples/resnet/src/main.rs +++ b/rust/tvm/examples/resnet/src/main.rs @@ -31,6 +31,10 @@ use tvm_rt::graph_rt::GraphRt; use tvm_rt::*; fn main() -> anyhow::Result<()> { + // Currently disabled, as it depends on the no-longer-supported + // mxnet repo to download resnet. + + /* let dev = Device::cpu(0); println!("{}", concat!(env!("CARGO_MANIFEST_DIR"), "/cat.png")); @@ -134,6 +138,7 @@ fn main() -> anyhow::Result<()> { "input image belongs to the class `{}` with probability {}", label, max_prob ); + */ Ok(()) } diff --git a/tests/python/frontend/mxnet/test_forward.py b/tests/python/frontend/mxnet/test_forward.py index 880416c7bee8..cf206a3d5261 100644 --- a/tests/python/frontend/mxnet/test_forward.py +++ b/tests/python/frontend/mxnet/test_forward.py @@ -42,7 +42,10 @@ def verify_mxnet_frontend_impl( if gluon_impl: def get_gluon_output(name, x): - net = vision.get_model(name) + try: + net = vision.get_model(name) + except RuntimeError: + pytest.skip(reason="mxnet downloads no longer supported") net.collect_params().initialize(mx.init.Xavier()) net_sym = gluon.nn.SymbolBlock( outputs=net(mx.sym.var("data")), diff --git a/tests/python/nightly/quantization/test_quantization_accuracy.py b/tests/python/nightly/quantization/test_quantization_accuracy.py index 66153831d8ff..7eebdd17f2eb 100644 --- a/tests/python/nightly/quantization/test_quantization_accuracy.py +++ b/tests/python/nightly/quantization/test_quantization_accuracy.py @@ -14,15 +14,19 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. + from collections import namedtuple -import tvm -from tvm import relay -from tvm.relay import quantize as qtz -import mxnet as mx -from mxnet import gluon import logging import os + +import mxnet as mx +from mxnet import gluon +import pytest + +import tvm import tvm.testing +from tvm import relay +from tvm.relay import quantize as qtz logging.basicConfig(level=logging.INFO) @@ -69,7 +73,10 @@ def batch_fn(batch, ctx): def get_model(model_name, batch_size, qconfig, original=False): - gluon_model = gluon.model_zoo.vision.get_model(model_name, pretrained=True) + try: + gluon_model = gluon.model_zoo.vision.get_model(model_name, pretrained=True) + except RuntimeError: + pytest.skip(reason="mxnet downloads no longer supported") img_size = 299 if model_name == "inceptionv3" else 224 data_shape = (batch_size, 3, img_size, img_size) mod, params = relay.frontend.from_mxnet(gluon_model, {"data": data_shape}) diff --git a/vta/scripts/tune_resnet.py b/vta/scripts/tune_resnet.py index 2c284f05a0de..7fa6ec42ce8a 100644 --- a/vta/scripts/tune_resnet.py +++ b/vta/scripts/tune_resnet.py @@ -17,7 +17,7 @@ """Perform ResNet autoTVM tuning on VTA using Relay.""" -import argparse, os, time +import argparse, os, sys, time from mxnet.gluon.model_zoo import vision import numpy as np from PIL import Image @@ -285,7 +285,11 @@ def tune_tasks( # Compile Relay program print("Initial compile...") - relay_prog, params = compile_network(opt, env, target) + try: + relay_prog, params = compile_network(opt, env, target) + except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) # Register VTA tuning tasks register_vta_tuning_tasks() diff --git a/vta/tutorials/autotvm/tune_alu_vta.py b/vta/tutorials/autotvm/tune_alu_vta.py index 8a4db13ac409..8ee58fe990a0 100644 --- a/vta/tutorials/autotvm/tune_alu_vta.py +++ b/vta/tutorials/autotvm/tune_alu_vta.py @@ -20,6 +20,7 @@ """ import os +import sys from mxnet.gluon.model_zoo import vision import numpy as np from PIL import Image @@ -337,4 +338,8 @@ def tune_and_evaluate(tuning_opt): # Run the tuning and evaluate the results -tune_and_evaluate(tuning_option) +try: + tune_and_evaluate(tuning_option) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) diff --git a/vta/tutorials/autotvm/tune_relay_vta.py b/vta/tutorials/autotvm/tune_relay_vta.py index dc5bd462276d..b5de247883c2 100644 --- a/vta/tutorials/autotvm/tune_relay_vta.py +++ b/vta/tutorials/autotvm/tune_relay_vta.py @@ -54,6 +54,8 @@ # Now return to python code. Import packages. import os +import sys + from mxnet.gluon.model_zoo import vision import numpy as np from PIL import Image @@ -471,7 +473,11 @@ def tune_and_evaluate(tuning_opt): # Run the tuning and evaluate the results -tune_and_evaluate(tuning_option) +try: + tune_and_evaluate(tuning_option) +except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) ###################################################################### # Sample Output diff --git a/vta/tutorials/frontend/deploy_classification.py b/vta/tutorials/frontend/deploy_classification.py index f1e4926a3240..c741a1678f1e 100644 --- a/vta/tutorials/frontend/deploy_classification.py +++ b/vta/tutorials/frontend/deploy_classification.py @@ -43,6 +43,7 @@ import argparse, json, os, requests, sys, time from io import BytesIO from os.path import join, isfile +import sys from PIL import Image from mxnet.gluon.model_zoo import vision @@ -163,7 +164,11 @@ shape_dict = {"data": (env.BATCH, 3, 224, 224)} # Get off the shelf gluon model, and convert to relay - gluon_model = vision.get_model(model, pretrained=True) + try: + gluon_model = vision.get_model(model, pretrained=True) + except RuntimeError: + print("Downloads from mxnet no longer supported", file=sys.stderr) + sys.exit(0) # Measure build start time build_start = time.time()