pytorch / opacus

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

Allowing users to use large `target_epsilon` for debugging and research #604

Closed jeandut closed 7 months ago

jeandut commented 10 months ago

šŸš€ Feature

Allowing users to use large target_epsilon when making their pipeline DP (as input to get_noise_multiplier before make_private)

Motivation

Currently using a target budget of epsilon > 10. is generally not supported by Opacus for most datasets / batch sizes / number of gradient steps because of discretization issues stemming from Microsoft's prv_accountant (https://github.com/microsoft/prv_accountant/issues/36) from which opacus's PRVAccountant implementation originates).

I argue that this should be changed for multiple reasons:

Warning the user that the privacy budget they set could be considered as high by some industries should be sufficient. What do you think ? In the meantime is there a relatively simple hack one could use in research experiments to use large target epsilons ?

Pitch

User provides a large target_epsilon say 50. in get_noise_multiplier and it runs wo throwing:

RuntimeError: Discrete mean differs from continuous mean significantly.

By instead displaying a warning.

Alternatives

In the meantime is there a relatively simple hack one could use in research experiments to use large target epsilons ? Such as exposing another custom get_noise_multiplier function wo this limitation ?

Additional context

I was hesitating between posting it in prv_accountant or here

Solosneros commented 10 months ago

Hi @jeandut,

if I understood correctly, the $\epsilon=10$ cut off isn't chosen because of it is being not according to industry standards but rather the numerics of the implementation are breaking down at that point. The prv_accountant from Microsoft just hasn't been tested for these high epsilons (I agree with the developers there that (in most applications) higher epsilons make little sense, but I don't want to argue about that without knowing your usecase).

Could you provide privacy parameters (num_steps, noise_multiplier and subsampling_ratio) for the case where it breaks down? We were able to fork the opacus get_noise_multiplier() and make a bit more robust but we are still waiting on internal review before proposing it here.

Have you considered using the rdp accountant instead? It should work as a drop-in replacement for the prv accountant when creating the privacy_engine. The privacy guarantees of prv are tighter than rdp but in the end you will just get a larger noise_multiplier for the same target_epsilon and target_delta. The rdp implementation is more robust in my experience.

jeandut commented 10 months ago

Thank you so much @Solosneros for your quick answer ! Indeed the cutoff is due to the numerical implementation not being robust enough with large epsilon an not because of some ad-hoc logic. It is very cool that you guys have something in store to robustify it.

In my use case I am just tracing a DP curve for a research article and want to make sure that my implementation is asymptotically equivalent to the one wo DP by taking epsilon very large aka for debugging purposes. I have run into this issue for multiple parameters values but typical values include i.e.:

sample_rate
0.19120458891013384
num_total_steps
5000
dp_target_epsilon
20.0
dp_target_delta
0.001

Or

sample_rate
0.19120458891013384
num_total_steps
5000
dp_target_epsilon
50.0
dp_target_delta
0.001

As for the reason I am using prv it is because it was the default value in opacus. But you are right a quick fix would be probably to switch to rdp. I will try that in the mean time !

jeandut commented 10 months ago

Note that indeed using RDP instead of PRV allows to use high epsilons. Feel free to either close or relabel my issue.

Solosneros commented 9 months ago

Hi @jeandut,

sorry for the delay. We tried out our fix further and while it seems a bit more robust it still fails occasionally.

We'll get back to this but maybe somebody else has a fix. The RDP workaround definitely works.

Solosneros commented 9 months ago

I posted a potential fix to this to the prv github but I am not sure if it is valid. Let's see what the folks from Microsoft say. https://github.com/microsoft/prv_accountant/issues/36#issuecomment-1746533944

Solosneros commented 9 months ago

PR is open #606.

HuanyuZhang commented 8 months ago

Thanks! Will take a look.

HuanyuZhang commented 7 months ago

Committed PR #606 so I close this issue.