Skip to main content

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

  1. Install bazel and python3 or use the devcontainer.

  2. Run the tests.

    bazel test //tf_shell/...
    bazel test //tf_shell_ml/...  # Large tests, requires 128GB of memory.
    
  3. Build the code.

    bazel build //:wheel
    bazel run //:wheel_rename
    
  4. (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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tf_shell-0.3.2-cp312-cp312-manylinux_2_35_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

tf_shell-0.3.2-cp311-cp311-manylinux_2_35_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

tf_shell-0.3.2-cp310-cp310-manylinux_2_35_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

tf_shell-0.3.2-cp39-cp39-manylinux_2_35_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.35+ x86-64

File details

Details for the file tf_shell-0.3.2-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for tf_shell-0.3.2-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 5bfb881e073fa563848518c4776c55fb2e1b1e55fafcd4ee818e3a3c8f7baab3
MD5 1d9f158926a01a67ce8727ee67d05ab8
BLAKE2b-256 0e19cf19904ede6f076f0ca721fcf6b09197c40bc536f801f98be463e12c6885

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_shell-0.3.2-cp312-cp312-manylinux_2_35_x86_64.whl:

Publisher: wheel.yaml on google/tf-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tf_shell-0.3.2-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for tf_shell-0.3.2-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 49ef1a1cd91ac743712180ce63efa7ffed2709cc10e00c57a5b71076ff17c546
MD5 d451752002aa028ae9481ab2a61c4501
BLAKE2b-256 f6f5350706819dc38a8e27135753f3a49a59e591f8dea15f389bb60dae1e05e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_shell-0.3.2-cp311-cp311-manylinux_2_35_x86_64.whl:

Publisher: wheel.yaml on google/tf-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tf_shell-0.3.2-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for tf_shell-0.3.2-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 a07e8ad1c643e5462d987fad9de2839c4120bbb3e0fa083416306efa7a507931
MD5 4b34db4105adb92bcc6ed32fa5a2559c
BLAKE2b-256 4517221b5d7aab36de4129b962442ff532b0e091ce486750904caa938db06294

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_shell-0.3.2-cp310-cp310-manylinux_2_35_x86_64.whl:

Publisher: wheel.yaml on google/tf-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tf_shell-0.3.2-cp39-cp39-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for tf_shell-0.3.2-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1c848c0f1f73fa10a973474e0b5614f38bbe96ee6571709d7529d0f040d230f5
MD5 43f9e536447dd05b4fcdc9bb13b40693
BLAKE2b-256 bec7bfdd65becd3da3c89aa85c7f538c1b2df721ebccec472a36af183c7c6836

See more details on using hashes here.

Provenance

The following attestation bundles were made for tf_shell-0.3.2-cp39-cp39-manylinux_2_35_x86_64.whl:

Publisher: wheel.yaml on google/tf-shell

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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