Skip to content

Commit

Permalink
Merge pull request #673 from bioimage-io/udpate_conda_env
Browse files Browse the repository at this point in the history
Udpate conda env
  • Loading branch information
FynnBe authored Dec 6, 2024
2 parents 485deee + ec13902 commit 9983d3e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ To keep the bioimageio.spec Python package version in sync with the (model) desc

### bioimageio.spec Python package

#### bioimageio.spec 0.5.3.7 (to be released)

* update conda environments (remove `cpuonly` from pytorch envs)

#### bioimageio.spec 0.5.3.6

* fix URL validation (checking with actual http requests was erroneously skipped)
Expand Down
3 changes: 3 additions & 0 deletions bioimageio/spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
dump_description,
validate_format,
)
from ._get_conda_env import BioimageioCondaEnv, get_conda_env
from ._internal import settings
from ._internal.common_nodes import InvalidDescr
from ._internal.constants import VERSION
Expand Down Expand Up @@ -57,6 +58,7 @@
"AnyNotebookDescr",
"application",
"ApplicationDescr",
"BioimageioCondaEnv",
"build_description",
"common",
"conda_env",
Expand All @@ -66,6 +68,7 @@
"enable_pretty_validation_errors_in_ipynb",
"generic",
"GenericDescr",
"get_conda_env",
"get_resource_package_content",
"InvalidDescr",
"LatestResourceDescr",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,68 +83,70 @@ def _get_default_pytorch_env(
if pytorch_version is None:
pytorch_version = Version("1.10.1")

# dependencies to install pytorch according to https://pytorch.org/get-started/previous-versions/
if (v := str(pytorch_version)) == "1.6.0":
deps: List[Union[str, PipDeps]] = [f"pytorch=={v}", "torchvision==0.7.0"]
# dependencies to install pytorch according to
# https://pytorch.org/get-started/previous-versions/
v = str(pytorch_version)
deps: List[Union[str, PipDeps]] = [f"pytorch=={v}"]
if v == "1.6.0":
deps += ["torchvision==0.7.0"]
elif v == "1.7.0":
deps = [f"pytorch=={v}", "torchvision==0.8.0", "torchaudio==0.7.0"]
deps += ["torchvision==0.8.0", "torchaudio==0.7.0"]
elif v == "1.7.1":
deps = [f"pytorch=={v}", "torchvision==0.8.2", "torchaudio==0.7.1"]
deps += ["torchvision==0.8.2", "torchaudio==0.7.1"]
elif v == "1.8.0":
deps = [f"pytorch=={v}", "torchvision==0.9.0", "torchaudio==0.8.0"]
deps += ["torchvision==0.9.0", "torchaudio==0.8.0"]
elif v == "1.8.1":
deps = [f"pytorch=={v}", "torchvision==0.9.1", "torchaudio==0.8.1"]
deps += ["torchvision==0.9.1", "torchaudio==0.8.1"]
elif v == "1.9.0":
deps = [f"pytorch=={v}", "torchvision==0.10.0", "torchaudio==0.9.0"]
deps += ["torchvision==0.10.0", "torchaudio==0.9.0"]
elif v == "1.9.1":
deps = [f"pytorch=={v}", "torchvision==0.10.1", "torchaudio==0.9.1"]
deps += ["torchvision==0.10.1", "torchaudio==0.9.1"]
elif v == "1.10.0":
deps = [f"pytorch=={v}", "torchvision==0.11.0", "torchaudio==0.10.0"]
deps += ["torchvision==0.11.0", "torchaudio==0.10.0"]
elif v == "1.10.1":
deps = [f"pytorch=={v}", "torchvision==0.11.2", "torchaudio==0.10.1"]
deps += ["torchvision==0.11.2", "torchaudio==0.10.1"]
elif v == "1.11.0":
deps = [f"pytorch=={v}", "torchvision==0.12.0", "torchaudio==0.11.0"]
deps += ["torchvision==0.12.0", "torchaudio==0.11.0"]
elif v == "1.12.0":
deps = [f"pytorch=={v}", "torchvision==0.13.0", "torchaudio==0.12.0"]
deps += ["torchvision==0.13.0", "torchaudio==0.12.0"]
elif v == "1.12.1":
deps = [f"pytorch=={v}", "torchvision==0.13.1", "torchaudio==0.12.1"]
deps += ["torchvision==0.13.1", "torchaudio==0.12.1"]
elif v == "1.13.0":
deps = [f"pytorch=={v}", "torchvision==0.14.0", "torchaudio==0.13.0"]
deps += ["torchvision==0.14.0", "torchaudio==0.13.0"]
elif v == "1.13.1":
deps = [f"pytorch=={v}", "torchvision==0.14.1", "torchaudio==0.13.1"]
deps += ["torchvision==0.14.1", "torchaudio==0.13.1"]
elif v == "2.0.0":
deps = [f"pytorch=={v}", "torchvision==0.15.0", "torchaudio==2.0.0"]
deps += ["torchvision==0.15.0", "torchaudio==2.0.0"]
elif v == "2.0.1":
deps = [f"pytorch=={v}", "torchvision==0.15.2", "torchaudio==2.0.2"]
deps += ["torchvision==0.15.2", "torchaudio==2.0.2"]
elif v == "2.1.0":
deps = [f"pytorch=={v}", "torchvision==0.16.0", "torchaudio==2.1.0"]
deps += ["torchvision==0.16.0", "torchaudio==2.1.0"]
elif v == "2.1.1":
deps = [f"pytorch=={v}", "torchvision==0.16.1", "torchaudio==2.1.1"]
deps += ["torchvision==0.16.1", "torchaudio==2.1.1"]
elif v == "2.1.2":
deps = [f"pytorch=={v}", "torchvision==0.16.2", "torchaudio==2.1.2"]
deps += ["torchvision==0.16.2", "torchaudio==2.1.2"]
elif v == "2.2.0":
deps = [f"pytorch=={v}", "torchvision==0.17.0", "torchaudio==2.2.0"]
deps += ["torchvision==0.17.0", "torchaudio==2.2.0"]
elif v == "2.2.1":
deps = [f"pytorch=={v}", "torchvision==0.17.1", "torchaudio==2.2.1"]
deps += ["torchvision==0.17.1", "torchaudio==2.2.1"]
elif v == "2.2.2":
deps = [f"pytorch=={v}", "torchvision==0.17.2", "torchaudio==2.2.2"]
deps += ["torchvision==0.17.2", "torchaudio==2.2.2"]
elif v == "2.3.0":
deps = [f"pytorch=={v}", "torchvision==0.18.0", "torchaudio==2.3.0"]
deps += ["torchvision==0.18.0", "torchaudio==2.3.0"]
elif v == "2.3.1":
deps = [f"pytorch=={v}", "torchvision==0.18.1", "torchaudio==2.3.1"]
deps += ["torchvision==0.18.1", "torchaudio==2.3.1"]
elif v == "2.4.0":
deps = [f"pytorch=={v}", "torchvision==0.19.0", "torchaudio==2.4.0"]
deps += ["torchvision==0.19.0", "torchaudio==2.4.0"]
elif v == "2.4.1":
deps = [f"pytorch=={v}", "torchvision==0.19.1", "torchaudio==2.4.1"]
deps += ["torchvision==0.19.1", "torchaudio==2.4.1"]
elif v == "2.5.0":
deps = [f"pytorch=={v}", "torchvision==0.20.0", "torchaudio==2.5.0"]
deps += ["torchvision==0.20.0", "torchaudio==2.5.0"]
else:
set_github_warning(
"UPDATE NEEDED", f"Specify pins for additional pytorch=={v} dependencies!"
"UPDATE NEEDED",
f"Leaving torchvision and torchaudio unpinned for pytorch=={v}",
)
deps = [f"pytorch=={v}", "torchvision", "torchaudio"]

deps.append("cpuonly")
deps += ["torchvision", "torchaudio"]

# avoid `undefined symbol: iJIT_NotifyEvent` from `torch/lib/libtorch_cpu.so`
# see https://github.com/pytorch/pytorch/issues/123097
Expand All @@ -153,9 +155,7 @@ def _get_default_pytorch_env(
):
deps.append("mkl ==2024.0.0")

if pytorch_version.major == 1 or (
pytorch_version.major == 2 and pytorch_version.minor < 2
):
if pytorch_version < Version("2.2"):
# avoid ImportError: cannot import name 'packaging' from 'pkg_resources'
# see https://github.com/pypa/setuptools/issues/4376#issuecomment-2126162839
deps.append("setuptools <70.0.0")
Expand Down
4 changes: 2 additions & 2 deletions bioimageio/spec/conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def _normalize_bioimageio_conda_env(self):
pip_section = None

if (
pip_section is not None
and any(pd.startswith("bioimageio.core") for pd in pip_section.pip)
pip_section is None
or any(pd.startswith("bioimageio.core") for pd in pip_section.pip)
) and not any(
d.startswith("bioimageio.core")
or d.startswith("conda-forge::bioimageio.core")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_get_conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_get_conda_env(
w: Mapping[str, Any],
unet2d_path: Path,
):
from bioimageio.spec.get_conda_env import get_conda_env
from bioimageio.spec import get_conda_env

with ValidationContext(perform_io_checks=False, root=unet2d_path.parent):
w_descr = descr_class.model_validate(w)
Expand All @@ -78,10 +78,10 @@ def test_get_conda_env(


def test_get_default_pytorch_env():
from bioimageio.spec._internal.version_type import Version
from bioimageio.spec.get_conda_env import (
from bioimageio.spec._get_conda_env import (
_get_default_pytorch_env, # pyright: ignore[reportPrivateUsage]
)
from bioimageio.spec._internal.version_type import Version

versions: Dict[str, List[Optional[str]]] = {
"pytorch": [
Expand Down

0 comments on commit 9983d3e

Please sign in to comment.