pytorch / opacus

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

refactor: delete unused code line #623

Closed helin0815 closed 8 months ago

helin0815 commented 8 months ago

Types of changes

bugfix: when use example of cifar10.py,will generate this error:

Traceback (most recent call last):
  File "cifar.py", line 36, in <module>
    from opacus.grad_sample.functorch import make_functional
ImportError: cannot import name 'make_functional' from 'opacus.grad_sample.functorch' (/root/miniconda3/lib/python3.8/site-packages/opacus/grad_sample/functorch.py)

Motivation and Context / Related issue

How Has This Been Tested (if it applies)

Checklist

facebook-github-bot commented 8 months ago

Hi @helin0815!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

HuanyuZhang commented 8 months ago

Thanks for the contribution! However, I could not replicate the error from my side. Could you make sure of the correctness of the Opacus's install?

Furthermore, I do not think this line is unused. See line 145 in the code (https://github.com/HuanyuZhang/opacus/blob/main/examples/cifar10.py#L145).

helin0815 commented 8 months ago

Thanks for the contribution! However, I could not replicate the error from my side. Could you make sure of the correctness of the Opacus's install?

Furthermore, I do not think this line is unused. See line 145 in the code (https://github.com/HuanyuZhang/opacus/blob/main/examples/cifar10.py#L145).

@HuanyuZhang Hello.What is the version of opacus on your end? My version here is 1.4

helin0815 commented 8 months ago

@HuanyuZhang hello,我最近在使用opacus的过程中遇到了一些问题,在这里请教您一下(看您的头像和id应该是中国人,因此在这里直接使用中文提问)。我现在北京交通大学计算机院读研,在做的实验是差分隐私相关,打算使用opacus来确认隐私预算的量,但是遇到了一些问题:我添加from opacus import PrivacyEngine privacy_engine = PrivacyEngine(accountant = "rdp") net, optimizer, trainloader = privacy_engine.make_private( module=net, optimizer=optimizer, data_loader=trainloader, noise_multiplier=1.1, max_grad_norm=1.0, )这样一段代码以后就出现了cuda out of memory的报错,未添加之前可以正常运行,而且我现在的GPU是一块24G显存的4090的卡,感觉已经挺大的了。而且我想请教一些关于opacus的问题,我在使用privacy_engine.make_private这个函数以后,是会对模型、优化器、参数都进行一些修改吗,还有在调用make_private这个函数以后是不是就会消耗大量的GPU来对模型参数进行一些处理,以及最后计算出来的隐私预算的值(epsilon)的值如果大于100的话合不合理。多谢