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 Bazelisk and python3 or use the devcontainer.

  2. Run the tests.

    bazelisk test ...
    
  3. Build the code.

    bazelisk build //:wheel
    bazelisk 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 tf_shell-...-manylinux.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

bazelisk run //:bazel_formatter
bazelisk run //:python_formatter
bazelisk 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
  touch requirements_${ver}.txt
  bazelisk run //:requirements_${ver}.update
done

bazelisk 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

tf_shell-0.1.3-cp312-cp312-manylinux_2_35_x86_64.whl (858.2 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.35+ x86-64

tf_shell-0.1.3-cp311-cp311-manylinux_2_35_x86_64.whl (858.2 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.35+ x86-64

tf_shell-0.1.3-cp310-cp310-manylinux_2_35_x86_64.whl (858.2 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.35+ x86-64

tf_shell-0.1.3-cp39-cp39-manylinux_2_35_x86_64.whl (858.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.35+ x86-64

File details

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

File metadata

File hashes

Hashes for tf_shell-0.1.3-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4df3697d61003fa95fadac9a1a0344c7336b98d5ef98360a0ef203558b4671a9
MD5 f85d84a26668e304e8ab12d9077d337a
BLAKE2b-256 0b24383fdc4df9ef522f20a831b642154b71e332e5e47544f509ce872d45814f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for tf_shell-0.1.3-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6eef175833a5b75ef9c473c50d64afe11e25b70d36fc3d42a33b08996497d204
MD5 9d6d6ccc109a9d58362a063c629fc23d
BLAKE2b-256 dedbc5493e43862e0e3a19ca55a4be488f92b235c0cc0919fd2df78756ac0ff1

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for tf_shell-0.1.3-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f1d0501b7250665d52a423f73f437c058ae3d2afd84bd0631995e01b13fa551a
MD5 7236c67ec5b7c6aab94d3e2b3311fc0a
BLAKE2b-256 5e98398463ae9cab90ca164657420d73522444a09486848424ce79924ee9b864

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for tf_shell-0.1.3-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 16128313314bc03a18af6ef832dbb69e989b800ae4fb66c6c812773cbac8611a
MD5 1f85be30ee092ebfa4bb4cca293db20c
BLAKE2b-256 fef4076b37fcc00fe1c5783a5ef7140b166bfbf34bfac33cfc955e072411848b

See more details on using hashes here.

Provenance

Supported by

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