opacus


Nameopacus JSON
Version 1.4.1 PyPI version JSON
download
home_pagehttps://opacus.ai
SummaryTrain PyTorch models with Differential Privacy
upload_time2024-02-11 17:28:31
maintainer
docs_urlNone
authorThe Opacus Team
requires_python>=3.7.5
licenseApache-2.0
keywords pytorch differential privacy dp-sgd dp sgd privacy preserving machine learning ppml ppai
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center"><img src="https://github.com/pytorch/opacus/blob/main/website/static/img/opacus_logo.svg" alt="Opacus" width="500"/></p>

<hr/>

[![CircleCI](https://dl.circleci.com/status-badge/img/gh/pytorch/opacus/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/pytorch/opacus/tree/main)
[![Coverage Status](https://coveralls.io/repos/github/pytorch/opacus/badge.svg?branch=main)](https://coveralls.io/github/pytorch/opacus?branch=main)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
[![License](https://img.shields.io/badge/license-apache2-green.svg)](LICENSE)

[Opacus](https://opacus.ai) 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.

## Target audience
This code release is aimed at two target audiences:
1. ML practitioners will find this to be a gentle introduction to training a model with differential privacy as it requires minimal code changes.
2. Differential Privacy researchers will find this easy to experiment and tinker with, allowing them to focus on what matters.


## Installation
The latest release of Opacus can be installed via `pip`:
```bash
pip install opacus
```
OR, alternatively, via `conda`:
```bash
conda install -c conda-forge opacus
```

You can also install directly from the source for the latest features (along with its quirks and potentially occasional bugs):
```bash
git clone https://github.com/pytorch/opacus.git
cd opacus
pip install -e .
```

## Getting started
To train your model with differential privacy, all you need to do is to instantiate a `PrivacyEngine` and pass your model, data_loader, and optimizer to the engine's `make_private()` method to obtain their private counterparts.

```python
# define your components as usual
model = Net()
optimizer = SGD(model.parameters(), lr=0.05)
data_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)

# enter PrivacyEngine
privacy_engine = PrivacyEngine()
model, optimizer, data_loader = privacy_engine.make_private(
    module=model,
    optimizer=optimizer,
    data_loader=data_loader,
    noise_multiplier=1.1,
    max_grad_norm=1.0,
)
# Now it's business as usual
```

The [MNIST example](https://github.com/pytorch/opacus/tree/main/examples/mnist.py) shows an end-to-end run using Opacus. The [examples](https://github.com/pytorch/opacus/tree/main/examples/) folder contains more such examples.

### Migrating to 1.0

Opacus 1.0 introduced many improvements to the library, but also some breaking changes.
If you've been using Opacus 0.x and want to update to the latest release,
please use this [Migration Guide](https://github.com/pytorch/opacus/blob/main/Migration_Guide.md)


## Learn more

### Interactive tutorials

We've built a series of IPython-based tutorials as a gentle introduction to training models
with privacy and using various Opacus features.

- [Building an Image Classifier with Differential Privacy](https://github.com/pytorch/opacus/blob/main/tutorials/building_image_classifier.ipynb)
- [Training a differentially private LSTM model for name classification](https://github.com/pytorch/opacus/blob/main/tutorials/building_lstm_name_classifier.ipynb)
- [Building text classifier with Differential Privacy on BERT](https://github.com/pytorch/opacus/blob/main/tutorials/building_text_classifier.ipynb)
- [Opacus Guide: Introduction to advanced features](https://github.com/pytorch/opacus/blob/main/tutorials/intro_to_advanced_features.ipynb)
- [Opacus Guide: Grad samplers](https://github.com/pytorch/opacus/blob/main/tutorials/guide_to_grad_sampler.ipynb)
- [Opacus Guide: Module Validator and Fixer](https://github.com/pytorch/opacus/blob/main/tutorials/guide_to_module_validator.ipynb)

## Technical report and citation
The technical report introducing Opacus, presenting its design principles, mathematical foundations, and benchmarks can be found [here](https://arxiv.org/abs/2109.12298).

Consider citing the report if you use Opacus in your papers, as follows:
```
@article{opacus,
  title={Opacus: {U}ser-Friendly Differential Privacy Library in {PyTorch}},
  author={Ashkan Yousefpour and Igor Shilov and Alexandre Sablayrolles and Davide Testuggine and Karthik Prasad and Mani Malek and John Nguyen and Sayan Ghosh and Akash Bharadwaj and Jessica Zhao and Graham Cormode and Ilya Mironov},
  journal={arXiv preprint arXiv:2109.12298},
  year={2021}
}
```

### Blogposts and talks

If you want to learn more about DP-SGD and related topics, check out our series of blogposts and talks:

- [Differential Privacy Series Part 1 | DP-SGD Algorithm Explained](https://medium.com/pytorch/differential-privacy-series-part-1-dp-sgd-algorithm-explained-12512c3959a3)
- [Differential Privacy Series Part 2 | Efficient Per-Sample Gradient Computation in Opacus](https://medium.com/pytorch/differential-privacy-series-part-2-efficient-per-sample-gradient-computation-in-opacus-5bf4031d9e22)
- [PriCon 2020 Tutorial: Differentially Private Model Training with Opacus](https://www.youtube.com/watch?v=MWPwofiQMdE&list=PLUNOsx6Az_ZGKQd_p4StdZRFQkCBwnaY6&index=52)
- [Differential Privacy on PyTorch | PyTorch Developer Day 2020](https://www.youtube.com/watch?v=l6fbl2CBnq0)
- [Opacus v1.0 Highlights | PyTorch Developer Day 2021](https://www.youtube.com/watch?v=U1mszp8lzUI)


## FAQ
Check out the [FAQ](https://opacus.ai/docs/faq) page for answers to some of the most frequently asked questions about differential privacy and Opacus.

## Contributing
See the [CONTRIBUTING](https://github.com/pytorch/opacus/tree/main/CONTRIBUTING.md) file for how to help out.
Do also check out the README files inside the repo to learn how the code is organized.

## License
This code is released under Apache 2.0, as found in the [LICENSE](https://github.com/pytorch/opacus/tree/main/LICENSE) file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://opacus.ai",
    "name": "opacus",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.5",
    "maintainer_email": "",
    "keywords": "PyTorch,Differential Privacy,DP-SGD,DP SGD,Privacy Preserving Machine Learning,PPML,PPAI",
    "author": "The Opacus Team",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/52/f6/79f7bc192b1129495bf25b9c19a1487e51d96e13e22249e37bedd7bd0e11/opacus-1.4.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\"><img src=\"https://github.com/pytorch/opacus/blob/main/website/static/img/opacus_logo.svg\" alt=\"Opacus\" width=\"500\"/></p>\n\n<hr/>\n\n[![CircleCI](https://dl.circleci.com/status-badge/img/gh/pytorch/opacus/tree/main.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/pytorch/opacus/tree/main)\n[![Coverage Status](https://coveralls.io/repos/github/pytorch/opacus/badge.svg?branch=main)](https://coveralls.io/github/pytorch/opacus?branch=main)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)\n[![License](https://img.shields.io/badge/license-apache2-green.svg)](LICENSE)\n\n[Opacus](https://opacus.ai) is a library that enables training PyTorch models with differential privacy.\nIt 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.\n\n## Target audience\nThis code release is aimed at two target audiences:\n1. ML practitioners will find this to be a gentle introduction to training a model with differential privacy as it requires minimal code changes.\n2. Differential Privacy researchers will find this easy to experiment and tinker with, allowing them to focus on what matters.\n\n\n## Installation\nThe latest release of Opacus can be installed via `pip`:\n```bash\npip install opacus\n```\nOR, alternatively, via `conda`:\n```bash\nconda install -c conda-forge opacus\n```\n\nYou can also install directly from the source for the latest features (along with its quirks and potentially occasional bugs):\n```bash\ngit clone https://github.com/pytorch/opacus.git\ncd opacus\npip install -e .\n```\n\n## Getting started\nTo train your model with differential privacy, all you need to do is to instantiate a `PrivacyEngine` and pass your model, data_loader, and optimizer to the engine's `make_private()` method to obtain their private counterparts.\n\n```python\n# define your components as usual\nmodel = Net()\noptimizer = SGD(model.parameters(), lr=0.05)\ndata_loader = torch.utils.data.DataLoader(dataset, batch_size=1024)\n\n# enter PrivacyEngine\nprivacy_engine = PrivacyEngine()\nmodel, optimizer, data_loader = privacy_engine.make_private(\n    module=model,\n    optimizer=optimizer,\n    data_loader=data_loader,\n    noise_multiplier=1.1,\n    max_grad_norm=1.0,\n)\n# Now it's business as usual\n```\n\nThe [MNIST example](https://github.com/pytorch/opacus/tree/main/examples/mnist.py) shows an end-to-end run using Opacus. The [examples](https://github.com/pytorch/opacus/tree/main/examples/) folder contains more such examples.\n\n### Migrating to 1.0\n\nOpacus 1.0 introduced many improvements to the library, but also some breaking changes.\nIf you've been using Opacus 0.x and want to update to the latest release,\nplease use this [Migration Guide](https://github.com/pytorch/opacus/blob/main/Migration_Guide.md)\n\n\n## Learn more\n\n### Interactive tutorials\n\nWe've built a series of IPython-based tutorials as a gentle introduction to training models\nwith privacy and using various Opacus features.\n\n- [Building an Image Classifier with Differential Privacy](https://github.com/pytorch/opacus/blob/main/tutorials/building_image_classifier.ipynb)\n- [Training a differentially private LSTM model for name classification](https://github.com/pytorch/opacus/blob/main/tutorials/building_lstm_name_classifier.ipynb)\n- [Building text classifier with Differential Privacy on BERT](https://github.com/pytorch/opacus/blob/main/tutorials/building_text_classifier.ipynb)\n- [Opacus Guide: Introduction to advanced features](https://github.com/pytorch/opacus/blob/main/tutorials/intro_to_advanced_features.ipynb)\n- [Opacus Guide: Grad samplers](https://github.com/pytorch/opacus/blob/main/tutorials/guide_to_grad_sampler.ipynb)\n- [Opacus Guide: Module Validator and Fixer](https://github.com/pytorch/opacus/blob/main/tutorials/guide_to_module_validator.ipynb)\n\n## Technical report and citation\nThe technical report introducing Opacus, presenting its design principles, mathematical foundations, and benchmarks can be found [here](https://arxiv.org/abs/2109.12298).\n\nConsider citing the report if you use Opacus in your papers, as follows:\n```\n@article{opacus,\n  title={Opacus: {U}ser-Friendly Differential Privacy Library in {PyTorch}},\n  author={Ashkan Yousefpour and Igor Shilov and Alexandre Sablayrolles and Davide Testuggine and Karthik Prasad and Mani Malek and John Nguyen and Sayan Ghosh and Akash Bharadwaj and Jessica Zhao and Graham Cormode and Ilya Mironov},\n  journal={arXiv preprint arXiv:2109.12298},\n  year={2021}\n}\n```\n\n### Blogposts and talks\n\nIf you want to learn more about DP-SGD and related topics, check out our series of blogposts and talks:\n\n- [Differential Privacy Series Part 1 | DP-SGD Algorithm Explained](https://medium.com/pytorch/differential-privacy-series-part-1-dp-sgd-algorithm-explained-12512c3959a3)\n- [Differential Privacy Series Part 2 | Efficient Per-Sample Gradient Computation in Opacus](https://medium.com/pytorch/differential-privacy-series-part-2-efficient-per-sample-gradient-computation-in-opacus-5bf4031d9e22)\n- [PriCon 2020 Tutorial: Differentially Private Model Training with Opacus](https://www.youtube.com/watch?v=MWPwofiQMdE&list=PLUNOsx6Az_ZGKQd_p4StdZRFQkCBwnaY6&index=52)\n- [Differential Privacy on PyTorch | PyTorch Developer Day 2020](https://www.youtube.com/watch?v=l6fbl2CBnq0)\n- [Opacus v1.0 Highlights | PyTorch Developer Day 2021](https://www.youtube.com/watch?v=U1mszp8lzUI)\n\n\n## FAQ\nCheck out the [FAQ](https://opacus.ai/docs/faq) page for answers to some of the most frequently asked questions about differential privacy and Opacus.\n\n## Contributing\nSee the [CONTRIBUTING](https://github.com/pytorch/opacus/tree/main/CONTRIBUTING.md) file for how to help out.\nDo also check out the README files inside the repo to learn how the code is organized.\n\n## License\nThis code is released under Apache 2.0, as found in the [LICENSE](https://github.com/pytorch/opacus/tree/main/LICENSE) file.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Train PyTorch models with Differential Privacy",
    "version": "1.4.1",
    "project_urls": {
        "Documentation": "https://opacus.ai/api",
        "Homepage": "https://opacus.ai",
        "Source": "https://github.com/pytorch/opacus"
    },
    "split_keywords": [
        "pytorch",
        "differential privacy",
        "dp-sgd",
        "dp sgd",
        "privacy preserving machine learning",
        "ppml",
        "ppai"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6612b16095aaaed4a50773383c221a2bdc67b4eb575a28d101f3ae090947fa64",
                "md5": "8af109c0ba1716856db3d1ccb6dce2bb",
                "sha256": "8c46aff596bbbc6025ce9d169b49d5b3112cb958e3d74f8b77274134e7590890"
            },
            "downloads": -1,
            "filename": "opacus-1.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8af109c0ba1716856db3d1ccb6dce2bb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.5",
            "size": 226652,
            "upload_time": "2024-02-11T17:28:30",
            "upload_time_iso_8601": "2024-02-11T17:28:30.018320Z",
            "url": "https://files.pythonhosted.org/packages/66/12/b16095aaaed4a50773383c221a2bdc67b4eb575a28d101f3ae090947fa64/opacus-1.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52f679f7bc192b1129495bf25b9c19a1487e51d96e13e22249e37bedd7bd0e11",
                "md5": "98aed749ef647b1ad57c8becc92c0632",
                "sha256": "e1d453c29bc8457ad7c530f5c56074c913dfebb0fb14d7524677cf03a217cff4"
            },
            "downloads": -1,
            "filename": "opacus-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "98aed749ef647b1ad57c8becc92c0632",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.5",
            "size": 139127,
            "upload_time": "2024-02-11T17:28:31",
            "upload_time_iso_8601": "2024-02-11T17:28:31.621572Z",
            "url": "https://files.pythonhosted.org/packages/52/f6/79f7bc192b1129495bf25b9c19a1487e51d96e13e22249e37bedd7bd0e11/opacus-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 17:28:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytorch",
    "github_project": "opacus",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "circle": true,
    "requirements": [],
    "lcname": "opacus"
}
        
Elapsed time: 0.19789s