Repository: Project-MONAI/MONAI

Issue:
Error from nightly build -- tests.test_rand_weighted_cropd.TestRandWeightedCrop
**Describe the bug**
```
======================================================================
ERROR: test_rand_weighted_crop_small_roi (tests.test_rand_weighted_cropd.TestRandWeightedCrop)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jenkins/agent/workspace/Monai-pytorch-versions/tests/test_rand_weighted_cropd.py", line 33, in test_rand_weighted_crop_small_roi
    result = crop(d)
  File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/transforms/croppad/dictionary.py", line 963, in __call__
    self.randomize(d[self.w_key])
  File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/transforms/croppad/dictionary.py", line 958, in randomize
    spatial_size=self.spatial_size, w=weight_map[0], n_samples=self.num_samples, r_state=self.R
  File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/transforms/utils.py", line 397, in weighted_patch_samples
    idx = searchsorted(v, r * v[-1], right=True)
  File "/home/jenkins/agent/workspace/Monai-pytorch-versions/monai/transforms/utils_pytorch_numpy_unification.py", line 301, in searchsorted
    return torch.searchsorted(a, v, right=right)  # type: ignore
AttributeError: module 'torch' has no attribute 'searchsorted'
```

```
================================
MONAI version: 0.7.0+47.ge0f84f2a
Numpy version: 1.18.1
Pytorch version: 1.5.1
MONAI flags: HAS_EXT = True, USE_COMPILED = True
MONAI rev id: e0f84f2a858bbcab341251898438a53dc9700095

Optional dependencies:
Pytorch Ignite version: 0.4.6
Nibabel version: 3.2.1
scikit-image version: 0.15.0
Pillow version: 8.3.2
Tensorboard version: 2.1.0
gdown version: 4.0.2
TorchVision version: 0.6.1
tqdm version: 4.62.3
lmdb version: 0.98
psutil version: 5.6.7
pandas version: 0.24.2
einops version: 0.3.2
transformers version: 4.11.3
mlflow version: 1.20.2

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
```


Discussion:

Resolving patch:
diff --git a/monai/transforms/utils_pytorch_numpy_unification.py b/monai/transforms/utils_pytorch_numpy_unification.py
--- a/monai/transforms/utils_pytorch_numpy_unification.py
+++ b/monai/transforms/utils_pytorch_numpy_unification.py
@@ -16,6 +16,7 @@
 
 from monai.config.type_definitions import NdarrayOrTensor
 from monai.utils.misc import is_module_ver_at_least
+from monai.utils.type_conversion import convert_to_dst_type
 
 __all__ = [
     "moveaxis",
@@ -294,8 +295,14 @@ def isfinite(x):
 
 
 def searchsorted(a: NdarrayOrTensor, v: NdarrayOrTensor, right=False, sorter=None):
+    side = "right" if right else "left"
     if isinstance(a, np.ndarray):
-        side = "right" if right else "left"
         return np.searchsorted(a, v, side, sorter)  # type: ignore
     else:
-        return torch.searchsorted(a, v, right=right)  # type: ignore
+        if hasattr(torch, "searchsorted"):
+            return torch.searchsorted(a, v, right=right)  # type: ignore
+        else:
+            # if using old PyTorch, will convert to numpy array then compute
+            ret = np.searchsorted(a.cpu().numpy(), v.cpu().numpy(), side, sorter)  # type: ignore
+            ret, *_ = convert_to_dst_type(ret, a)
+            return ret


Test patch: