pytorch / opacus

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

problem about run the opacus example #76

Closed wlnancy closed 4 years ago

wlnancy commented 4 years ago

Feature

I try to run the opacus example in the pycharm, but it occurs the error : AttributeError: 'Parameter' object has no attribute 'grad_sample'. And I don't know how to resolve it.

sayanghosh commented 4 years ago

Hi @wlnancy could you try to share the code you have so that the error can be reproduced ? It would be easier to debug that, and understand if the issue is coming from Opacus or from the IDE you are using.

wlnancy commented 4 years ago

Yeah,@sayanghosh, I try to follow the blog 'https://blog.openmined.org/pysyft-opacus-federated-learning-with-differential-privacy/' to do the experiment. And it occurs the error mentioned about.

ashkan-software commented 4 years ago

Hi @wlnancy. Thanks for pointing this out. I will help you resolve this :)

Could you please paste your error in the whole stack? (the entire output of the error you see). That way we can see which line this error is coming from.

At this point, it's hard for us to see which line is causing this issue.

karthikprasad commented 4 years ago

Hi @wlnancy, I ran the example you pointed to on Google Colab and ran into the same issue as you did. I see that you have already raised an issue on PySyft (https://github.com/OpenMined/PySyft/issues/4631); I think it would be best to follow up there.

wlnancy commented 4 years ago

Hi@ashkan-software,here is the entir output: "D:\Program Files\Python\Python37\python.exe" F:/python/pysyft+ocapus.py D:\Program Files\Python\Python37\lib\site-packages\numpy_distributor_init.py:32: UserWarning: loaded more than 1 DLL from .libs: D:\Program Files\Python\Python37\lib\site-packages\numpy.libs\libopenblas.NOIJJG62EMASZI6NYURL6JBKM4EVBGM7.gfortran-win_amd64.dll D:\Program Files\Python\Python37\lib\site-packages\numpy.libs\libopenblas.PYQHXLVVQ7VESDPUVUADXEVJOBGHJPAY.gfortran-win_amd64.dll stacklevel=1) D:\Program Files\Python\Python37\lib\site-packages\opacus\privacy_engine.py:111: UserWarning: Secure RNG turned off. This is perfectly fine for experimentation as it allows for much faster training performance, but remember to turn it on and retrain one last time before production with secure_rng turned on. "Secure RNG turned off. This is perfectly fine for experimentation as it allows " D:\Program Files\Python\Python37\lib\site-packages\opacus\privacy_engine.py:111: UserWarning: Secure RNG turned off. This is perfectly fine for experimentation as it allows for much faster training performance, but remember to turn it on and retrain one last time before production with secure_rng turned on. "Secure RNG turned off. This is perfectly fine for experimentation as it allows " 0%| | 0/234 [00:00<?, ?it/s] Traceback (most recent call last): File "F:/python/pysyft+ocapus.py", line 115, in train(epoch, delta=1e-5) File "F:/python/pysyft+ocapus.py", line 99, in train optimizer.step() File "D:\Program Files\Python\Python37\lib\site-packages\opacus\privacy_engine.py", line 190, in dp_step self.privacy_engine.step() File "D:\Program Files\Python\Python37\lib\site-packages\opacus\privacy_engine.py", line 260, in step self.clipper.clip_and_accumulate() File "D:\Program Files\Python\Python37\lib\site-packages\opacus\per_sample_gradient_clip.py", line 192, in clip_and_accumulate flat=not self.norm_clipper.is_per_layer, File "D:\Program Files\Python\Python37\lib\site-packages\opacus\utils\tensor_utils.py", line 42, in calc_sample_norms norms = [param.view(len(param), -1).norm(2, dim=-1) for name, param in named_params] File "D:\Program Files\Python\Python37\lib\site-packages\opacus\utils\tensor_utils.py", line 42, in norms = [param.view(len(param), -1).norm(2, dim=-1) for name, param in named_params] File "D:\Program Files\Python\Python37\lib\site-packages\opacus\per_sample_gradient_clip.py", line 262, in if p.requires_grad AttributeError: 'Parameter' object has no attribute 'grad_sample' And I had already change the code in line 18 because it occurs the error that the number of parameter is not match,I just delete ',' .

wlnancy commented 4 years ago

Hi @karthikprasad ,because the error about download the package mentioned on PySyft (OpenMined/PySyft#4631) has been solved, and this is another error about the code.

ashkan-software commented 4 years ago

I see @karthikprasad asked this in issue 4631 recently. Thanks @karthikprasad for following up on this issue on PySyft! Really helpful to get PySyft community involved in this, to figure out what the error is.

@wlnancy, let us follow this issue on the PySyft Github. I will close this now.

In the meantime, thanks to your comment @wlnancy we started looking into adding windows support for Opacus. :)