pytorch / opacus

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

AttributeError: The following layers do not have gradients #590

Closed Camelliavin closed 8 months ago

Camelliavin commented 1 year ago

Recently, I have been trying an example of opacus, and the code is here. when I'm running

python src/federated_main_s2.py --epochs=1 --num_users=1 --frac=1. --local_ep=100 --local_bs=50 --virtual_batch_size=50 --optimizer='sgd' --lr=0.001 --momentum=0.9 --dataset='dr' --dr_from_np=1 --withDP=1 --max_grad_norm=2. --noise_multiplier=1. --delta=1e-4

An error occurred: image

By the way, the opacus version I am using is v0.13.0. And when I change the version of opacus, it will have other errors. I have tried v0.15.0 and v1.0.0, and the following errors will occur: 1683802352123

It seems like it's an issue with opacus. Can someone solve it? I would be very grateful if this mistake could be resolved.

shakeelakram00 commented 1 year ago

!pip install opacus==0.14.0 I hope it may work for you. If you see the documents in the link provided in your comment, the exact compatible version is stated somewhere in it.

HuanyuZhang commented 8 months ago

I assume you have solved this issue. Feel free to re-open it if it is needed.

HamdanZoghbor commented 3 months ago

I have a similar issue, I am using version 0.15.0 and I have yet to solve it. Do you know what what it might be? My intuition is saying I messed up on the backward pass but I am not very sure.

HamdanZoghbor commented 3 months ago

!pip install opacus==0.14.0 I hope it may work for you. If you see the documents in the link provided in your comment, the exact compatible version is stated somewhere in it.

How would this help? can you explain what to do if that solution did not work?