Package: crypten
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 implementsSecure Multiparty Computationas its secure computing backend and offers three main benefits to ML researchers:It is machine learning first. The framework presents the protocols via aCrypTensorobject that looks and feels exactly like a PyTorchTensor. This allows the user to use
automatic differentiation and neural network modules akin to those in PyTorch.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.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 themimporttorchimportcryptencrypten.init()x=torch.tensor([1.0,2.0,3.0])x_enc=crypten.cryptensor(x)# encryptx_dec=x_enc.get_plain_text()# decrypty_enc=crypten.cryptensor([2.0,3.0,4.0])sum_xy=x_enc+y_enc# add encrypted tensorssum_xy_dec=sum_xy.get_plain_text()# decrypt sumIt is currently not production ready and its main use is as a research framework.Installing CrypTenCrypTen currently runs on Linux and Mac with Python 3.7.
We also support computation on GPUs.
Windowsis notsupported.For Linux or MacpipinstallcryptenIf you want to run the examples in theexamplesdirectory, you should also do the followingpipinstall-rrequirements.examples.txtExamplesTo run the examples in theexamplesdirectory, you additionally need to clone the repo andpipinstall-rrequirements.examples.txtWe provide examples covering a range of models in theexamplesdirectoryThe linear SVM example,mpc_linear_svm, generates random data and trains a
SVM classifier on encrypted data.The LeNet example,mpc_cifar, trains an adaptation of LeNet on CIFAR in
cleartext and encrypts the model and data for inference.The TFE benchmark example,tfe_benchmarks, trains three different network
architectures on MNIST in cleartext, and encrypts the trained model and data
for inference.The bandits example,bandits, trains a contextual bandits model on
encrypted data (MNIST).The imagenet example,mpc_imagenet, performs inference on pretrained
models fromtorchvision.For examples that train in cleartext, we also provide pre-trained models in
cleartext in themodelsubdirectory of each example subdirectory.You can check all example specific command line options by doing the following;
shown here fortfe_benchmarks:pythonexamples/tfe_benchmarks/launcher.py--helpHow CrypTen worksWe have a set of tutorials in thetutorialsdirectory to show how
CrypTen works. These are presented as Jupyter notebooks so please install
the following in your conda environmentcondainstallipythonjupyter
pipinstall-rrequirements.examples.txtIntroduction.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.Tutorial_1_Basics_of_CrypTen_Tensors.ipynb- introducesCrypTensor, CrypTen's
encrypted tensor object, and shows how to use it to do various operations on
this object.Tutorial_2_Inside_CrypTensors.ipynb– delves deeper intoCrypTensorto show
the inner workings; specifically howCrypTensorusesMPCTensorfor its
backend and the two different kind ofsharings, arithmetic and binary, are
used for two different kind of functions. It also shows CrypTen'sMPI-inspired
programming model.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.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.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.Tutorial_6_CrypTen_on_AWS_instances.ipynb- shows how to usescrips/aws_launcher.pyto launch our examples on AWS. It can also work with your code written in CrypTen.Tutorial_7_Training_an_Encrypted_Neural_Network.ipynb- introduces the
automatic differentiation functionality ofCrypTensor. This functionality
makes it easy to train neural networks in CrypTen.Documentation and citingCrypTen is documentedhere.The protocols and design protocols implemented in CrypTen are described inthis paper. 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 communityPlease contactusto join the CrypTen community onSlackSee theCONTRIBUTINGfile for how to help out.LicenseCrypTen is MIT licensed, as found in the LICENSE file.