Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gallery/how_to/compile_models/from_mxnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
8 changes: 7 additions & 1 deletion gallery/how_to/deploy_models/deploy_model_on_nano.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@
# `MXNet Gluon model zoo <https://mxnet.apache.org/api/python/gluon/model_zoo.html>`_.
# 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
Expand Down
8 changes: 7 additions & 1 deletion gallery/how_to/deploy_models/deploy_model_on_rasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@
# `MXNet Gluon model zoo <https://mxnet.apache.org/api/python/gluon/model_zoo.html>`_.
# 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
Expand Down
12 changes: 9 additions & 3 deletions gallery/how_to/deploy_models/deploy_quantized.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@
Relay, quantize the Relay model and then perform the inference.
"""

import logging
import os
import sys

import tvm
from tvm import te
from tvm import relay
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"
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 7 additions & 1 deletion gallery/how_to/extend_tvm/bring_your_own_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
11 changes: 8 additions & 3 deletions gallery/how_to/tune_with_autoscheduler/tune_network_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

import numpy as np
import os
import sys

import tvm
from tvm import relay, auto_scheduler
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions gallery/how_to/tune_with_autoscheduler/tune_network_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
__name__ == "__main__":` block.
"""


import sys
import numpy as np

import tvm
Expand Down Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions gallery/how_to/tune_with_autoscheduler/tune_network_mali.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@
__name__ == "__main__":` block.
"""

import os
import sys

import numpy as np

import tvm
from tvm import relay, auto_scheduler
import tvm.relay.testing
from tvm.contrib import graph_executor
import os


#################################################################
# Define a Network
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 13 additions & 7 deletions gallery/how_to/tune_with_autoscheduler/tune_network_x86.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
__name__ == "__main__":` block.
"""

import sys

import numpy as np

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions rust/tvm/examples/resnet/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -53,5 +57,7 @@ fn main() -> Result<()> {
);
println!("cargo:rustc-link-search=native={}", out_dir);

*/

Ok(())
}
5 changes: 5 additions & 0 deletions rust/tvm/examples/resnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down Expand Up @@ -134,6 +138,7 @@ fn main() -> anyhow::Result<()> {
"input image belongs to the class `{}` with probability {}",
label, max_prob
);
*/

Ok(())
}
5 changes: 4 additions & 1 deletion tests/python/frontend/mxnet/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
19 changes: 13 additions & 6 deletions tests/python/nightly/quantization/test_quantization_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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})
Expand Down
8 changes: 6 additions & 2 deletions vta/scripts/tune_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion vta/tutorials/autotvm/tune_alu_vta.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

import os
import sys
from mxnet.gluon.model_zoo import vision
import numpy as np
from PIL import Image
Expand Down Expand Up @@ -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)
8 changes: 7 additions & 1 deletion vta/tutorials/autotvm/tune_relay_vta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion vta/tutorials/frontend/deploy_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down