TF-Shell: Privacy preserving machine learning with Tensorflow and the SHELL encryption library, built for python 3.10.
Project description
tf-shell
The tf-shell
library supports privacy preserving machine learning with
homomorphic encryption via the
SHELL library and tensorflow.
This is not an officially supported Google product.
Getting Started
pip install tf-shell
See ./examples/
for how to use the library.
Background
Homomorphic encryption allows computation on encrypted data. For example, given
two ciphertexts a
and b
representing the numbers 3
and 4
, respectively,
one can compute a ciphertext c
representing the number 7
without decrypting
a
or b
. This is useful for privacy preserving machine learning because it
allows training a model on encrypted data.
The SHELL encryption library supports homomorphic encryption with respect to addition and multiplication. This means that one can compute the sum of two ciphertexts or the product of two ciphertexts without decrypting them. SHELL does not support fully homomorphic encryption, meaning computing functions of ciphertexts with arbitrary depth. That said, because machine learning models are of bounded depth, the performance benefits of leveled schemes (without bootstrapping, e.g. SHELL) outweight limitations in circuit depth.
Design
This library has two modules, tf_shell
which supports Tensorflow Tensors
containing ciphertexts with homomorphic properties, and tf_shell_ml
some (very)
simple machine learning tools supporting privacy preserving training.
tf-shell
is designed for Label-DP SGD where training data is vertically
partitioned, e.g. one party holds features while another party holds labels. The
party who holds the features would like to train a model without learning the
labels. The resultant trained model is differentially private with respect to
the labels.
Building
Build From Source
-
Install bazel and python3 or use the devcontainer.
-
Run the tests.
bazel test ...
-
Build the code.
bazel build //:wheel bazel run //:wheel_rename
-
(Optional) Install the wheel, e.g. to try out the
./examples/
. You may first need to copy the wheel out of the devcontainer's filesystem.cp -f bazel-bin/*.whl ./ # Run in devcontainer if using.
Then install.
pip install --force-reinstall tf_shell-*.whl # Run in target environment.
Note the cpython api is not compatible across minor python versions (e.g. 3.10, 3.11) so the wheel must be rebuilt for each python version.
Code Formatters and Counters
bazel run //:bazel_formatter
bazel run //:python_formatter
bazel run //:clang_formatter
cloc ./ --fullpath --not-match-d='/(bazel-.*|.*\.venv)/'
Update Python Dependencies
Update requirements.in and run the following to update the requirements files for each python version.
for ver in 3_9 3_10 3_11 3_12; do
rm requirements_${ver}.txt
touch requirements_${ver}.txt
bazel run //:requirements_${ver}.update
done
bazel clean --expunge
If updating the tensorflow dependency, other dependencies may also need to
change, e.g. abseil (see MODULE.bazel
). This issue usually manifests as a
missing symbols error in the tests when trying to import the tensorflow DSO. In
this case, c++filt
will help to decode the mangled symbol name and nm --defined-only .../libtensorflow_framework.so | grep ...
may help find what the
symbol changed to, and which dependency is causing the error.
Contributing
See CONTRIBUTING.md
for details.
License
Apache 2.0; see LICENSE
for details.
Disclaimer
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file tf_shell-0.1.5-cp311-cp311-manylinux_2_35_x86_64.whl
.
File metadata
- Download URL: tf_shell-0.1.5-cp311-cp311-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 990.3 kB
- Tags: CPython 3.11, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 552482bfd76faaa4e4245303f477d14b5001a368a395fa929310b0f53b74eafd |
|
MD5 | ea61ff77c859ac40078eea42037720d3 |
|
BLAKE2b-256 | 00a4bc0d382a215181e751ce106fe5e6f404d6be5da0a6758fd8cc83c3ea7d5c |
Provenance
File details
Details for the file tf_shell-0.1.5-cp310-cp310-manylinux_2_35_x86_64.whl
.
File metadata
- Download URL: tf_shell-0.1.5-cp310-cp310-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 990.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71ffbe599e8466bc3c83ca5af1bb43808a2e4fd73d56d05bb4e0c45e8a378a70 |
|
MD5 | 4eb9ca12c4abe8270c6ba497b60fae6f |
|
BLAKE2b-256 | c93a5f5c7c13e625c286594fb03b369557713ddd8beddfc4117ac30741e00db7 |
Provenance
File details
Details for the file tf_shell-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl
.
File metadata
- Download URL: tf_shell-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl
- Upload date:
- Size: 990.3 kB
- Tags: CPython 3.9, manylinux: glibc 2.35+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf492e47ce96024ff454240278261346ad8c80c45ba6c023e95e28afb323de5e |
|
MD5 | 9c849b22b34280e96db5b6288874586e |
|
BLAKE2b-256 | 21baf9a968e4fe66a439e07ee85f1be1e0c6fd880758cbfd0e739f68af225b44 |