opacus icon indicating copy to clipboard operation
opacus copied to clipboard

run advanced_feature notebook get error

Open lmaxeniro opened this issue 2 years ago • 1 comments

🐛 Bug

run this example: https://github.com/pytorch/opacus/blob/main/tutorials/intro_to_advanced_features.ipynb, below error reported:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/var/folders/_r/hzffvgfd23sc3w0gr577_qmc0000gn/T/ipykernel_89101/506156005.py in <module>
      8 
      9 # second should fail
---> 10 model(torch.randn(10, 16)).sum().backward()
     11 
     12 model.zero_grad()

~/Documents/opacus/venv/lib/python3.7/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    873                 _global_forward_pre_hooks.values(),
    874                 self._forward_pre_hooks.values()):
--> 875             result = hook(self, input)
    876             if result is not None:
    877                 if not isinstance(result, tuple):

~/Documents/opacus/opacus/privacy_engine.py in forbid_accumulation_hook(module, _input)
     36         if p.grad_sample is not None:
     37             raise ValueError(
---> 38                 "Poisson sampling is not compatible with grad accumulation. "
     39                 "You need to call optimizer.step() after every forward/backward pass "
     40                 "or consider using BatchMemoryManager"

ValueError: Poisson sampling is not compatible with grad accumulation. You need to call optimizer.step() after every forward/backward pass or consider using BatchMemoryManager

Please reproduce using our template Colab and post here the link

To Reproduce

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

  1. simply run the notebook line-by-line
  2. the error will happen

Expected behavior

Environment

Please copy and paste the output from our environment collection script (or fill out the checklist below manually).

You can get the script and run it with:

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py

Collecting environment information... PyTorch version: 1.11.0+cu102 Is debug build: False CUDA used to build PyTorch: 10.2 ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.6 LTS (x86_64) GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 Clang version: 6.0.0-1ubuntu2 (tags/RELEASE_600/final) CMake version: Could not collect Libc version: glibc-2.27

Python version: 3.10.4 (main, Mar 31 2022, 08:41:55) [GCC 7.5.0] (64-bit runtime) Python platform: Linux-5.4.0-122-generic-x86_64-with-glibc2.27 Is CUDA available: True CUDA runtime version: Could not collect GPU models and configuration: GPU 0: NVIDIA GeForce GT 1030 Nvidia driver version: 510.73.05 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True

Versions of relevant libraries: [pip3] numpy==1.23.1 [pip3] torch==1.11.0 [pip3] torchvision==0.12.0 [conda] numpy 1.23.1 pypi_0 pypi [conda] torch 1.11.0 pypi_0 pypi [conda] torchvision 0.12.0 pypi_0 pypi

Additional context

lmaxeniro avatar Aug 01 '22 07:08 lmaxeniro

Thanks for flagging this, I think this tutorial was not updated with the latest version of Opacus, we will take a look!

alexandresablayrolles avatar Aug 03 '22 09:08 alexandresablayrolles