Skip to content

Commit

Permalink
Simplify specifying torch dependency (#642)
Browse files Browse the repository at this point in the history
ivadomed now <ivadomed/ivadomed#1129> specifies torch
as a standard dependency, without giving special manual instructions for it.

This means there's finally no need to pin a torch version here in axondeepseg;
previously, we had to match their version in our environment.yml because it was
a manual step in their install instructions. But now the metadata makes pip handle it.

ivadomed gave special install instructions to try to handle the complicated mess that it
hardware (i.e. CPU vs GPU vs hyper modern CUDA-11-only GPUs) compatibility.
But now they're just leaning on the 80%-20% rule of thumb: >80% of people are covered
by the default torch builds. And we know how to handle the <20% cases of people with
CUDA-11-only GPUs or Windows machines with GPUs by having them install with
'--extra-index-url = https://download.pytorch.org/whl/<hardware-specific-build>'

axondeepseg was pushing the CPU version of torch on people, assuming that most users
would not own GPUs and that in the Linux case it would be very wasteful, maybe even
make ADS uninstallable for some users. We gave our own manual instructions that
duplicated ivadomed's for how to switch to the GPU version. That process meant double
the downloads and likely mismatched versions, and maintenance work on our end
as we would have to update the manual instructions whenever ivadomed did.

Instead, follow torch's defaults, like ivadomed now does. But since the users with
Linux and CPU-only hardware is still fairly common, highlight --extra-index-url as an
optional *pre*step, allowing for the same final install but avoiding the double-download
and likely versioning mistakes.

Overall:

- Windows and macOS continue to have no GPU support
- Linux always has GPU support, even if it doesn't need it; this balloons the
  default install, but anyone using torch now has this same problem and the
  consensus seems to be just to pay for bigger disks that can tolerate the waste
- The relatively common case of Linux users without GPUs have an escape
  hatch to avoid the large download 
- Windows users with GPUs have a way to use them
  (`--extra-index-url https://download.pytorch.org/whl/cu102`), but we don't
  document nor support this
- Linux/Windows users with super new CUDA-11-only GPUs also have a
  way to use them, which we we also don't document nor support directly

Fixes ivadomed/ivadomed#861 (comment)

Related: spinalcordtoolbox/spinalcordtoolbox#3790

In passing, remove the redundant parts of the `conda env create` line.

Co-authored-by: Mathieu Boudreau, PhD <emb6150@gmail.com>
Co-authored-by: Armand <83031821+hermancollin@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 25, 2022
1 parent 1151d70 commit 21c4054
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
31 changes: 19 additions & 12 deletions docs/source/documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,31 @@ To install ``git``, please follow instructions for your operating system on the
Install AxonDeepSeg
-------------------

To install AxonDeepSeg, "clone" AxonDeepSeg's repository (you will need to have ``git`` installed on your system) and then open the directory::
To install AxonDeepSeg, in a terminal window (macOS or Linux) or Anaconda Prompt (Windows), "clone" AxonDeepSeg's repository (you will need to have ``git`` installed on your system) and then open the directory::

git clone https://github.com/neuropoly/axondeepseg.git
cd axondeepseg

Virtual environments are a tool to separate the Python environment and packages used between Python projects. They allow for different versions of Python packages to be installed and managed for the specific needs of your projects. There are several virtual environment managers available, but the one we recommend and will use in our installation guide is `conda <https://conda.io/docs/>`_, which is installed by default with Miniconda. We strongly recommend you create a virtual environment before you continue with your installation.
Virtual environments are a tool to separate the Python environment and packages used between Python projects. They allow for different versions of Python packages to be installed and managed for the specific needs of your projects. There are several virtual environment managers available, but the one we recommend and will use in our installation guide is `conda <https://conda.io/docs/>`_, which is installed by default with Miniconda. We strongly recommend you install into a virtual environment.

.. NOTE :: Linux systems can accelerate some of AxonDeepSeg's functions with an `NVIDIA GPU <https://developer.nvidia.com/cuda-gpus>`_, but these are expensive and rare, and if you do not own one you can save some time and space by not downloading the accelerated codes. You can do this by putting this in your `pip.conf <https://pip.pypa.io/en/stable/topics/configuration/#location>`_ before continuing:
::
# ~/.config/pip/pip.conf
[install]
extra-index-url =
https://download.pytorch.org/whl/cpu
.. comment: There's similar configs used for the opposite cases:
owning a GPU that's so new it needs CUDA 11, or owning a GPU but running Windows.
See https://github.com/axondeepseg/axondeepseg/pull/642#issuecomment-1142311380.
We don't document them publically because they are rare and the distraction will sew confusion.
People in these situations can ask us for help.
To setup a Python virtual environment named "ads_venv" with all the required packages, in a terminal window (macOS or Linux) or Anaconda Prompt (Windows) run the following command and answer "y" to the installation instructions::
conda env create -f environment.yml -n ads_venv
To setup the Python virtual environment with all the required packages, run the following command::

conda env create

.. WARNING :: For some users, the installation may take up to 30 minutes as many dependencies have shared subdependencies, and resolving these potential conflicts takes time. If that's the case, we encourage you to take a break from your screen and go for a walk while listening to the `AxonDeepSeg Spotify playlist <https://open.spotify.com/playlist/27LVNnfhTKjVOli6bPCaV5?si=OydcwxoOSamwCsg3xcqybw>`_.
Expand Down Expand Up @@ -167,14 +182,6 @@ Known issues
~~~~~~~~~~~~
1. The FSLeyes installation doesn't always work on Linux. Refer to the `FSLeyes installation guide <https://users.fmrib.ox.ac.uk/~paulmc/fsleyes/userdoc/latest/install.html>`_ if you need. In our testing, most issues came from the installation of the wxPython package.

GPU Support
-----------

If you have a compatible NVIDIA GPU card that supports CUDA11 and with the right driver installed, running the following command after installing AxonDeepSeg will install the necessary ``torch`` and ``torchvision`` versions for GPU use of AxonDeepSeg::

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 --find-links https://download.pytorch.org/whl/torch_stable.html

For more information aboud CPU and GPU support, please view the `IVADOMED documentation page <https://ivadomed.org/installation.html#step-3-install-torch-and-torchvision-with-cpu-or-gpu-support>`_ about it.

Existing models
===============
Expand Down
7 changes: 1 addition & 6 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,5 @@ dependencies:
- pip:
- opencv-contrib-python
- opencv-python-headless
- --find-links https://download.pytorch.org/whl/torch_stable.html
- torch==1.8.1+cpu; sys_platform != "darwin"
- torchvision==0.9.1+cpu; sys_platform != "darwin"
- torch==1.8.1;sys_platform == "darwin"
- torchvision==0.9.1; sys_platform == "darwin"
- protobuf==3.20.1
- ivadomed==2.9.5
- ivadomed~=2.9.6

0 comments on commit 21c4054

Please sign in to comment.