pytorch / opacus

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

PRV Accountant fails for specific input values for its args #601

Closed gauriprdhn closed 7 months ago

gauriprdhn commented 10 months ago

🐛 Bug

Please reproduce using our template Colab and post here the link

[Check Here](https://colab.research.google.com/drive/1zO7T7hfR45XaaFsVzhQ0qu5rQF7dYDJU) ## To Reproduce Steps to reproduce the behavior: 1. Just run each cell of the shared opacus bug report notebook 2. You should have access to edit/ view the file.

Expected behavior

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
[<ipython-input-3-e9e4db84336a>](https://localhost:8080/#) in <cell line: 4>()
     11                                                                                         target_epochs,
     12                                                                                         target_delta))
---> 13         noise_sigma = get_noise_multiplier(
     14                     target_epsilon = eps,
     15                     epochs = target_epochs,

4 frames
[/content/opacus/opacus/accountants/analysis/prv/prvs.py](https://localhost:8080/#) in discretize(prv, domain)
    173 
    174     if np.abs(mean_shift) >= domain.dt / 2:
--> 175         raise RuntimeError("Discrete mean differs significantly from continuous mean.")
    176 
    177     domain_shifted = domain.shift_right(mean_shift)

RuntimeError: Discrete mean differs significantly from continuous mean. 

I expected it to return the estimated sigma value of noise to be used for DP just like it did for other values of the arguments. However, for some configurations of the input to the noise_multiplier, the abovementioned error pops up. For example, for the setting epsilon = 5, batch size = 50, epochs = 10, delta = 1e-05 and epsilon = 4, batch size = 50, epochs = 5, delta = 1e-05. However, the error is NOT limited to just these 2 settings.

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

Additional context

xuefeng-xu commented 10 months ago

See microsoft/prv_accountant#36

Solosneros commented 9 months ago

See PR #606.