Skip to content

Commit 4d87ffa

Browse files
committed
Update installation dependencies in notebooks following the new torch $ torchmetrics version pins; 2) make gpu argument to be more robust
1 parent c80075a commit 4d87ffa

28 files changed

Lines changed: 129 additions & 261 deletions

biapy/_biapy.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from typing import (
2121
Optional,
2222
Dict,
23+
List,
24+
Tuple,
2325
Union,
2426
)
2527
from bioimageio.spec.model.v0_5 import (
@@ -107,14 +109,33 @@ def isatty(self):
107109
return False
108110

109111

112+
GpuArg = Union[str, int, List[Union[str, int]], Tuple[Union[str, int], ...], None]
113+
114+
115+
def _normalize_gpu_arg(gpu: GpuArg) -> str:
116+
"""Normalize 'gpu' (str, int, or list/tuple of either) into a CUDA_VISIBLE_DEVICES-style string."""
117+
if gpu is None:
118+
return ""
119+
if isinstance(gpu, str):
120+
return gpu.strip()
121+
if isinstance(gpu, int):
122+
return str(gpu)
123+
if isinstance(gpu, (list, tuple)):
124+
return ",".join(str(g).strip() for g in gpu)
125+
raise TypeError(
126+
f"'gpu' must be a str, int, list or tuple (got {type(gpu).__name__}). "
127+
"Examples: gpu=0, gpu='0', gpu='0,1', gpu=[0, 1]."
128+
)
129+
130+
110131
class BiaPy:
111132
def __init__(
112133
self,
113134
config: Union[str, dict, CN],
114135
result_dir: Optional[str] = None,
115136
name: Optional[str] = "unknown_job",
116137
run_id: Optional[int] = 1,
117-
gpu: Optional[str] = "",
138+
gpu: GpuArg = "",
118139
world_size: Optional[int] = 1,
119140
local_rank: Optional[int] = -1,
120141
dist_on_itp: Optional[bool] = False,
@@ -146,8 +167,10 @@ def __init__(
146167
run_id: int, optional
147168
Run number of the same job. Defaults to 1.
148169
149-
gpu: str, optional
150-
GPU number according to 'nvidia-smi' command. Defaults to None.
170+
gpu: str, int, list or tuple, optional
171+
GPU number(s) according to 'nvidia-smi' command, or "mps" for Apple Silicon. Accepts
172+
a single value (``0`` or ``"0"``) or multiple (``"0,1"``, ``[0, 1]``, ``(0, 1)``).
173+
Defaults to "" (CPU).
151174
152175
world_size: int, optional
153176
Number of distributed processes. Defaults to 1.
@@ -220,7 +243,7 @@ def __init__(
220243
result_dir=result_dir,
221244
name=name,
222245
run_id=run_id,
223-
gpu=gpu,
246+
gpu=_normalize_gpu_arg(gpu),
224247
world_size=world_size,
225248
local_rank=local_rank,
226249
dist_on_itp=dist_on_itp,

biapy/utils/env/Dockerfile_CUDA10.2

Lines changed: 0 additions & 58 deletions
This file was deleted.

biapy/utils/env/conda_forge_meta.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ requirements:
2424
- setuptools
2525
run:
2626
- python >={{ python_min }}
27-
# These must mirror pyproject.toml exactly, or the `pip check` in the test
28-
# section fails against the metadata of the installed sdist. conda-forge's
29-
# torchvision 0.27.1 is built against pytorch >=2.12.0,<2.13.0a0.
30-
- pytorch >=2.12,<2.13
31-
- torchvision >=0.27,<0.28
27+
# Must mirror pyproject.toml's torch/torchvision range exactly, or the `pip
28+
# check` in the test section fails against the installed sdist's metadata.
29+
- pytorch >=2.9,<3.0
30+
- torchvision >=0.24,<1.0
3231
- timm ==1.0.14
3332
- pytorch-msssim
3433
- torchmetrics >=1.4,<1.5

notebooks/BiaPy_Inference.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,10 @@
356356
],
357357
"source": [
358358
"#@markdown ##Play to install BiaPy and its dependences\n",
359-
"# Install latest release of BiaPy\n",
360-
"!pip install biapy==3.7.0\n",
361-
"\n",
362-
"# Then install Pytorch\n",
363-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
364-
"\n",
365-
"# Finally install some packages that rely on the Pytorch installation\n",
366-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
359+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
360+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
361+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
362+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
367363
"\n",
368364
"import os\n",
369365
"import sys\n",

notebooks/Data_Augments.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,10 @@
440440
],
441441
"source": [
442442
"#@markdown ##Play to install BiaPy and its dependences\n",
443-
"# Install latest release of BiaPy\n",
444-
"!pip install biapy==3.7.0\n",
445-
"\n",
446-
"# Then install Pytorch\n",
447-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
448-
"\n",
449-
"# Finally install some packages that rely on the Pytorch installation\n",
450-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
443+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
444+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
445+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
446+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
451447
"\n",
452448
"\n",
453449
"import os\n",

notebooks/Data_Preprocessing.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,10 @@
340340
],
341341
"source": [
342342
"#@markdown ##Play to install BiaPy and its dependences\n",
343-
"# Install latest release of BiaPy\n",
344-
"!pip install biapy==3.7.0\n",
345-
"\n",
346-
"# Then install Pytorch\n",
347-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
348-
"\n",
349-
"# Finally install some packages that rely on the Pytorch installation\n",
350-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
343+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
344+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
345+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
346+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
351347
"\n",
352348
"\n",
353349
"import os\n",

notebooks/classification/BiaPy_2D_Classification.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,10 @@
466466
],
467467
"source": [
468468
"#@markdown ##Play to install BiaPy and its dependences\n",
469-
"# Install latest release of BiaPy\n",
470-
"!pip install biapy==3.7.0\n",
471-
"\n",
472-
"# Then install Pytorch\n",
473-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
474-
"\n",
475-
"# Finally install some packages that rely on the Pytorch installation\n",
476-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
469+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
470+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
471+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
472+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
477473
"\n",
478474
"import os\n",
479475
"import sys\n",

notebooks/classification/BiaPy_2D_Classification_Butterfly.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,10 @@
466466
],
467467
"source": [
468468
"#@markdown ##Play to install BiaPy and its dependences\n",
469-
"# Install latest release of BiaPy\n",
470-
"!pip install biapy==3.7.0\n",
471-
"\n",
472-
"# Then install Pytorch\n",
473-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
474-
"\n",
475-
"# Finally install some packages that rely on the Pytorch installation\n",
476-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
469+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
470+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
471+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
472+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
477473
"\n",
478474
"import os\n",
479475
"import sys\n",

notebooks/classification/BiaPy_3D_Classification.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,14 +471,10 @@
471471
],
472472
"source": [
473473
"#@markdown ##Play to install BiaPy and its dependences\n",
474-
"# Install latest release of BiaPy\n",
475-
"!pip install biapy==3.7.0\n",
476-
"\n",
477-
"# Then install Pytorch\n",
478-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
479-
"\n",
480-
"# Finally install some packages that rely on the Pytorch installation\n",
481-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
474+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
475+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
476+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
477+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
482478
"\n",
483479
"import os\n",
484480
"import sys\n",

notebooks/denoising/BiaPy_2D_Denoising.ipynb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,10 @@
435435
],
436436
"source": [
437437
"#@markdown ##Play to install BiaPy and its dependences\n",
438-
"# Install latest release of BiaPy\n",
439-
"!pip install biapy==3.7.0\n",
440-
"\n",
441-
"# Then install Pytorch\n",
442-
"!pip install torch==2.12.1 torchvision==0.27.1\n",
443-
"\n",
444-
"# Finally install some packages that rely on the Pytorch installation\n",
445-
"!pip install timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
438+
"# Install BiaPy plus the packages Colab doesn't already ship. PyTorch/torchvision are\n",
439+
"# left untouched (BiaPy accepts whatever version Colab provides), which avoids Colab's\n",
440+
"# disruptive \"restart the runtime\" reinstall and keeps this cell fast.\n",
441+
"!pip install biapy timm==1.0.14 pytorch-msssim torchmetrics[image]==1.4.*\n",
446442
"\n",
447443
"import os\n",
448444
"import sys\n",

0 commit comments

Comments
 (0)