crypten


Namecrypten JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://github.com/facebookresearch/CrypTen
SummaryCrypTen: secure machine learning in PyTorch.
upload_time2022-12-08 22:10:18
maintainer
docs_urlNone
authorFacebook AI Research
requires_python
licenseMIT licensed, as found in the LICENSE file
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center"><img width="70%" src="https://raw.githubusercontent.com/facebookresearch/CrypTen/master/docs/_static/img/CrypTen_Identity_Horizontal_Lockup_01_FullColor.png" alt="CrypTen logo" /></p>

[![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebookresearch/CrypTen/blob/master/LICENSE) [![CircleCI](https://circleci.com/gh/facebookresearch/CrypTen.svg?style=shield)](https://circleci.com/gh/facebookresearch/CrypTen/tree/master) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/facebookresearch/CrypTen/blob/master/CONTRIBUTING.md)

--------------------------------------------------------------------------------

CrypTen is a framework for Privacy Preserving Machine Learning built on PyTorch.
Its goal is to make secure computing techniques accessible to Machine Learning practitioners.
It currently implements [Secure Multiparty Computation](https://en.wikipedia.org/wiki/Secure_multi-party_computation)
as its secure computing backend and offers three main benefits to ML researchers:

1. It is machine learning first. The framework presents the protocols via a `CrypTensor`
   object that looks and feels exactly like a PyTorch `Tensor`. This allows the user to use
   automatic differentiation and neural network modules akin to those in PyTorch.

2. CrypTen is library-based. It implements a tensor library just as PyTorch does.
   This makes it easier for practitioners to debug, experiment on, and explore ML models.

3. The framework is built with real-world challenges in mind. CrypTen does not scale back or
   oversimplify the implementation of the secure protocols.

Here is a bit of CrypTen code that encrypts and decrypts tensors and adds them

```python
import torch
import crypten

crypten.init()

x = torch.tensor([1.0, 2.0, 3.0])
x_enc = crypten.cryptensor(x) # encrypt

x_dec = x_enc.get_plain_text() # decrypt

y_enc = crypten.cryptensor([2.0, 3.0, 4.0])
sum_xy = x_enc + y_enc # add encrypted tensors
sum_xy_dec = sum_xy.get_plain_text() # decrypt sum
```

It is currently not production ready and its main use is as a research framework.

## Installing CrypTen

CrypTen currently runs on Linux and Mac with Python 3.7.
We also support computation on GPUs.
Windows **is not** supported.

_For Linux or Mac_
```bash
pip install crypten
```

If you want to run the examples in the `examples` directory, you should also do the following
```bash
pip install -r requirements.examples.txt
```

## Examples
To run the examples in the `examples` directory, you additionally need to clone the repo and

```bash
pip install -r requirements.examples.txt
```

We provide examples covering a range of models in the `examples` directory

1. The linear SVM example, `mpc_linear_svm`, generates random data and trains a
  SVM classifier on encrypted data.
2. The LeNet example, `mpc_cifar`, trains an adaptation of LeNet on CIFAR in
  cleartext and encrypts the model and data for inference.
3. The TFE benchmark example, `tfe_benchmarks`, trains three different network
  architectures on MNIST in cleartext, and encrypts the trained model and data
  for inference.
4. The bandits example, `bandits`, trains a contextual bandits model on
  encrypted data (MNIST).
5. The imagenet example, `mpc_imagenet`, performs inference on pretrained
  models from `torchvision`.

For examples that train in cleartext, we also provide pre-trained models in
cleartext in the `model` subdirectory of each example subdirectory.

You can check all example specific command line options by doing the following;
shown here for `tfe_benchmarks`:

```bash
python examples/tfe_benchmarks/launcher.py --help
```

## How CrypTen works

We have a set of tutorials in the `tutorials` directory to show how
CrypTen works. These are presented as Jupyter notebooks so please install
the following in your conda environment

```bash
conda install ipython jupyter
pip install -r requirements.examples.txt
```

1. `Introduction.ipynb` - an introduction to Secure Multiparty Compute; CrypTen's
   underlying secure computing protocol; use cases we are trying to solve and the
   threat model we assume.
2. `Tutorial_1_Basics_of_CrypTen_Tensors.ipynb` - introduces `CrypTensor`, CrypTen's
   encrypted tensor object, and shows how to use it to do various operations on
   this object.
3. `Tutorial_2_Inside_CrypTensors.ipynb` – delves deeper into `CrypTensor` to show
   the inner workings; specifically how `CrypTensor` uses `MPCTensor` for its
   backend and the two different kind of _sharings_, arithmetic and binary, are
   used for two different kind of functions. It also shows CrypTen's
   [MPI](https://en.wikipedia.org/wiki/Message_Passing_Interface)-inspired
   programming model.
4. `Tutorial_3_Introduction_to_Access_Control.ipynb` - shows how to train a linear
   model using CrypTen and shows various scenarios of data labeling, feature
   aggregation, dataset augmentation and model hiding where this is applicable.
5. `Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb` – shows how
   CrypTen can load a pre-trained PyTorch model, encrypt it and then do inference
   on encrypted data.
6. `Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb` - examines how CrypTen
   loads PyTorch models, how they are encrypted and how data moves through a multilayer
   network.
7. `Tutorial_6_CrypTen_on_AWS_instances.ipynb` - shows how to use `scrips/aws_launcher.py`
   to launch our examples on AWS. It can also work with your code written in CrypTen.
8. `Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb` - introduces the
   automatic differentiation functionality of `CrypTensor`. This functionality
   makes it easy to train neural networks in CrypTen.


## Documentation and citing
CrypTen is documented [here](https://crypten.readthedocs.io/en/latest/).

The protocols and design protocols implemented in CrypTen are described in [this paper](https://arxiv.org/pdf/2109.00984.pdf). If you want to cite CrypTen in your papers (much appreciated!), you can cite it as follows:
```
@inproceedings{crypten2020,
  author={B. Knott and S. Venkataraman and A.Y. Hannun and S. Sengupta and M. Ibrahim and L.J.P. van der Maaten},
  title={CrypTen: Secure Multi-Party Computation Meets Machine Learning},
  booktitle={arXiv 2109.00984},
  year={2021},
}
```

## Join the CrypTen community
Please contact [us](mailto:ssengupta@fb.com) to join the CrypTen community on [Slack](https://cryptensor.slack.com)

See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.

## License
CrypTen is MIT licensed, as found in the LICENSE file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/facebookresearch/CrypTen",
    "name": "crypten",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Facebook AI Research",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/59/e3/38d581fc9f73d583b1578d4db810091659d64ed3904035940d7bf54a6275/crypten-0.4.1.tar.gz",
    "platform": null,
    "description": "<p align=\"center\"><img width=\"70%\" src=\"https://raw.githubusercontent.com/facebookresearch/CrypTen/master/docs/_static/img/CrypTen_Identity_Horizontal_Lockup_01_FullColor.png\" alt=\"CrypTen logo\" /></p>\n\n[![Support Ukraine](https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB)](https://opensource.fb.com/support-ukraine) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/facebookresearch/CrypTen/blob/master/LICENSE) [![CircleCI](https://circleci.com/gh/facebookresearch/CrypTen.svg?style=shield)](https://circleci.com/gh/facebookresearch/CrypTen/tree/master) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/facebookresearch/CrypTen/blob/master/CONTRIBUTING.md)\n\n--------------------------------------------------------------------------------\n\nCrypTen is a framework for Privacy Preserving Machine Learning built on PyTorch.\nIts goal is to make secure computing techniques accessible to Machine Learning practitioners.\nIt currently implements [Secure Multiparty Computation](https://en.wikipedia.org/wiki/Secure_multi-party_computation)\nas its secure computing backend and offers three main benefits to ML researchers:\n\n1. It is machine learning first. The framework presents the protocols via a `CrypTensor`\n   object that looks and feels exactly like a PyTorch `Tensor`. This allows the user to use\n   automatic differentiation and neural network modules akin to those in PyTorch.\n\n2. CrypTen is library-based. It implements a tensor library just as PyTorch does.\n   This makes it easier for practitioners to debug, experiment on, and explore ML models.\n\n3. The framework is built with real-world challenges in mind. CrypTen does not scale back or\n   oversimplify the implementation of the secure protocols.\n\nHere is a bit of CrypTen code that encrypts and decrypts tensors and adds them\n\n```python\nimport torch\nimport crypten\n\ncrypten.init()\n\nx = torch.tensor([1.0, 2.0, 3.0])\nx_enc = crypten.cryptensor(x) # encrypt\n\nx_dec = x_enc.get_plain_text() # decrypt\n\ny_enc = crypten.cryptensor([2.0, 3.0, 4.0])\nsum_xy = x_enc + y_enc # add encrypted tensors\nsum_xy_dec = sum_xy.get_plain_text() # decrypt sum\n```\n\nIt is currently not production ready and its main use is as a research framework.\n\n## Installing CrypTen\n\nCrypTen currently runs on Linux and Mac with Python 3.7.\nWe also support computation on GPUs.\nWindows **is not** supported.\n\n_For Linux or Mac_\n```bash\npip install crypten\n```\n\nIf you want to run the examples in the `examples` directory, you should also do the following\n```bash\npip install -r requirements.examples.txt\n```\n\n## Examples\nTo run the examples in the `examples` directory, you additionally need to clone the repo and\n\n```bash\npip install -r requirements.examples.txt\n```\n\nWe provide examples covering a range of models in the `examples` directory\n\n1. The linear SVM example, `mpc_linear_svm`, generates random data and trains a\n  SVM classifier on encrypted data.\n2. The LeNet example, `mpc_cifar`, trains an adaptation of LeNet on CIFAR in\n  cleartext and encrypts the model and data for inference.\n3. The TFE benchmark example, `tfe_benchmarks`, trains three different network\n  architectures on MNIST in cleartext, and encrypts the trained model and data\n  for inference.\n4. The bandits example, `bandits`, trains a contextual bandits model on\n  encrypted data (MNIST).\n5. The imagenet example, `mpc_imagenet`, performs inference on pretrained\n  models from `torchvision`.\n\nFor examples that train in cleartext, we also provide pre-trained models in\ncleartext in the `model` subdirectory of each example subdirectory.\n\nYou can check all example specific command line options by doing the following;\nshown here for `tfe_benchmarks`:\n\n```bash\npython examples/tfe_benchmarks/launcher.py --help\n```\n\n## How CrypTen works\n\nWe have a set of tutorials in the `tutorials` directory to show how\nCrypTen works. These are presented as Jupyter notebooks so please install\nthe following in your conda environment\n\n```bash\nconda install ipython jupyter\npip install -r requirements.examples.txt\n```\n\n1. `Introduction.ipynb` - an introduction to Secure Multiparty Compute; CrypTen's\n   underlying secure computing protocol; use cases we are trying to solve and the\n   threat model we assume.\n2. `Tutorial_1_Basics_of_CrypTen_Tensors.ipynb` - introduces `CrypTensor`, CrypTen's\n   encrypted tensor object, and shows how to use it to do various operations on\n   this object.\n3. `Tutorial_2_Inside_CrypTensors.ipynb` \u2013 delves deeper into `CrypTensor` to show\n   the inner workings; specifically how `CrypTensor` uses `MPCTensor` for its\n   backend and the two different kind of _sharings_, arithmetic and binary, are\n   used for two different kind of functions. It also shows CrypTen's\n   [MPI](https://en.wikipedia.org/wiki/Message_Passing_Interface)-inspired\n   programming model.\n4. `Tutorial_3_Introduction_to_Access_Control.ipynb` - shows how to train a linear\n   model using CrypTen and shows various scenarios of data labeling, feature\n   aggregation, dataset augmentation and model hiding where this is applicable.\n5. `Tutorial_4_Classification_with_Encrypted_Neural_Networks.ipynb` \u2013 shows how\n   CrypTen can load a pre-trained PyTorch model, encrypt it and then do inference\n   on encrypted data.\n6. `Tutorial_5_Under_the_hood_of_Encrypted_Networks.ipynb` - examines how CrypTen\n   loads PyTorch models, how they are encrypted and how data moves through a multilayer\n   network.\n7. `Tutorial_6_CrypTen_on_AWS_instances.ipynb` - shows how to use `scrips/aws_launcher.py`\n   to launch our examples on AWS. It can also work with your code written in CrypTen.\n8. `Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb` - introduces the\n   automatic differentiation functionality of `CrypTensor`. This functionality\n   makes it easy to train neural networks in CrypTen.\n\n\n## Documentation and citing\nCrypTen is documented [here](https://crypten.readthedocs.io/en/latest/).\n\nThe protocols and design protocols implemented in CrypTen are described in [this paper](https://arxiv.org/pdf/2109.00984.pdf). If you want to cite CrypTen in your papers (much appreciated!), you can cite it as follows:\n```\n@inproceedings{crypten2020,\n  author={B. Knott and S. Venkataraman and A.Y. Hannun and S. Sengupta and M. Ibrahim and L.J.P. van der Maaten},\n  title={CrypTen: Secure Multi-Party Computation Meets Machine Learning},\n  booktitle={arXiv 2109.00984},\n  year={2021},\n}\n```\n\n## Join the CrypTen community\nPlease contact [us](mailto:ssengupta@fb.com) to join the CrypTen community on [Slack](https://cryptensor.slack.com)\n\nSee the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out.\n\n## License\nCrypTen is MIT licensed, as found in the LICENSE file.\n",
    "bugtrack_url": null,
    "license": "MIT licensed, as found in the LICENSE file",
    "summary": "CrypTen: secure machine learning in PyTorch.",
    "version": "0.4.1",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "eb8001a43abb5452691a2502639973a7",
                "sha256": "26e7f4b54997b3a78d10c8c0bcb604215eef6ad7830ddbfe93a14d80c9c1dd84"
            },
            "downloads": -1,
            "filename": "crypten-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb8001a43abb5452691a2502639973a7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 259912,
            "upload_time": "2022-12-08T22:10:16",
            "upload_time_iso_8601": "2022-12-08T22:10:16.937983Z",
            "url": "https://files.pythonhosted.org/packages/34/18/5d8c375d558d8aa72bb147d9cc833abde8c316920c1c9c5e083a0f1c28b3/crypten-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "638e1d7081a0ea5ee29a8f294df5a669",
                "sha256": "8c106ecc1547f892b488c560a27acd6787e216cb77bf7659a3d4e8271a1d4fb7"
            },
            "downloads": -1,
            "filename": "crypten-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "638e1d7081a0ea5ee29a8f294df5a669",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 215163,
            "upload_time": "2022-12-08T22:10:18",
            "upload_time_iso_8601": "2022-12-08T22:10:18.849633Z",
            "url": "https://files.pythonhosted.org/packages/59/e3/38d581fc9f73d583b1578d4db810091659d64ed3904035940d7bf54a6275/crypten-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-08 22:10:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "facebookresearch",
    "github_project": "CrypTen",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [],
    "lcname": "crypten"
}
        
Elapsed time: 0.05919s