Repository: sbi-dev/sbi

Issue:
Installing sbi replaces existing torch version with 2.0.1
Hello, I have a conda environment where PyTorch 1.13 is installed. Installing `sbi` in that environment uninstalls it and installs PyTorch 2.0.1 (with `pip`) instead, as well as many other packages related to CUDA (`cudnn` stuff).

For instance, with the following environment

```
$ conda create -n tempenv python=3.9
$ conda activate tempenv
(tempenv) $ conda install pytorch=1.13.1 cpuonly -c pytorch
```

installing `sbi` leads to

```
(tempenv) $ pip install sbi
Collecting sbi
...
  Attempting uninstall: torch
    Found existing installation: torch 1.13.1
    Uninstalling torch-1.13.1:
      Successfully uninstalled torch-1.13.1
Successfully installed MarkupSafe-2.1.3 absl-py-1.4.0 arviz-0.15.1 cachetools-5.3.1 certifi-2023.5.7 charset-normalizer-3.2.0 cmake-3.26.4 contourpy-1.1.0 cycler-0.11.0 filelock-3.12.2 fonttools-4.40.0 google-auth-2.22.0 google-auth-oauthlib-1.0.0 grpcio-1.56.0 h5netcdf-1.2.0 h5py-3.9.0 idna-3.4 importlib-metadata-6.8.0 importlib-resources-6.0.0 jinja2-3.1.2 joblib-1.3.1 kiwisolver-1.4.4 lit-16.0.6 markdown-3.4.3 matplotlib-3.7.2 mpmath-1.3.0 networkx-3.1 nflows-0.14 numpy-1.25.1 nvidia-cublas-cu11-11.10.3.66 nvidia-cuda-cupti-cu11-11.7.101 nvidia-cuda-nvrtc-cu11-11.7.99 nvidia-cuda-runtime-cu11-11.7.99 nvidia-cudnn-cu11-8.5.0.96 nvidia-cufft-cu11-10.9.0.58 nvidia-curand-cu11-10.2.10.91 nvidia-cusolver-cu11-11.4.0.1 nvidia-cusparse-cu11-11.7.4.91 nvidia-nccl-cu11-2.14.3 nvidia-nvtx-cu11-11.7.91 oauthlib-3.2.2 opt-einsum-3.3.0 packaging-23.1 pandas-2.0.3 pillow-10.0.0 protobuf-4.23.4 pyasn1-0.5.0 pyasn1-modules-0.3.0 pyknos-0.15.1 pyparsing-3.0.9 pyro-api-0.1.2 pyro-ppl-1.8.5 python-dateutil-2.8.2 pytz-2023.3 requests-2.31.0 requests-oauthlib-1.3.1 rsa-4.9 sbi-0.21.0 scikit-learn-1.3.0 scipy-1.11.1 six-1.16.0 sympy-1.12 tensorboard-2.13.0 tensorboard-data-server-0.7.1 threadpoolctl-3.1.0 torch-2.0.1 tqdm-4.65.0 triton-2.0.0 tzdata-2023.3 urllib3-1.26.16 werkzeug-2.3.6 xarray-2023.6.0 xarray-einstats-0.6.0 zipp-3.16.0
```

I don't why this happens but it is quite annoying :cry: Do you know how i can solve this? Thank you for your help!



Discussion:
Thanks for reporting, that's indeed very annoying. The reason seems to be that `pyro` requires >2.0.1, see [here](https://github.com/pyro-ppl/pyro/blob/7e3d62ecf5ebf2fd3798d93e80cb554e7d38f61e/setup.py#L105).

`sbi` uses pyro for its MCMC samplers, so I don't expect that core functionality of `sbi` affected by having torch v1.x.x.

Easiest fix might be to simply pin pyro to an older version that did not have this requirement. What do you think @janfb ?

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -17,10 +17,13 @@
 # Package meta-data.
 NAME = "sbi"
 DESCRIPTION = "Simulation-based inference."
-KEYWORDS = "bayesian parameter inference system_identification simulator PyTorch"
+KEYWORDS = (
+    "bayesian parameter inference system_identification simulator PyTorch"
+)
 URL = "https://github.com/mackelab/sbi"
 EMAIL = "sbi@mackelab.org"
-AUTHOR = "Álvaro Tejero-Cantero, Jakob H. Macke, Jan-Matthis Lückmann, Conor M. Durkan, Michael Deistler, Jan Bölts"
+AUTHOR = """Álvaro Tejero-Cantero, Jakob H. Macke, Jan-Matthis Lückmann, Conor M.
+         Durkan, Michael Deistler, Jan Bölts"""
 REQUIRES_PYTHON = ">=3.6.0"
 
 REQUIRED = [
@@ -30,7 +33,7 @@
     "numpy",
     "pillow",
     "pyknos>=0.15.1",
-    "pyro-ppl>=1.3.1",
+    "pyro-ppl>=1.3.1,<1.8.5",
     "scikit-learn",
     "scipy",
     "tensorboard",
@@ -103,7 +106,9 @@ def run(self):
             pass
 
         self.status("Building Source and Wheel (universal) distribution…")
-        os.system("{0} setup.py sdist bdist_wheel --universal".format(sys.executable))
+        os.system(
+            "{0} setup.py sdist bdist_wheel --universal".format(sys.executable)
+        )
 
         self.status("Uploading the package to PyPI via Twine…")
         os.system("twine upload dist/*")
@@ -126,7 +131,9 @@ def run(self):
     author_email=EMAIL,
     python_requires=REQUIRES_PYTHON,
     url=URL,
-    packages=find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"]),
+    packages=find_packages(
+        exclude=["tests", "*.tests", "*.tests.*", "tests.*"]
+    ),
     install_requires=REQUIRED,
     extras_require=EXTRAS,
     include_package_data=True,
@@ -134,7 +141,8 @@ def run(self):
     classifiers=[
         # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
         "Development Status :: 3 - Alpha",
-        "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
+        """License :: OSI Approved :: GNU Affero General Public License v3 or later
+        (AGPLv3+)""",
         "Intended Audience :: Developers",
         "Intended Audience :: Education",
         "Intended Audience :: Science/Research",


Test patch: