You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by jr...@apache.org on 2020/11/06 02:53:03 UTC

[incubator-tvm] 02/02: SciPy causes crashes

This is an automated email from the ASF dual-hosted git repository.

jroesch pushed a commit to branch cargo-build
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git

commit 1604de7f94524c2a79df6aaf50c578a010be9681
Author: Jared Roesch <jr...@octoml.ai>
AuthorDate: Thu Nov 5 18:52:41 2020 -0800

    SciPy causes crashes
---
 python/tvm/relay/frontend/__init__.py                  | 3 ---
 python/tvm/relay/frontend/tensorflow.py                | 6 ++++--
 python/tvm/topi/testing/conv1d_transpose_ncw_python.py | 3 +--
 python/tvm/topi/testing/conv2d_hwcn_python.py          | 2 +-
 tests/python/topi/python/test_topi_sparse.py           | 2 +-
 5 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/python/tvm/relay/frontend/__init__.py b/python/tvm/relay/frontend/__init__.py
index 7e16499..aa8ac4f 100644
--- a/python/tvm/relay/frontend/__init__.py
+++ b/python/tvm/relay/frontend/__init__.py
@@ -20,9 +20,6 @@ Frontends for constructing Relay programs.
 Contains the model importers currently defined
 for Relay.
 """
-
-from __future__ import absolute_import
-
 from .mxnet import from_mxnet
 from .mxnet_qnn_op_utils import quantize_conv_bias_mkldnn_from_var
 from .keras import from_keras
diff --git a/python/tvm/relay/frontend/tensorflow.py b/python/tvm/relay/frontend/tensorflow.py
index c6079b4..0283146 100644
--- a/python/tvm/relay/frontend/tensorflow.py
+++ b/python/tvm/relay/frontend/tensorflow.py
@@ -904,10 +904,12 @@ def _batch_matmul():
 
 
 def _sparse_tensor_dense_matmul():
-    # Sparse utility from scipy
-    from scipy.sparse import csr_matrix
 
     def _impl(inputs, attr, params, mod):
+        # Loading this by default causes TVM to not be loadable from other languages.
+        # Sparse utility from scipy
+        from scipy.sparse import csr_matrix
+
         assert len(inputs) == 4, "There should be 4 input tensors"
 
         indices_tensor = _infer_value(inputs[0], params, mod).asnumpy()
diff --git a/python/tvm/topi/testing/conv1d_transpose_ncw_python.py b/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
index 85e1410..642908a 100644
--- a/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
+++ b/python/tvm/topi/testing/conv1d_transpose_ncw_python.py
@@ -17,11 +17,9 @@
 # pylint: disable=unused-variable
 """Transposed 1D convolution in python"""
 import numpy as np
-import scipy
 import tvm.topi.testing
 from tvm.topi.nn.utils import get_pad_tuple1d
 
-
 def conv1d_transpose_ncw_python(a_np, w_np, stride, padding, output_padding):
     """Transposed 1D convolution operator in NCW layout.
 
@@ -51,6 +49,7 @@ def conv1d_transpose_ncw_python(a_np, w_np, stride, padding, output_padding):
         3-D with shape [batch, out_channel, out_width]
 
     """
+    import scipy
     batch, in_c, in_w = a_np.shape
     _, out_c, filter_w = w_np.shape
     opad = output_padding[0]
diff --git a/python/tvm/topi/testing/conv2d_hwcn_python.py b/python/tvm/topi/testing/conv2d_hwcn_python.py
index 9ee66df..bcfd921 100644
--- a/python/tvm/topi/testing/conv2d_hwcn_python.py
+++ b/python/tvm/topi/testing/conv2d_hwcn_python.py
@@ -17,7 +17,6 @@
 # pylint: disable=invalid-name, line-too-long, unused-variable, too-many-locals
 """Convolution in python"""
 import numpy as np
-import scipy.signal
 from tvm.topi.nn.utils import get_pad_tuple
 
 
@@ -45,6 +44,7 @@ def conv2d_hwcn_python(a_np, w_np, stride, padding):
     b_np : np.ndarray
         4-D with shape [out_height, out_width, out_channel, batch]
     """
+    import scipy.signal
     in_height, in_width, in_channel, batch = a_np.shape
     kernel_h, kernel_w, _, num_filter = w_np.shape
     if isinstance(stride, int):
diff --git a/tests/python/topi/python/test_topi_sparse.py b/tests/python/topi/python/test_topi_sparse.py
index 62f49e2..fb5faf9 100644
--- a/tests/python/topi/python/test_topi_sparse.py
+++ b/tests/python/topi/python/test_topi_sparse.py
@@ -25,7 +25,6 @@ from tvm.topi.utils import get_const_tuple
 import tvm.contrib.sparse as tvmsp
 from collections import namedtuple
 import time
-import scipy.sparse as sp
 import tvm.testing
 
 _sparse_dense_implement = {
@@ -248,6 +247,7 @@ def test_dense():
 
 
 def test_sparse_dense_csr():
+    import scipy.sparse as sp
     M, N, K, density = 1, 17, 47, 0.2
     X_np = np.random.randn(M, K).astype("float32")
     W_sp_np = sp.random(N, K, density=density, format="csr", dtype="float32")