pytorch / opacus

Training PyTorch models with differential privacy
https://opacus.ai
Apache License 2.0
1.67k stars 332 forks source link

cannot install opacus with torch(+gpu) #551

Closed giladcohen closed 1 year ago

giladcohen commented 1 year ago

Upon calling pip install opacus pip is trying to delete my installed torch(GPU) version and install a CPU version instead.

To Reproduce

:warning: We cannot help you without you sharing reproducible code. Do not ignore this part :) Steps to reproduce the behavior:

  1. install pytorch 1.13.1: pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
  2. install opacus: pip install opacus

This is what I got:

Collecting opacus
  Downloading opacus-1.3.0-py3-none-any.whl (216 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 216.9/216.9 kB 1.5 MB/s eta 0:00:00
Collecting functorch
  Using cached functorch-1.13.0-py2.py3-none-any.whl (2.1 kB)
Requirement already satisfied: torch>=1.8 in /home/gilad/venv_py37_new/lib/python3.7/site-packages (from opacus) (1.13.1+cu117)
Requirement already satisfied: scipy>=1.2 in /home/gilad/venv_py37_new/lib/python3.7/site-packages (from opacus) (1.7.3)
Requirement already satisfied: numpy>=1.15 in /home/gilad/venv_py37_new/lib/python3.7/site-packages (from opacus) (1.19.5)
Requirement already satisfied: opt-einsum>=3.3.0 in /home/gilad/venv_py37_new/lib/python3.7/site-packages (from opacus) (3.3.0)
Requirement already satisfied: typing-extensions in /home/gilad/venv_py37_new/lib/python3.7/site-packages (from torch>=1.8->opacus) (4.0.1)
Collecting torch>=1.8
  Downloading torch-1.13.0-cp37-cp37m-manylinux1_x86_64.whl (890.2 MB)

It seems that functorch is forcing a non cuda pytorch version. I experienced the same behavior also when I tried to install opacus for torch==1.12.1+cu113.

I am using python vertion 3.7.9

Environment

(venv_py37_new) gilad@Yoshua:~/workspace$ python collect_env.py
Collecting environment information...
PyTorch version: 1.13.1+cu117
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.26

Python version: 3.7.9 (default, Aug 18 2020, 06:22:45)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.0-65-generic-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: True
CUDA runtime version: 11.1.74
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA GeForce RTX 2080 Ti
GPU 1: NVIDIA GeForce RTX 2080 Ti
GPU 2: NVIDIA GeForce RTX 2080 Ti
GPU 3: NVIDIA GeForce RTX 2080 Ti
GPU 4: NVIDIA GeForce RTX 2080 Ti
GPU 5: NVIDIA GeForce RTX 2080 Ti
GPU 6: NVIDIA GeForce RTX 2080 Ti
GPU 7: NVIDIA GeForce RTX 2080 Ti

Nvidia driver version: 525.60.11
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] geotorch==0.3.0
[pip3] numpy==1.19.5
[pip3] pytorch-ignite==0.4.8
[pip3] torch==1.13.1+cu117
[pip3] torchaudio==0.13.1+cu117
[pip3] torchdiffeq==0.2.2
[pip3] torchsummary==1.5.1
[pip3] torchvision==0.14.1+cu117
[conda] Could not collect
alexandresablayrolles commented 1 year ago

Thanks for flagging this issue! We will take a look at this.

giladcohen commented 1 year ago

I found this workaround:

1) pip install --no-deps functorch
2) pip install opacus
ffuuugor commented 1 year ago

The fix has finally been published, the problem should go away for opacus==1.4.0

Please reopen the issue if it doesn't

bwegge commented 1 year ago

Hi, I am still facing some issues with installing Opacus 1.4.0 together with PyTorch 2.0.1 into the same conda environment.

Following the suggested installation command of PyTorch (https://pytorch.org/get-started/locally/), I create a new conda environment only with PyTorch 2.0.1 but without Opacus via conda create -n pt20-pure pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia In particular, this will pull the following pytorch-related packages, as expected:

  pytorch            pytorch/win-64::pytorch-2.0.1-py3.11_cuda11.8_cudnn8_0
  pytorch-cuda       pytorch/win-64::pytorch-cuda-11.8-h24eeafa_5
  torchaudio         pytorch/win-64::torchaudio-2.0.2-py311_cu118
  torchvision        pytorch/win-64::torchvision-0.15.2-py311_cu118

On the other hand, running a modified command that also installs Opacus 1.4.0 from conda-forge via conda create -n pt20-opacus pytorch torchvision torchaudio pytorch-cuda=11.8 "opacus>=1.4" -c pytorch -c nvidia -c conda-forge will pull some outdated CPU-builds of the above packages, except the pytorch-cuda package:

  pytorch            pytorch/win-64::pytorch-1.13.1-py3.10_cpu_0
  pytorch-cuda       pytorch/win-64::pytorch-cuda-11.8-h24eeafa_5
  torchaudio         pytorch/win-64::torchaudio-0.13.1-py310_cpu
  torchvision        pytorch/win-64::torchvision-0.14.1-py310_cpu

Or does Opacus 1.4 still require PyTorch < 2.0? The release notes (https://github.com/pytorch/opacus/releases/tag/v1.4.0) say "Upgraded to PyTorch 1.13+ as required dependency", which strictly speaking would include PyTorch 2.x :). Also, the current requirements.txt on GitHub has a line "torch>=2.0" (but the latest commit to requirements.txt was after the release of Opacus 1.4.0).

color4-alt commented 5 months ago

Hey, dude, I'm facing the same problem as you. And my torch verison == 1.12.1+cu116, which is older than 2.0.