训练具有不同隐私的PyTorch模型
opacus的Python项目详细描述
Opacus是一个库,它允许使用不同的隐私来训练PyTorch模型。它支持对客户机进行最少代码更改的培训,对培训性能的影响很小,并且允许客户机在线跟踪在任何给定时刻花费的隐私预算。在
目标受众
此代码发布面向两个目标受众:
- ML从业者将发现这是一个温和的介绍,以培训一个具有差异隐私的模型,因为它需要最少的代码更改。在
- 差异隐私科学家会发现这很容易实验和修补,使他们能够专注于什么是重要的。在
安装
最新版本的Opacus可通过pip
安装:
pip install opacus
:warning: NOTE: This will bring in the latest version of our deps, which are on Cuda 10.2. This will not work if you environment is using an older Cuda version (for example, Google Colab is still on Cuda 10.1).
要在Colab上安装,请先运行此单元:
^{pr2}$然后你就可以像以前一样pip install opacus
。{更多内容请参阅a3}。在
您还可以直接从源代码处安装最新功能(以及它的怪癖和潜在的专业错误):
git clone https://github.com/pytorch/opacus.git
cd opacus
pip install -e .
入门
要使用差异隐私来训练模型,只需声明一个PrivacyEngine
,并在运行之前将其附加到优化器,例如:
model=Net()optimizer=SGD(model.parameters(),lr=0.05)privacy_engine=PrivacyEngine(model,batch_size,sample_size,alphas=[10,100],noise_multiplier=1.3,max_grad_norm=1.0,)privacy_engine.attach(optimizer)# Now it's business as usual
MNIST example显示使用opacus的端到端运行。examples文件夹包含更多这样的示例。在
常见问题解答
请访问FAQ页面,以获得有关差异隐私和Opacus的一些最常见问题的答案。在
贡献
请参阅CONTRIBUTING文件以获取帮助。在
参考文献
- Mironov, Ilya. "Rényi differential privacy." 2017 IEEE 30th Computer Security Foundations Symposium (CSF). IEEE, 2017.
- Abadi, Martin, et al. "Deep learning with differential privacy." Proceedings of the 2016 ACM SIGSAC Conference on Computer and Communications Security. ACM, 2016.
- Mironov, Ilya, Kunal Talwar, and Li Zhang. "R'enyi Differential Privacy of the Sampled Gaussian Mechanism." arXiv preprint arXiv:1908.10530 (2019).
- Goodfellow, Ian. "Efficient per-example gradient computations." arXiv preprint arXiv:1510.01799 (2015).
- McMahan, H. Brendan, and Galen Andrew. "A general approach to adding differential privacy to iterative training procedures." arXiv preprint arXiv:1812.06210 (2018).
许可证
这段代码是在Apache2.0下发布的,可以在LICENSE文件中找到。在
- 项目
标签: