From 45c9b50f0ce67d7f2228ba75a6aba5dba3ae25b9 Mon Sep 17 00:00:00 2001 From: Josh Fromm Date: Sun, 10 Nov 2019 18:45:50 -0800 Subject: [PATCH 1/3] Switch to onnxruntime and newer onnx version. --- docker/install/ubuntu_install_onnx.sh | 3 ++- tests/python/frontend/onnx/test_forward.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docker/install/ubuntu_install_onnx.sh b/docker/install/ubuntu_install_onnx.sh index 54210b83f4d6..0e5da4b8193f 100755 --- a/docker/install/ubuntu_install_onnx.sh +++ b/docker/install/ubuntu_install_onnx.sh @@ -21,7 +21,8 @@ set -u set -o pipefail # fix to certain version for now -pip3 install onnx==1.5.0 +pip3 install onnx==1.6.0 +pip3 install onnxruntime-gpu==1.0.0 # torch depends on a number of other packages, but unhelpfully, does # not expose that in the wheel!!! diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 6391a1a9504d..41d2cc374e13 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -77,19 +77,18 @@ def get_tvm_output(graph_def, input_data, target, ctx, output_shape=None, output return tvm_output.asnumpy() -def get_caffe2_output(model, x, dtype='float32'): - import caffe2.python.onnx.backend - prepared_backend = caffe2.python.onnx.backend.prepare(model) - W = {model.graph.input[0].name: x.astype(dtype)} - c2_out = prepared_backend.run(W)[0] - return c2_out +def get_onnx_output(model, x, dtype='float32'): + import onnxruntime.backend + prepared_backend = onnxruntime.backend.prepare(model) + ort_out = prepared_backend.run(x.astype(dtype))[0] + return ort_out def verify_onnx_forward_impl(graph_file, data_shape, out_shape): dtype = 'float32' x = np.random.uniform(size=data_shape) model = onnx.load_model(graph_file) - c2_out = get_caffe2_output(model, x, dtype) + c2_out = get_onnx_output(model, x, dtype) for target, ctx in ctx_list(): tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype) tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5) @@ -1372,7 +1371,7 @@ def check_torch_conversion(model, input_size): onnx_model = onnx.load(file_name) for target, ctx in ctx_list(): input_data = np.random.uniform(size=input_size).astype('int32') - c2_out = get_caffe2_output(onnx_model, input_data) + c2_out = get_onnx_output(onnx_model, input_data) tvm_out = get_tvm_output(onnx_model, input_data, target, ctx) tvm.testing.assert_allclose(c2_out, tvm_out) From ba206e80cd919efa2d87b6905f5a1c2b9059e50f Mon Sep 17 00:00:00 2001 From: Josh Fromm Date: Sun, 10 Nov 2019 19:02:07 -0800 Subject: [PATCH 2/3] onnx v1.5 working. --- docker/install/ubuntu_install_onnx.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/install/ubuntu_install_onnx.sh b/docker/install/ubuntu_install_onnx.sh index 0e5da4b8193f..a915ca02c05a 100755 --- a/docker/install/ubuntu_install_onnx.sh +++ b/docker/install/ubuntu_install_onnx.sh @@ -21,8 +21,8 @@ set -u set -o pipefail # fix to certain version for now -pip3 install onnx==1.6.0 -pip3 install onnxruntime-gpu==1.0.0 +pip3 install onnx==1.5.0 +pip3 install onnxruntime==1.0.0 # torch depends on a number of other packages, but unhelpfully, does # not expose that in the wheel!!! From 133c17768c95c4eaeb28e7e41390785a0f7a6ef3 Mon Sep 17 00:00:00 2001 From: Josh Fromm Date: Sun, 10 Nov 2019 19:47:02 -0800 Subject: [PATCH 3/3] reverted changes to test_forward --- tests/python/frontend/onnx/test_forward.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 41d2cc374e13..6391a1a9504d 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -77,18 +77,19 @@ def get_tvm_output(graph_def, input_data, target, ctx, output_shape=None, output return tvm_output.asnumpy() -def get_onnx_output(model, x, dtype='float32'): - import onnxruntime.backend - prepared_backend = onnxruntime.backend.prepare(model) - ort_out = prepared_backend.run(x.astype(dtype))[0] - return ort_out +def get_caffe2_output(model, x, dtype='float32'): + import caffe2.python.onnx.backend + prepared_backend = caffe2.python.onnx.backend.prepare(model) + W = {model.graph.input[0].name: x.astype(dtype)} + c2_out = prepared_backend.run(W)[0] + return c2_out def verify_onnx_forward_impl(graph_file, data_shape, out_shape): dtype = 'float32' x = np.random.uniform(size=data_shape) model = onnx.load_model(graph_file) - c2_out = get_onnx_output(model, x, dtype) + c2_out = get_caffe2_output(model, x, dtype) for target, ctx in ctx_list(): tvm_out = get_tvm_output(model, x, target, ctx, out_shape, dtype) tvm.testing.assert_allclose(c2_out, tvm_out, rtol=1e-5, atol=1e-5) @@ -1371,7 +1372,7 @@ def check_torch_conversion(model, input_size): onnx_model = onnx.load(file_name) for target, ctx in ctx_list(): input_data = np.random.uniform(size=input_size).astype('int32') - c2_out = get_onnx_output(onnx_model, input_data) + c2_out = get_caffe2_output(onnx_model, input_data) tvm_out = get_tvm_output(onnx_model, input_data, target, ctx) tvm.testing.assert_allclose(c2_out, tvm_out)