Skip to main content

Train PyTorch models with Differential Privacy

Project description

pytorch-dp: Train PyTorch models with Differential Privacy

CircleCI

pytorch-dp is a library that enables training PyTorch models with differential privacy. It supports training with minimal code changes required on the client, has little impact on training performance and allows the client to online track the privacy budget expended at any given moment.

PyTorch Privacy is currently a preview beta and under active development!

Target audience

This code release is aimed at two target audiences:

  1. ML practicioners will find this code a gentle introduction to training a model with differential privacy as it requires minimal code changes.
  2. Differential Privacy scientists will find this code easy to experiment and tinker with, allowing them to focus on what matters.

Installation

pip:

pip install pytorch-dp

From source:

git clone https://github.com/facebookresearch/pytorch-dp.git
cd pytorch-dp
pip install -e .

Getting started

To train your model with differential privacy, all you need to do is to declare a PrivacyEngine and attach it to your optimizer before running, eg:

model = Net()
optimizer = SGD(model.parameters(), lr=0.05)
privacy_engine = PrivacyEngine(
    model,
    batch_size,
    sample_size,
    alphas=[1, 10, 100],
    noise_multiplier=1.3,
    max_grad_norm=1.0,
)
privacy_engine.attach(optimizer)
# Now it's business as usual

The MNIST example contains an end to end run.

Contributing

See the CONTRIBUTING file for how to help out.

References

License

This code is released under Apache 2.0, as found in the LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytorch-dp-0.1b1.tar.gz (37.0 kB view hashes)

Uploaded Source

Built Distribution

pytorch_dp-0.1b1-py3-none-any.whl (50.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page