From f66d4e80d2d4b533b03a6d5237ae8f84312b68a8 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 09:09:03 +0900 Subject: [PATCH 01/11] fix norm and linspace test --- python/tvm/relay/frontend/pytorch.py | 2 +- tests/python/frontend/pytorch/test_forward.py | 330 +++++++++--------- 2 files changed, 166 insertions(+), 166 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index d8c0769e24ea..72d4da65ac1e 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -1552,7 +1552,7 @@ def _impl(inputs, input_types): axis = None keepdims = False if len(inputs) > 2: - axis = inputs[1] + axis = inputs[1] if len(inputs[1]) > 0 else None keepdims = bool(inputs[2]) return _op.sqrt(_op.reduce.sum((data * data), axis=axis, keepdims=keepdims)) diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index e997ebe07a50..8ebb71308fb0 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -2535,7 +2535,7 @@ def test_forward_linspace(): class Linspace1(Module): def forward(self, *args): - return torch.linspace(5, 10) + return torch.linspace(5, 10, steps=100) class Linspace2(Module): def forward(self, *args): @@ -2559,7 +2559,7 @@ def forward(self, *args): class Linspace7(Module): def forward(self, *args): - return torch.linspace(1, 4, dtype=torch.float32) + return torch.linspace(1, 4, steps=100, dtype=torch.float32) class Linspace8(Module): def forward(self, *args): @@ -3364,167 +3364,167 @@ def test_fn(x, weights=None): if __name__ == "__main__": - # some structural tests - test_forward_traced_function() - test_forward_dtypes() - test_weight_names() - test_duplicate_weight_use() - - # Single operator tests - test_forward_pixel_shuffle() - test_forward_add() - test_forward_subtract() - test_forward_multiply() - test_forward_matmul() - test_forward_rsub() - test_forward_onehot() - test_forward_embedding() - test_forward_reshape() - test_forward_reciprocal() - test_forward_repeat() - test_forward_repeat_interleave() - test_forward_squeeze() - test_forward_unsqueeze() - test_forward_concatenate() - test_forward_reduce_sum() - test_forward_reduce_prod() - test_forward_argmin() - test_forward_argmax() - test_forward_norm() - test_forward_frobenius_norm() - test_forward_std() - test_forward_variance() - test_forward_relu() - test_forward_prelu() - test_forward_leakyrelu() - test_forward_elu() - test_forward_celu() - test_forward_gelu() - test_forward_selu() - test_forward_log_sigmoid() - test_forward_adaptiveavgpool() - test_forward_maxpool2d() - test_forward_maxpool1d() - test_forward_maxpool3d() - test_forward_hardtanh() - test_forward_conv() - test_forward_conv_transpose() - test_forward_threshold() - test_forward_contiguous() - test_forward_batchnorm() - test_forward_instancenorm() - test_forward_layernorm() - test_forward_groupnorm() - test_forward_transpose() - test_forward_size() - test_forward_view() - test_forward_select() - test_forward_take() - test_forward_topk() - test_forward_where() - test_forward_addcdiv() - test_forward_addcmul() - test_forward_true_divide() - test_forward_clone() - test_forward_softplus() - test_forward_softsign() - test_forward_logsoftmax() - test_forward_sigmoid() - test_forward_dense() - test_forward_avgpool() - test_forward_avgpool3d() - test_forward_dropout() - test_forward_slice() - test_forward_mean() - test_forward_expand() - test_forward_pow() - test_forward_unary() - test_forward_clamp() - test_forward_clamp_() - test_forward_logical_not() - test_forward_bitwise_not() - test_forward_bitwise_xor() - test_forward_logical_xor() - test_forward_isfinite() - test_forward_isnan() - test_forward_isinf() - test_forward_ones() - test_forward_ones_like() - test_forward_zeros() - test_forward_zeros_like() - test_forward_full() - test_forward_full_like() + # # some structural tests + # test_forward_traced_function() + # test_forward_dtypes() + # test_weight_names() + # test_duplicate_weight_use() + + # # Single operator tests + # test_forward_pixel_shuffle() + # test_forward_add() + # test_forward_subtract() + # test_forward_multiply() + # test_forward_matmul() + # test_forward_rsub() + # test_forward_onehot() + # test_forward_embedding() + # test_forward_reshape() + # test_forward_reciprocal() + # test_forward_repeat() + # test_forward_repeat_interleave() + # test_forward_squeeze() + # test_forward_unsqueeze() + # test_forward_concatenate() + # test_forward_reduce_sum() + # test_forward_reduce_prod() + # test_forward_argmin() + # test_forward_argmax() + # test_forward_norm() + # test_forward_frobenius_norm() + # test_forward_std() + # test_forward_variance() + # test_forward_relu() + # test_forward_prelu() + # test_forward_leakyrelu() + # test_forward_elu() + # test_forward_celu() + # test_forward_gelu() + # test_forward_selu() + # test_forward_log_sigmoid() + # test_forward_adaptiveavgpool() + # test_forward_maxpool2d() + # test_forward_maxpool1d() + # test_forward_maxpool3d() + # test_forward_hardtanh() + # test_forward_conv() + # test_forward_conv_transpose() + # test_forward_threshold() + # test_forward_contiguous() + # test_forward_batchnorm() + # test_forward_instancenorm() + # test_forward_layernorm() + # test_forward_groupnorm() + # test_forward_transpose() + # test_forward_size() + # test_forward_view() + # test_forward_select() + # test_forward_take() + # test_forward_topk() + # test_forward_where() + # test_forward_addcdiv() + # test_forward_addcmul() + # test_forward_true_divide() + # test_forward_clone() + # test_forward_softplus() + # test_forward_softsign() + # test_forward_logsoftmax() + # test_forward_sigmoid() + # test_forward_dense() + # test_forward_avgpool() + # test_forward_avgpool3d() + # test_forward_dropout() + # test_forward_slice() + # test_forward_mean() + # test_forward_expand() + # test_forward_pow() + # test_forward_unary() + # test_forward_clamp() + # test_forward_clamp_() + # test_forward_logical_not() + # test_forward_bitwise_not() + # test_forward_bitwise_xor() + # test_forward_logical_xor() + # test_forward_isfinite() + # test_forward_isnan() + # test_forward_isinf() + # test_forward_ones() + # test_forward_ones_like() + # test_forward_zeros() + # test_forward_zeros_like() + # test_forward_full() + # test_forward_full_like() test_forward_linspace() - test_forward_arange() - test_forward_mesh_grid() - test_forward_chunk() - test_forward_split() - test_forward_gather() - test_upsample() - test_forward_upsample3d() - test_forward_nms() - test_forward_roi_align() - test_to() - test_flatten() - test_type_as() - test_forward_functional_pad() - test_forward_zero_pad2d() - test_forward_constant_pad1d() - test_forward_constant_pad2d() - test_forward_constant_pad3d() - test_forward_reflection_pad1d() - test_forward_reflection_pad2d() - test_forward_replication_pad1d() - test_forward_replication_pad2d() - test_forward_replication_pad3d() - test_adaptive_pool3d() - test_conv3d() - test_conv3d_transpose() - test_forward_index() - test_min_max() - test_logsumexp() - test_stack() - test_stack_dynamic() - test_forward_unbind() - test_forward_nonzero() - test_forward_scatter() - test_numel() - test_bincount() - - # Model tests - test_resnet18() - test_squeezenet1_0() - test_squeezenet1_1() - test_densenet121() - # disable inception test for now, since loading it takes ~5min on torchvision-0.5 due to scipy bug - # See https://discuss.pytorch.org/t/torchvisions-inception-v3-takes-much-longer-to-load-than-other-models/68756 - # test_inception_v3() - test_googlenet() - test_mnasnet0_5() - test_mobilenet_v2() - - test_custom_conversion_map() - - test_segmentaton_models() - test_3d_models() - - # Quantization test - from qnn_test import test_quantized_imagenet, test_quantized_modules - - test_quantized_modules() - test_quantized_imagenet() - - # Test simple conditionals and loop - test_control_flow() - test_simple_rnn() - - # More complex recurrent models - from test_lstm import test_custom_lstm - - test_custom_lstm() - - # Test bert model - test_forward_pretrained_bert_base_uncased() - - # Test convert torch script(jit) with specific inputs' types - test_convert_torch_script_with_input_types() + # test_forward_arange() + # test_forward_mesh_grid() + # test_forward_chunk() + # test_forward_split() + # test_forward_gather() + # test_upsample() + # test_forward_upsample3d() + # test_forward_nms() + # test_forward_roi_align() + # test_to() + # test_flatten() + # test_type_as() + # test_forward_functional_pad() + # test_forward_zero_pad2d() + # test_forward_constant_pad1d() + # test_forward_constant_pad2d() + # test_forward_constant_pad3d() + # test_forward_reflection_pad1d() + # test_forward_reflection_pad2d() + # test_forward_replication_pad1d() + # test_forward_replication_pad2d() + # test_forward_replication_pad3d() + # test_adaptive_pool3d() + # test_conv3d() + # test_conv3d_transpose() + # test_forward_index() + # test_min_max() + # test_logsumexp() + # test_stack() + # test_stack_dynamic() + # test_forward_unbind() + # test_forward_nonzero() + # test_forward_scatter() + # test_numel() + # test_bincount() + + # # Model tests + # test_resnet18() + # test_squeezenet1_0() + # test_squeezenet1_1() + # test_densenet121() + # # disable inception test for now, since loading it takes ~5min on torchvision-0.5 due to scipy bug + # # See https://discuss.pytorch.org/t/torchvisions-inception-v3-takes-much-longer-to-load-than-other-models/68756 + # # test_inception_v3() + # test_googlenet() + # test_mnasnet0_5() + # test_mobilenet_v2() + + # test_custom_conversion_map() + + # test_segmentaton_models() + # test_3d_models() + + # # Quantization test + # from qnn_test import test_quantized_imagenet, test_quantized_modules + + # test_quantized_modules() + # test_quantized_imagenet() + + # # Test simple conditionals and loop + # test_control_flow() + # test_simple_rnn() + + # # More complex recurrent models + # from test_lstm import test_custom_lstm + + # test_custom_lstm() + + # # Test bert model + # test_forward_pretrained_bert_base_uncased() + + # # Test convert torch script(jit) with specific inputs' types + # test_convert_torch_script_with_input_types() From ecc20600219b115fc39d6d5ad4f7ab05ede6bfa7 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 09:40:44 +0900 Subject: [PATCH 02/11] fix upsampling conversion --- python/tvm/relay/frontend/pytorch.py | 48 ++++++++++++++++------------ 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 72d4da65ac1e..9a2882440e2a 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -21,6 +21,7 @@ import itertools import logging import sys +import math import numpy as np @@ -1847,18 +1848,33 @@ def _impl(inputs, input_types): return _impl -def _upsample(method, prelude): - def _impl(inputs, input_types): - out_size = [] +def _get_upsample_out_size(inputs, method): + # This assumes a static shape + out_size = [] + if inputs[1] is not None: for size in inputs[1]: if not isinstance(size, int): out_size.append(int(_infer_value(size, {}).asnumpy())) else: out_size.append(size) + else: + scale_index = 3 if method in ["bilinear", "trilinear"] else 2 + scales = inputs[scale_index] + assert scales is not None, "neither out size nor scale provided" + assert isinstance(scales, list) + ishape = _infer_shape(inputs[0]) + for i in range(len(scales)): + out_size.append(int(math.floor(math.floor(ishape[2 + i] * scales[i])))) + + return out_size + +def _upsample(method, prelude): + def _impl(inputs, input_types): data = inputs[0] + out_size = _get_upsample_out_size(inputs, method) - if len(inputs) > 2: + if len(inputs) > 2 and method == "bilinear": align_corners = inputs[2] else: align_corners = False @@ -1874,17 +1890,13 @@ def func(x): return _op.image.resize(x, out_size, "NCHW", method, coord_trans) if _is_quantized_tensor(data, prelude): - # Torch version > 1.4 changed upsampling API - if is_version_greater_than("1.4.0"): - num_inputs = 7 - else: - num_inputs = 5 - - assert len(inputs) == num_inputs, "Input quant param not found in op inputs" - + # input qparams are manually appended by us + assert isinstance(inputs[-2], float) + assert isinstance(inputs[-1], int) input_scale = _expr.const(inputs[-2]) input_zero_point = _expr.const(inputs[-1]) return qnn_torch.quantized_upsample(data, input_scale, input_zero_point, func) + return func(data) return _impl @@ -1892,17 +1904,10 @@ def func(x): def _upsample3d(method): def _impl(inputs, input_types): - if isinstance(inputs[1], _expr.Var): - out_size = _infer_shape(inputs[1]) - elif _is_int_seq(inputs[1]): - out_size = inputs[1] - elif isinstance(inputs[1], list): - infer_res = [_infer_value(size, {}) for size in inputs[1]] - out_size = [np.asscalar(res.asnumpy().astype(np.int)) for res in infer_res] - data = inputs[0] + out_size = _get_upsample_out_size(inputs, method) - if len(inputs) > 2: + if len(inputs) > 2 and method == "trilinear": align_corners = inputs[2] else: align_corners = False @@ -3370,6 +3375,7 @@ def from_pytorch(script_module, input_infos, custom_convert_map=None, default_dt op_names = get_all_op_names(graph) _report_missing_conversion(op_names, convert_map) + print(graph) is_module = isinstance(script_module, torch.jit.ScriptModule) params = script_module.state_dict() if is_module else {} From 91c48f05b328dca77d46a084bf56077806645743 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 09:46:15 +0900 Subject: [PATCH 03/11] update install script --- docker/install/ubuntu_install_onnx.sh | 2 +- tests/python/frontend/pytorch/test_forward.py | 326 +++++++++--------- 2 files changed, 164 insertions(+), 164 deletions(-) diff --git a/docker/install/ubuntu_install_onnx.sh b/docker/install/ubuntu_install_onnx.sh index 2ad601983fa2..a92a0244d707 100755 --- a/docker/install/ubuntu_install_onnx.sh +++ b/docker/install/ubuntu_install_onnx.sh @@ -28,4 +28,4 @@ pip3 install onnxruntime==1.0.0 # not expose that in the wheel!!! pip3 install future -pip3 install torch==1.4.0 torchvision==0.5.0 +pip3 install torch==1.7.0 torchvision==0.8.1 diff --git a/tests/python/frontend/pytorch/test_forward.py b/tests/python/frontend/pytorch/test_forward.py index 8ebb71308fb0..4dec5f7e5916 100644 --- a/tests/python/frontend/pytorch/test_forward.py +++ b/tests/python/frontend/pytorch/test_forward.py @@ -3364,167 +3364,167 @@ def test_fn(x, weights=None): if __name__ == "__main__": - # # some structural tests - # test_forward_traced_function() - # test_forward_dtypes() - # test_weight_names() - # test_duplicate_weight_use() - - # # Single operator tests - # test_forward_pixel_shuffle() - # test_forward_add() - # test_forward_subtract() - # test_forward_multiply() - # test_forward_matmul() - # test_forward_rsub() - # test_forward_onehot() - # test_forward_embedding() - # test_forward_reshape() - # test_forward_reciprocal() - # test_forward_repeat() - # test_forward_repeat_interleave() - # test_forward_squeeze() - # test_forward_unsqueeze() - # test_forward_concatenate() - # test_forward_reduce_sum() - # test_forward_reduce_prod() - # test_forward_argmin() - # test_forward_argmax() - # test_forward_norm() - # test_forward_frobenius_norm() - # test_forward_std() - # test_forward_variance() - # test_forward_relu() - # test_forward_prelu() - # test_forward_leakyrelu() - # test_forward_elu() - # test_forward_celu() - # test_forward_gelu() - # test_forward_selu() - # test_forward_log_sigmoid() - # test_forward_adaptiveavgpool() - # test_forward_maxpool2d() - # test_forward_maxpool1d() - # test_forward_maxpool3d() - # test_forward_hardtanh() - # test_forward_conv() - # test_forward_conv_transpose() - # test_forward_threshold() - # test_forward_contiguous() - # test_forward_batchnorm() - # test_forward_instancenorm() - # test_forward_layernorm() - # test_forward_groupnorm() - # test_forward_transpose() - # test_forward_size() - # test_forward_view() - # test_forward_select() - # test_forward_take() - # test_forward_topk() - # test_forward_where() - # test_forward_addcdiv() - # test_forward_addcmul() - # test_forward_true_divide() - # test_forward_clone() - # test_forward_softplus() - # test_forward_softsign() - # test_forward_logsoftmax() - # test_forward_sigmoid() - # test_forward_dense() - # test_forward_avgpool() - # test_forward_avgpool3d() - # test_forward_dropout() - # test_forward_slice() - # test_forward_mean() - # test_forward_expand() - # test_forward_pow() - # test_forward_unary() - # test_forward_clamp() - # test_forward_clamp_() - # test_forward_logical_not() - # test_forward_bitwise_not() - # test_forward_bitwise_xor() - # test_forward_logical_xor() - # test_forward_isfinite() - # test_forward_isnan() - # test_forward_isinf() - # test_forward_ones() - # test_forward_ones_like() - # test_forward_zeros() - # test_forward_zeros_like() - # test_forward_full() - # test_forward_full_like() + # some structural tests + test_forward_traced_function() + test_forward_dtypes() + test_weight_names() + test_duplicate_weight_use() + + # Single operator tests + test_forward_pixel_shuffle() + test_forward_add() + test_forward_subtract() + test_forward_multiply() + test_forward_matmul() + test_forward_rsub() + test_forward_onehot() + test_forward_embedding() + test_forward_reshape() + test_forward_reciprocal() + test_forward_repeat() + test_forward_repeat_interleave() + test_forward_squeeze() + test_forward_unsqueeze() + test_forward_concatenate() + test_forward_reduce_sum() + test_forward_reduce_prod() + test_forward_argmin() + test_forward_argmax() + test_forward_norm() + test_forward_frobenius_norm() + test_forward_std() + test_forward_variance() + test_forward_relu() + test_forward_prelu() + test_forward_leakyrelu() + test_forward_elu() + test_forward_celu() + test_forward_gelu() + test_forward_selu() + test_forward_log_sigmoid() + test_forward_adaptiveavgpool() + test_forward_maxpool2d() + test_forward_maxpool1d() + test_forward_maxpool3d() + test_forward_hardtanh() + test_forward_conv() + test_forward_conv_transpose() + test_forward_threshold() + test_forward_contiguous() + test_forward_batchnorm() + test_forward_instancenorm() + test_forward_layernorm() + test_forward_groupnorm() + test_forward_transpose() + test_forward_size() + test_forward_view() + test_forward_select() + test_forward_take() + test_forward_topk() + test_forward_where() + test_forward_addcdiv() + test_forward_addcmul() + test_forward_true_divide() + test_forward_clone() + test_forward_softplus() + test_forward_softsign() + test_forward_logsoftmax() + test_forward_sigmoid() + test_forward_dense() + test_forward_avgpool() + test_forward_avgpool3d() + test_forward_dropout() + test_forward_slice() + test_forward_mean() + test_forward_expand() + test_forward_pow() + test_forward_unary() + test_forward_clamp() + test_forward_clamp_() + test_forward_logical_not() + test_forward_bitwise_not() + test_forward_bitwise_xor() + test_forward_logical_xor() + test_forward_isfinite() + test_forward_isnan() + test_forward_isinf() + test_forward_ones() + test_forward_ones_like() + test_forward_zeros() + test_forward_zeros_like() + test_forward_full() + test_forward_full_like() test_forward_linspace() - # test_forward_arange() - # test_forward_mesh_grid() - # test_forward_chunk() - # test_forward_split() - # test_forward_gather() - # test_upsample() - # test_forward_upsample3d() - # test_forward_nms() - # test_forward_roi_align() - # test_to() - # test_flatten() - # test_type_as() - # test_forward_functional_pad() - # test_forward_zero_pad2d() - # test_forward_constant_pad1d() - # test_forward_constant_pad2d() - # test_forward_constant_pad3d() - # test_forward_reflection_pad1d() - # test_forward_reflection_pad2d() - # test_forward_replication_pad1d() - # test_forward_replication_pad2d() - # test_forward_replication_pad3d() - # test_adaptive_pool3d() - # test_conv3d() - # test_conv3d_transpose() - # test_forward_index() - # test_min_max() - # test_logsumexp() - # test_stack() - # test_stack_dynamic() - # test_forward_unbind() - # test_forward_nonzero() - # test_forward_scatter() - # test_numel() - # test_bincount() - - # # Model tests - # test_resnet18() - # test_squeezenet1_0() - # test_squeezenet1_1() - # test_densenet121() - # # disable inception test for now, since loading it takes ~5min on torchvision-0.5 due to scipy bug - # # See https://discuss.pytorch.org/t/torchvisions-inception-v3-takes-much-longer-to-load-than-other-models/68756 - # # test_inception_v3() - # test_googlenet() - # test_mnasnet0_5() - # test_mobilenet_v2() - - # test_custom_conversion_map() - - # test_segmentaton_models() - # test_3d_models() - - # # Quantization test - # from qnn_test import test_quantized_imagenet, test_quantized_modules - - # test_quantized_modules() - # test_quantized_imagenet() - - # # Test simple conditionals and loop - # test_control_flow() - # test_simple_rnn() - - # # More complex recurrent models - # from test_lstm import test_custom_lstm - - # test_custom_lstm() - - # # Test bert model - # test_forward_pretrained_bert_base_uncased() - - # # Test convert torch script(jit) with specific inputs' types - # test_convert_torch_script_with_input_types() + test_forward_arange() + test_forward_mesh_grid() + test_forward_chunk() + test_forward_split() + test_forward_gather() + test_upsample() + test_forward_upsample3d() + test_forward_nms() + test_forward_roi_align() + test_to() + test_flatten() + test_type_as() + test_forward_functional_pad() + test_forward_zero_pad2d() + test_forward_constant_pad1d() + test_forward_constant_pad2d() + test_forward_constant_pad3d() + test_forward_reflection_pad1d() + test_forward_reflection_pad2d() + test_forward_replication_pad1d() + test_forward_replication_pad2d() + test_forward_replication_pad3d() + test_adaptive_pool3d() + test_conv3d() + test_conv3d_transpose() + test_forward_index() + test_min_max() + test_logsumexp() + test_stack() + test_stack_dynamic() + test_forward_unbind() + test_forward_nonzero() + test_forward_scatter() + test_numel() + test_bincount() + + # Model tests + test_resnet18() + test_squeezenet1_0() + test_squeezenet1_1() + test_densenet121() + # disable inception test for now, since loading it takes ~5min on torchvision-0.5 due to scipy bug + # See https://discuss.pytorch.org/t/torchvisions-inception-v3-takes-much-longer-to-load-than-other-models/68756 + # test_inception_v3() + test_googlenet() + test_mnasnet0_5() + test_mobilenet_v2() + + test_custom_conversion_map() + + test_segmentaton_models() + test_3d_models() + + # Quantization test + from qnn_test import test_quantized_imagenet, test_quantized_modules + + test_quantized_modules() + test_quantized_imagenet() + + # Test simple conditionals and loop + test_control_flow() + test_simple_rnn() + + # More complex recurrent models + from test_lstm import test_custom_lstm + + test_custom_lstm() + + # Test bert model + test_forward_pretrained_bert_base_uncased() + + # Test convert torch script(jit) with specific inputs' types + test_convert_torch_script_with_input_types() From 09ee610dde7c5c629ac49f4ffe43b38865ff5bac Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 09:48:08 +0900 Subject: [PATCH 04/11] remove print --- python/tvm/relay/frontend/pytorch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 9a2882440e2a..ab1d43053c38 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -3375,7 +3375,6 @@ def from_pytorch(script_module, input_infos, custom_convert_map=None, default_dt op_names = get_all_op_names(graph) _report_missing_conversion(op_names, convert_map) - print(graph) is_module = isinstance(script_module, torch.jit.ScriptModule) params = script_module.state_dict() if is_module else {} From 6f8b74488509195af29001d218f570d58e453efb Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 10:10:35 +0900 Subject: [PATCH 05/11] fix pylint --- python/tvm/relay/frontend/pytorch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index ab1d43053c38..ec7c3a7df63e 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -1863,8 +1863,8 @@ def _get_upsample_out_size(inputs, method): assert scales is not None, "neither out size nor scale provided" assert isinstance(scales, list) ishape = _infer_shape(inputs[0]) - for i in range(len(scales)): - out_size.append(int(math.floor(math.floor(ishape[2 + i] * scales[i])))) + for i, scale in enumerate(scales): + out_size.append(int(math.floor(math.floor(ishape[2 + i] * scale)))) return out_size From 14265605f56fd42d97d01513ea73a282423bd7f2 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 10:13:40 +0900 Subject: [PATCH 06/11] disable quantized googlenet test --- tests/python/frontend/pytorch/qnn_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python/frontend/pytorch/qnn_test.py b/tests/python/frontend/pytorch/qnn_test.py index 1851e31e817f..9781eb5d57c4 100644 --- a/tests/python/frontend/pytorch/qnn_test.py +++ b/tests/python/frontend/pytorch/qnn_test.py @@ -367,7 +367,8 @@ def get_imagenet_input(): # disable inception test for now, since loading it takes ~5min on torchvision-0.5 due to scipy bug # See https://discuss.pytorch.org/t/torchvisions-inception-v3-takes-much-longer-to-load-than-other-models/68756 # ("inception_v3", qinception.inception_v3(pretrained=True), per_channel), - ("googlenet", qgooglenet(pretrained=True), per_channel), + # tracing quantized googlenet broken as of v1.6 + # ("googlenet", qgooglenet(pretrained=True), per_channel), ] results = [] From b5acd25f56cd44de0eeeef010f9696cfff85a593 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 14:51:11 +0900 Subject: [PATCH 07/11] fix for object detection test --- python/tvm/relay/frontend/pytorch.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index ec7c3a7df63e..280c6dadeac6 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -169,7 +169,6 @@ def _min(): def _unary(name): def _impl(inputs, input_types): - input_type = input_types[0] # this is just to ensure tensor input (data,) = _pytorch_promote_types(inputs[:1], input_types[:1]) return get_relay_op(name)(data) @@ -1988,8 +1987,7 @@ def _impl(inputs, input_types): def _logical_not(): def _impl(inputs, input_types): - data = inputs[0] - + data = _wrap_const(inputs[0]) return _op.logical_not(_op.cast(data, "bool")) return _impl @@ -2737,6 +2735,7 @@ def _get_convert_map(prelude, default_dtype): "aten::empty": _empty(), "aten::bincount": _bincount(), "aten::scatter_add": _scatter_add(), + "aten::__not__": _logical_not(), } return convert_map @@ -2803,6 +2802,7 @@ def _report_missing_conversion(op_names, convert_map): "prim::ListUnpack", "prim::TupleConstruct", "prim::TupleUnpack", + "prim::RaiseException", "prim::If", "prim::Loop", ] @@ -2908,7 +2908,9 @@ def _get_operator_nodes(nodes): ops = [] # Traverse nodes and add to graph for node in nodes: - if node.outputsSize() > 1: + if node.outputsSize() == 0: + continue + elif node.outputsSize() > 1: node_name = "_".join(_get_output_names(node)) else: node_name = _get_output_name(node) @@ -3291,6 +3293,9 @@ def convert_operators(operators, outputs, ret_names, convert_map, prelude, defau else: unpacked = _unpack_tuple(inputs[0]) outputs.update(zip(_get_output_names(op_node), unpacked)) + elif operator == "prim::prim::RaiseException": + logging.warn("raising exceptions is ignored") + outputs[node_name] = None elif operator == "prim::If": if_out = convert_if(op_node, outputs, convert_map, prelude, default_dtype=default_dtype) outputs[node_name] = if_out From 5fc810b4ac9ab56c4cf57e395258524259ce58e7 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Sun, 1 Nov 2020 15:11:37 +0900 Subject: [PATCH 08/11] fix pylint --- python/tvm/relay/frontend/pytorch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 280c6dadeac6..8e64a388b209 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -2910,7 +2910,7 @@ def _get_operator_nodes(nodes): for node in nodes: if node.outputsSize() == 0: continue - elif node.outputsSize() > 1: + if node.outputsSize() > 1: node_name = "_".join(_get_output_names(node)) else: node_name = _get_output_name(node) @@ -3294,7 +3294,7 @@ def convert_operators(operators, outputs, ret_names, convert_map, prelude, defau unpacked = _unpack_tuple(inputs[0]) outputs.update(zip(_get_output_names(op_node), unpacked)) elif operator == "prim::prim::RaiseException": - logging.warn("raising exceptions is ignored") + logging.warning("raising exceptions is ignored") outputs[node_name] = None elif operator == "prim::If": if_out = convert_if(op_node, outputs, convert_map, prelude, default_dtype=default_dtype) From 94c17419cb72178c7fc491e1b3a8f89d7aedd94f Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Mon, 2 Nov 2020 18:23:33 +0900 Subject: [PATCH 09/11] update ci-gpu --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 17ddbabcdcf6..079001f0524b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,7 +45,7 @@ // NOTE: these lines are scanned by docker/dev_common.sh. Please update the regex as needed. --> ci_lint = "tlcpack/ci-lint:v0.62" -ci_gpu = "tlcpack/ci-gpu:v0.71" +ci_gpu = "tlcpack/ci-gpu:v0.72" ci_cpu = "tlcpack/ci-cpu:v0.71" ci_wasm = "tlcpack/ci-wasm:v0.70" ci_i386 = "tlcpack/ci-i386:v0.71" From f07f78ab057c1c33c4d5b84ddadec8b02fb9d2a5 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Mon, 2 Nov 2020 19:24:41 +0900 Subject: [PATCH 10/11] fix typo --- python/tvm/relay/frontend/pytorch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tvm/relay/frontend/pytorch.py b/python/tvm/relay/frontend/pytorch.py index 8e64a388b209..2fd207883dad 100644 --- a/python/tvm/relay/frontend/pytorch.py +++ b/python/tvm/relay/frontend/pytorch.py @@ -1863,7 +1863,7 @@ def _get_upsample_out_size(inputs, method): assert isinstance(scales, list) ishape = _infer_shape(inputs[0]) for i, scale in enumerate(scales): - out_size.append(int(math.floor(math.floor(ishape[2 + i] * scale)))) + out_size.append(int(math.floor(float(ishape[2 + i]) * scale))) return out_size From 1c4a2e87bd550c76f94b00aae9902ccd56e8d964 Mon Sep 17 00:00:00 2001 From: Masahiro Masuda Date: Tue, 3 Nov 2020 03:50:51 +0900 Subject: [PATCH 11/11] updated supported version --- tutorials/frontend/deploy_object_detection_pytorch.py | 6 +++--- tutorials/frontend/from_pytorch.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/frontend/deploy_object_detection_pytorch.py b/tutorials/frontend/deploy_object_detection_pytorch.py index 6408685febfb..2852dd3ad99d 100644 --- a/tutorials/frontend/deploy_object_detection_pytorch.py +++ b/tutorials/frontend/deploy_object_detection_pytorch.py @@ -27,8 +27,8 @@ .. code-block:: bash - pip install torch==1.4.0 - pip install torchvision==0.5.0 + pip install torch==1.7.0 + pip install torchvision==0.8.1 or please refer to official site https://pytorch.org/get-started/locally/ @@ -36,7 +36,7 @@ PyTorch versions should be backwards compatible but should be used with the proper TorchVision version. -Currently, TVM supports PyTorch 1.4 and 1.3. Other versions may +Currently, TVM supports PyTorch 1.7 and 1.4. Other versions may be unstable. """ diff --git a/tutorials/frontend/from_pytorch.py b/tutorials/frontend/from_pytorch.py index 33a05884f61d..b5bcdf6792f9 100644 --- a/tutorials/frontend/from_pytorch.py +++ b/tutorials/frontend/from_pytorch.py @@ -28,8 +28,8 @@ .. code-block:: bash - pip install torch==1.4.0 - pip install torchvision==0.5.0 + pip install torch==1.7.0 + pip install torchvision==0.8.1 or please refer to official site https://pytorch.org/get-started/locally/ @@ -37,7 +37,7 @@ PyTorch versions should be backwards compatible but should be used with the proper TorchVision version. -Currently, TVM supports PyTorch 1.4 and 1.3. Other versions may +Currently, TVM supports PyTorch 1.7 and 1.4. Other versions may be unstable. """