pytorch / opacus

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

Can opacus only inject differential noise in only one layer of parameters or some target layers? #615

Closed hacker-jerry closed 5 months ago

hacker-jerry commented 6 months ago

Hi, I noticed that Opacus is on the whole model to be performed differential privacy,whether can only on a layer parameter performed differential privacy(density gradient,adding noise)in training.

For example, consider a DNN classifier where I want to achieve differential privacy only for the classifier layer, and therefore only CLIP the parameters of that layer, and also only inject noise into that layer. How should this be done?

Thanks!

HuanyuZhang commented 6 months ago

You can apply DP optimizer to the desired part of model and apply a non-private optimizer to the remaining. For example, after you privatize the mode by the privacy engine, only apply the private optimizer to the parameters in the classification layer and create another non-private optimizer which applied to the other model parameters.

HuanyuZhang commented 5 months ago

Close the task due to no response.