diff --git a/.gitattributes b/.gitattributes index 4f1f0a3d7..f7d6f7e97 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,5 +5,5 @@ docs/advanced_examples/data/** filter=lfs diff=lfs merge=lfs -text *.tar filter=lfs diff=lfs merge=lfs -text *.pt filter=lfs diff=lfs merge=lfs -text use_case_examples/cifar_10_with_model_splitting/mlir.txt filter=lfs diff=lfs merge=lfs -text -docs/developer-guide/api/** binary +docs/references/api/** binary use_case_examples/credit_scoring/hmeq.csv filter=lfs diff=lfs merge=lfs -text diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 12e7f1200..5154d45d2 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -520,7 +520,7 @@ jobs: - '!.*/**' - '!docs/_*/**' - '!docs/SUMMARY.md' - - '!docs/developer-guide/api/**.md' + - '!docs/references/api/**.md' dependencies: - deps_licenses/licenses_linux_user.txt.md5 conftest: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 17ccecda5..9bbb94d3e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -16,7 +16,7 @@ on: - 'release/*' paths: - src/concrete/ml/version.py - - 'docs/developer-guide/api/**' + - 'docs/references/api/**' # We need to make sure that the concurrency group is not identical to the continuous-integration.yaml # one, else the release workflow will be canceled when calling that latter for tests. More diff --git a/.gitignore b/.gitignore index 344ae88f5..fb4a4b5c7 100644 --- a/.gitignore +++ b/.gitignore @@ -78,7 +78,7 @@ docs/_build/ docs-copy/ # GitBook -docs/developer-guide/api/.pages +docs/references/api/.pages # PyBuilder target/ diff --git a/Makefile b/Makefile index 6ba647198..1d5f4dfb5 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ COUNT?=1 RANDOMLY_SEED?=$$RANDOM PYTEST_OPTIONS:= POETRY_VERSION:=1.7.1 -APIDOCS_OUTPUT?="./docs/developer-guide/api" +APIDOCS_OUTPUT?="./docs/references/api" OPEN_PR="true" # Force the installation of a Concrete Python version, which is very useful with nightly versions @@ -425,10 +425,12 @@ docs_no_links: clean_docs check_docs_dollars ! grep -r "hint style" docs-copy @# Replace $$, $/$ and /$$ by $ ./script/make_utils/fix_double_dollars_issues_with_mdformat.sh docs-copy --single_dollar + @# Replace `href="*.md` patterns with `href="*.html` because Sphinx does not handle them + ./script/make_utils/fix_md_to_html_conversion_from_sphinx_in_href.sh docs-copy + @# Replace `references/api/README.md` with `_apidoc/modules.html`. + ./script/make_utils/fix_api_readme_reference.sh docs-copy @# Fix not-compatible paths ./script/make_utils/fix_gitbook_paths.sh docs-copy - @# Fixing cardboard - poetry run python script/doc_utils/fix_gitbook_table.py --files docs-copy/getting-started/showcase.md @# Docs cd docs-copy && poetry run "$(MAKE)" html SPHINXOPTS='-W --keep-going' @# Copy images from GitBook @@ -669,7 +671,7 @@ mdformat: # Remark we need to remove .md's in venv check_mdformat: "$(MAKE)" mdformat - find docs -name "*.md" | grep -v docs/developer-guide/tmp.api_for_check | xargs git diff --quiet + find docs -name "*.md" | grep -v docs/references/tmp.api_for_check | xargs git diff --quiet .PHONY: benchmark # Perform benchmarks benchmark: diff --git a/README.md b/README.md index 59b5cdbb1..cae47fcfd 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Concrete ML is designed with ease of use in mind. Data scientists can use models - **Built-in models**: Ready-to-use FHE-friendly models with a user interface that is equivalent to their the scikit-learn and XGBoost counterparts - **Customs models**: Concrete ML supports models that can use quantization-aware training. These are developed by the user using PyTorch or keras/tensorflow and are imported into Concrete ML through ONNX -*Learn more about Concrete ML features in the [documentation](https://docs.zama.ai/concrete-ml/readme).* +*Learn more about Concrete ML features in the [documentation](https://docs.zama.ai/concrete-ml).*

### Use cases @@ -211,7 +211,7 @@ Concrete ML built-in models have APIs that are almost identical to their scikit- - [\[Video tutorial\] How To Convert a Scikit-learn Model Into Its Homomorphic Equivalent](https://www.zama.ai/post/how-to-convert-a-scikit-learn-model-into-its-homomorphic-equivalent) - [Linear Regression Over Encrypted Data With Homomorphic Encryption](https://www.zama.ai/post/linear-regression-using-linear-svr-and-concrete-ml-homomorphic-encryption) - [How to Deploy a Machine Learning Model With Concrete ML](https://www.zama.ai/post/how-to-deploy-machine-learning-models-with-concrete-ml) -- More [Built-in models tutorials](docs/built-in-models/ml_examples.md) and [Deep learning tutorials](docs/deep-learning/examples.md) +- More [Built-in models tutorials](docs/tutorials/ml_examples.md) and [Deep learning tutorials](docs/tutorials/dl_examples.md) *Explore more useful resources in [Awesome Zama repo](https://github.com/zama-ai/awesome-zama)*

@@ -241,7 +241,7 @@ To cite Concrete ML in academic papers, please use the following entry: ### Contributing -To contribute to Concrete ML, please refer to [this section of the documentation](docs/developer-guide/contributing.md). +To contribute to Concrete ML, please refer to [this section of the documentation](docs/developer/contributing.md).

### License diff --git a/docs/.gitbook/assets/3.png b/docs/.gitbook/assets/3.png deleted file mode 100644 index bd13f1464..000000000 Binary files a/docs/.gitbook/assets/3.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_credit.png b/docs/.gitbook/assets/demo_credit.png deleted file mode 100644 index d0ebe7915..000000000 Binary files a/docs/.gitbook/assets/demo_credit.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_filtering.png b/docs/.gitbook/assets/demo_filtering.png deleted file mode 100644 index 3549b694b..000000000 Binary files a/docs/.gitbook/assets/demo_filtering.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_gpt2.png b/docs/.gitbook/assets/demo_gpt2.png deleted file mode 100644 index ab7ff4b66..000000000 Binary files a/docs/.gitbook/assets/demo_gpt2.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_health.png b/docs/.gitbook/assets/demo_health.png deleted file mode 100644 index 7601702e1..000000000 Binary files a/docs/.gitbook/assets/demo_health.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_mnist.png b/docs/.gitbook/assets/demo_mnist.png deleted file mode 100644 index 602101b4b..000000000 Binary files a/docs/.gitbook/assets/demo_mnist.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_nn_finetuning.png b/docs/.gitbook/assets/demo_nn_finetuning.png deleted file mode 100644 index a452d8e3b..000000000 Binary files a/docs/.gitbook/assets/demo_nn_finetuning.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_nn_splitting.png b/docs/.gitbook/assets/demo_nn_splitting.png deleted file mode 100644 index 647db4b50..000000000 Binary files a/docs/.gitbook/assets/demo_nn_splitting.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_sentiment.png b/docs/.gitbook/assets/demo_sentiment.png deleted file mode 100644 index fc4c8dd48..000000000 Binary files a/docs/.gitbook/assets/demo_sentiment.png and /dev/null differ diff --git a/docs/.gitbook/assets/demo_titanic.png b/docs/.gitbook/assets/demo_titanic.png deleted file mode 100644 index 89efb8cfe..000000000 Binary files a/docs/.gitbook/assets/demo_titanic.png and /dev/null differ diff --git a/docs/.gitbook/assets/doc_header_CML.png b/docs/.gitbook/assets/doc_header_CML.png new file mode 100644 index 000000000..73115f656 Binary files /dev/null and b/docs/.gitbook/assets/doc_header_CML.png differ diff --git a/docs/.gitbook/assets/fundamentals.jpg b/docs/.gitbook/assets/fundamentals.jpg new file mode 100644 index 000000000..94fba49fc Binary files /dev/null and b/docs/.gitbook/assets/fundamentals.jpg differ diff --git a/docs/.gitbook/assets/getstarted1.jpg b/docs/.gitbook/assets/getstarted1.jpg new file mode 100644 index 000000000..1d9254e0c Binary files /dev/null and b/docs/.gitbook/assets/getstarted1.jpg differ diff --git a/docs/.gitbook/assets/getstarted2.jpg b/docs/.gitbook/assets/getstarted2.jpg new file mode 100644 index 000000000..be44c0a04 Binary files /dev/null and b/docs/.gitbook/assets/getstarted2.jpg differ diff --git a/docs/.gitbook/assets/getstarted3.jpg b/docs/.gitbook/assets/getstarted3.jpg new file mode 100644 index 000000000..bb85f9c83 Binary files /dev/null and b/docs/.gitbook/assets/getstarted3.jpg differ diff --git a/docs/.gitbook/assets/guides.jpg b/docs/.gitbook/assets/guides.jpg new file mode 100644 index 000000000..88c9ebd5f Binary files /dev/null and b/docs/.gitbook/assets/guides.jpg differ diff --git a/docs/.gitbook/assets/tutorials.jpg b/docs/.gitbook/assets/tutorials.jpg new file mode 100644 index 000000000..6370df4c5 Binary files /dev/null and b/docs/.gitbook/assets/tutorials.jpg differ diff --git a/docs/README.md b/docs/README.md index 0a4a44f09..99799feff 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,118 +1,46 @@ -# What is Concrete ML? +--- +description: >- + Concrete ML is an open-source, privacy-preserving, machine learning framework + based on Fully Homomorphic Encryption (FHE). +--- -[⭐️ Star the repo on Github](https://github.com/zama-ai/concrete-ml) | [🗣 Community support forum](https://community.zama.ai/c/concrete-ml/8) | [📁 Contribute to the project](developer-guide/contributing.md) +# Welcome -![](.gitbook/assets/3.png) +## Start here -Concrete ML is an open source, privacy-preserving, machine learning framework based on Fully Homomorphic Encryption (FHE). It enables data scientists without any prior knowledge of cryptography to automatically turn machine learning models into their FHE equivalent, using familiar APIs from scikit-learn and PyTorch (see how it looks for [linear models](built-in-models/linear.md), [tree-based models](built-in-models/tree.md), and [neural networks](built-in-models/neural-networks.md)). Concrete ML supports converting models for inference with FHE but can also [train some models](built-in-models/training.md) on encrypted data. +Learn the basics of Concrete ML, set it up, and make it run with ease. -Fully Homomorphic Encryption is an encryption technique that allows computing directly on encrypted data, without needing to decrypt it. With FHE, you can build private-by-design applications without compromising on features. You can learn more about FHE in [this introduction](https://www.zama.ai/post/tfhe-deep-dive-part-1) or by joining the [FHE.org](https://fhe.org) community. +
What is Concrete MLgetstarted1.jpggetting-started
Installationgetstarted2.jpgpip_installing.md
Key conceptsgetstarted3.jpgconcepts.md
-Training on encrypted data provides the highest level of privacy but is slower than training on clear data. Federated learning is an alternative approach, where data privacy can be ensured by using a trusted gradient aggregator, coupled with optional _differential privacy_ instead of encryption. Concrete ML -can import linear models, including logistic regression, that are trained using federated learning using the [`from_sklearn` function](./built-in-models/linear.md#pre-trained-models). +## Build with Concrete ML -## Example usage +Start building with Concrete ML by exploring its core features, discovering essential guides, and learning more with user-friendly tutorials. -Here is a simple example of classification on encrypted data using logistic regression. More examples can be found [here](built-in-models/ml_examples.md). +
FundamentalsExplore core features and basics of Concrete ML.fundamentals.jpg
GuidesDiscover essential guides to work with Concrete ML.guides.jpg
TutorialsLearn more about Concrete ML with our tutorials.tutorials.jpg
-```python -from sklearn.datasets import make_classification -from sklearn.model_selection import train_test_split -from concrete.ml.sklearn import LogisticRegression +## References & Explanations -# Lets create a synthetic data-set -x, y = make_classification(n_samples=100, class_sep=2, n_features=30, random_state=42) +Refer to the API, review product architecture, and access additional resources for in-depth explanations while working with Concrete ML. -# Split the data-set into a train and test set -X_train, X_test, y_train, y_test = train_test_split( - x, y, test_size=0.2, random_state=42 -) +- [API](references/api/README.md) +- [Quantization](explanations/quantization.md) +- [Pruning](explanations/pruning.md) +- [Compilation](explanations/compilation.md) +- [Advanced features](explanations/advanced_features.md) +- [Project architecture](explanations/inner-workings/) -# Now we train in the clear and quantize the weights -model = LogisticRegression(n_bits=8) -model.fit(X_train, y_train) +## Supports -# We can simulate the predictions in the clear -y_pred_clear = model.predict(X_test) +Ask technical questions and discuss with the community. Our team of experts usually answers within 24 hours in working days. -# We then compile on a representative set -model.compile(X_train) +- [Community forum](https://community.zama.ai/) +- [Discord channel](https://discord.fhe.org/) -# Finally we run the inference on encrypted inputs -y_pred_fhe = model.predict(X_test, fhe="execute") +## Developers -print(f"In clear : {y_pred_clear}") -print(f"In FHE : {y_pred_fhe}") -print(f"Similarity: {(y_pred_fhe == y_pred_clear).mean():.1%}") +Collaborate with us to advance the FHE spaces and drive innovation together. -# Output: - # In clear : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0] - # In FHE : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0] - # Similarity: 100.0% -``` - -It is also possible to call encryption, model prediction, and decryption functions separately as follows. -Executing these steps separately is equivalent to calling `predict_proba` on the model instance. - - - -```python -# Predict probability for a single example -y_proba_fhe = model.predict_proba(X_test[[0]], fhe="execute") - -# Quantize an original float input -q_input = model.quantize_input(X_test[[0]]) - -# Encrypt the input -q_input_enc = model.fhe_circuit.encrypt(q_input) - -# Execute the linear product in FHE -q_y_enc = model.fhe_circuit.run(q_input_enc) - -# Decrypt the result (integer) -q_y = model.fhe_circuit.decrypt(q_y_enc) - -# De-quantize and post-process the result -y0 = model.post_processing(model.dequantize_output(q_y)) - -print("Probability with `predict_proba`: ", y_proba_fhe) -print("Probability with encrypt/run/decrypt calls: ", y0) -``` - -This example shows the typical flow of a Concrete ML model: - -- The model is trained on unencrypted (plaintext) data using scikit-learn. As FHE operates over integers, Concrete ML quantizes the model to use only integers during inference. -- The quantized model is compiled to an FHE equivalent. Under the hood, the model is first converted to a Concrete Python program, then compiled. -- Inference can then be done on encrypted data. The above example shows encrypted inference in the model-development phase. Alternatively, during [deployment](getting-started/cloud.md) in a client/server setting, the data is encrypted by the client, processed securely by the server, and then decrypted by the client. - -## Current limitations - -To make a model work with FHE, the only constraint is to make it run within the supported precision limitations of Concrete ML (currently 16-bit integers). Thus, machine learning models must be quantized, which sometimes leads to a loss of accuracy versus the original model, which operates on plaintext. - -Additionally, Concrete ML currently only supports training on encrypted data for some models, while it supports _inference_ for a large variety of models. - -Finally, there is currently no support for pre-processing model inputs and post-processing model outputs. These processing stages may involve text-to-numerical feature transformation, dimensionality reduction, KNN or clustering, featurization, normalization, and the mixing of results of ensemble models. - -These issues are currently being addressed, and significant improvements are expected to be released in the near future. - -## Concrete stack - -Concrete ML is built on top of Zama's [Concrete](https://github.com/zama-ai/concrete). - -## Online demos and tutorials - -Various tutorials are available for [built-in models](built-in-models/ml_examples.md) and [deep learning](deep-learning/examples.md). Several stand-alone demos for use cases can be found in the [Demos and Tutorials](getting-started/showcase.md) section. - -If you have built awesome projects using Concrete ML, feel free to let us know and we'll link to your work! - -## Additional resources - -- [Dedicated Concrete ML community support](https://community.zama.ai/c/concrete-ml/8) -- [Zama's blog](https://www.zama.ai/blog) -- [FHE.org community](https://fhe.org) - -## Support - -- Support forum: [https://community.zama.ai](https://community.zama.ai) (we answer in less than 24 hours). -- Live discussion on the FHE.org Discord server: [https://discord.fhe.org](https://discord.fhe.org) (inside the #**concrete** channel). -- Do you have a question about Zama? Write us on [Twitter](https://twitter.com/zama_fhe) or send us an email at: **hello@zama.ai** +- [Contribute to Concrete ML](developer/contributing.md) +- [Check the latest release note](https://github.com/zama-ai/concrete-ml/releases) +- [Request a feature](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=feature&projects=&template=feature_request.md) +- [Report a bug](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=bug&projects=&template=bug_report.md) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 17565d8ed..207a67d26 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -1,111 +1,118 @@ -# Table of Contents +# Table of contents -- [What is Concrete ML?](README.md) +- [Welcome](README.md) ## Getting Started +- [What is Concrete ML?](getting-started/README.md) - [Installation](getting-started/pip_installing.md) -- [Key Concepts](getting-started/concepts.md) -- [Inference in the Cloud](getting-started/cloud.md) -- [Demos and Tutorials](getting-started/showcase.md) +- [Key concepts](getting-started/concepts.md) +- [Inference in the cloud](getting-started/cloud.md) ## Built-in Models -- [Linear Models](built-in-models/linear.md) -- [Tree-based Models](built-in-models/tree.md) -- [Neural Networks](built-in-models/neural-networks.md) -- [Nearest Neighbors](built-in-models/nearest-neighbors.md) +- [Linear models](built-in-models/linear.md) +- [Tree-based models](built-in-models/tree.md) +- [Neural networks](built-in-models/neural-networks.md) +- [Nearest neighbors](built-in-models/nearest-neighbors.md) - [Pandas](built-in-models/pandas.md) -- [Encrypted Training](built-in-models/training.md) -- [Built-in Model Examples](built-in-models/ml_examples.md) +- [Encrypted training](built-in-models/training.md) ## Deep Learning - [Using Torch](deep-learning/torch_support.md) - [Using ONNX](deep-learning/onnx_support.md) -- [Step-by-step Guide](deep-learning/fhe_friendly_models.md) -- [Deep Learning Examples](deep-learning/examples.md) -- [Debugging Models](deep-learning/fhe_assistant.md) -- [Optimizing Inference](deep-learning/optimizing_inference.md) - -## Deployment - -- [Prediction with FHE](advanced-topics/prediction_with_fhe.md) -- [Hybrid models](advanced-topics/hybrid-models.md) -- [Production Deployment](advanced-topics/client_server.md) -- [Serialization](advanced-topics/serialization.md) - -## Advanced topics - -- [Quantization](advanced-topics/quantization.md) -- [Pruning](advanced-topics/pruning.md) -- [Compilation](advanced-topics/compilation.md) -- [Advanced Features](advanced-topics/advanced_features.md) - -## Developer Guide - -- [Workflow](developer-guide/workflow/README.md) - - [Set Up the Project](developer-guide/project_setup.md) - - [Set Up Docker](developer-guide/docker_setup.md) - - [Documentation](developer-guide/documenting.md) - - [Support and Issues](developer-guide/debug_support_submit_issues.md) - - [Contributing](developer-guide/contributing.md) -- [Inner Workings](developer-guide/inner-workings/README.md) - - [Importing ONNX](developer-guide/onnx_pipeline.md) - - [Quantization Tools](developer-guide/quantization_internal.md) - - [FHE Op-graph Design](developer-guide/fhe-op-graphs.md) - - [External Libraries](developer-guide/external_libraries.md) -- [API](developer-guide/api/README.md) - - - [concrete.ml.common.check_inputs.md](developer-guide/api/concrete.ml.common.check_inputs.md) - - [concrete.ml.common.debugging.custom_assert.md](developer-guide/api/concrete.ml.common.debugging.custom_assert.md) - - [concrete.ml.common.debugging.md](developer-guide/api/concrete.ml.common.debugging.md) - - [concrete.ml.common.md](developer-guide/api/concrete.ml.common.md) - - [concrete.ml.common.serialization.decoder.md](developer-guide/api/concrete.ml.common.serialization.decoder.md) - - [concrete.ml.common.serialization.dumpers.md](developer-guide/api/concrete.ml.common.serialization.dumpers.md) - - [concrete.ml.common.serialization.encoder.md](developer-guide/api/concrete.ml.common.serialization.encoder.md) - - [concrete.ml.common.serialization.loaders.md](developer-guide/api/concrete.ml.common.serialization.loaders.md) - - [concrete.ml.common.serialization.md](developer-guide/api/concrete.ml.common.serialization.md) - - [concrete.ml.common.utils.md](developer-guide/api/concrete.ml.common.utils.md) - - [concrete.ml.deployment.deploy_to_aws.md](developer-guide/api/concrete.ml.deployment.deploy_to_aws.md) - - [concrete.ml.deployment.deploy_to_docker.md](developer-guide/api/concrete.ml.deployment.deploy_to_docker.md) - - [concrete.ml.deployment.fhe_client_server.md](developer-guide/api/concrete.ml.deployment.fhe_client_server.md) - - [concrete.ml.deployment.md](developer-guide/api/concrete.ml.deployment.md) - - [concrete.ml.deployment.server.md](developer-guide/api/concrete.ml.deployment.server.md) - - [concrete.ml.deployment.utils.md](developer-guide/api/concrete.ml.deployment.utils.md) - - [concrete.ml.onnx.convert.md](developer-guide/api/concrete.ml.onnx.convert.md) - - [concrete.ml.onnx.md](developer-guide/api/concrete.ml.onnx.md) - - [concrete.ml.onnx.onnx_impl_utils.md](developer-guide/api/concrete.ml.onnx.onnx_impl_utils.md) - - [concrete.ml.onnx.onnx_model_manipulations.md](developer-guide/api/concrete.ml.onnx.onnx_model_manipulations.md) - - [concrete.ml.onnx.onnx_utils.md](developer-guide/api/concrete.ml.onnx.onnx_utils.md) - - [concrete.ml.onnx.ops_impl.md](developer-guide/api/concrete.ml.onnx.ops_impl.md) - - [concrete.ml.pytest.md](developer-guide/api/concrete.ml.pytest.md) - - [concrete.ml.pytest.torch_models.md](developer-guide/api/concrete.ml.pytest.torch_models.md) - - [concrete.ml.pytest.utils.md](developer-guide/api/concrete.ml.pytest.utils.md) - - [concrete.ml.quantization.base_quantized_op.md](developer-guide/api/concrete.ml.quantization.base_quantized_op.md) - - [concrete.ml.quantization.md](developer-guide/api/concrete.ml.quantization.md) - - [concrete.ml.quantization.post_training.md](developer-guide/api/concrete.ml.quantization.post_training.md) - - [concrete.ml.quantization.quantized_module.md](developer-guide/api/concrete.ml.quantization.quantized_module.md) - - [concrete.ml.quantization.quantized_module_passes.md](developer-guide/api/concrete.ml.quantization.quantized_module_passes.md) - - [concrete.ml.quantization.quantized_ops.md](developer-guide/api/concrete.ml.quantization.quantized_ops.md) - - [concrete.ml.quantization.quantizers.md](developer-guide/api/concrete.ml.quantization.quantizers.md) - - [concrete.ml.search_parameters.md](developer-guide/api/concrete.ml.search_parameters.md) - - [concrete.ml.search_parameters.p_error_search.md](developer-guide/api/concrete.ml.search_parameters.p_error_search.md) - - [concrete.ml.sklearn.base.md](developer-guide/api/concrete.ml.sklearn.base.md) - - [concrete.ml.sklearn.glm.md](developer-guide/api/concrete.ml.sklearn.glm.md) - - [concrete.ml.sklearn.linear_model.md](developer-guide/api/concrete.ml.sklearn.linear_model.md) - - [concrete.ml.sklearn.md](developer-guide/api/concrete.ml.sklearn.md) - - [concrete.ml.sklearn.neighbors.md](developer-guide/api/concrete.ml.sklearn.neighbors.md) - - [concrete.ml.sklearn.qnn.md](developer-guide/api/concrete.ml.sklearn.qnn.md) - - [concrete.ml.sklearn.qnn_module.md](developer-guide/api/concrete.ml.sklearn.qnn_module.md) - - [concrete.ml.sklearn.rf.md](developer-guide/api/concrete.ml.sklearn.rf.md) - - [concrete.ml.sklearn.svm.md](developer-guide/api/concrete.ml.sklearn.svm.md) - - [concrete.ml.sklearn.tree.md](developer-guide/api/concrete.ml.sklearn.tree.md) - - [concrete.ml.sklearn.tree_to_numpy.md](developer-guide/api/concrete.ml.sklearn.tree_to_numpy.md) - - [concrete.ml.sklearn.xgb.md](developer-guide/api/concrete.ml.sklearn.xgb.md) - - [concrete.ml.torch.compile.md](developer-guide/api/concrete.ml.torch.compile.md) - - [concrete.ml.torch.hybrid_model.md](developer-guide/api/concrete.ml.torch.hybrid_model.md) - - [concrete.ml.torch.md](developer-guide/api/concrete.ml.torch.md) - - [concrete.ml.torch.numpy_module.md](developer-guide/api/concrete.ml.torch.numpy_module.md) - - [concrete.ml.version.md](developer-guide/api/concrete.ml.version.md) - +- [Step-by-step guide](deep-learning/fhe_friendly_models.md) +- [Debugging models](deep-learning/fhe_assistant.md) +- [Optimizing inference](deep-learning/optimizing_inference.md) + +## Guides + +- [Prediction with FHE](guides/prediction_with_fhe.md) +- [Production deployment](guides/client_server.md) +- [Hybrid models](guides/hybrid-models.md) +- [Serialization](guides/serialization.md) + +## Tutorials + +- [See all tutorials](tutorials/showcase.md) +- [Built-in model examples](tutorials/ml_examples.md) +- [Deep learning examples](tutorials/dl_examples.md) + +## References + +- [API](references/api/README.md) + - [concrete.ml.common.check_inputs.md](references/api/concrete.ml.common.check_inputs.md) + - [concrete.ml.common.debugging.custom_assert.md](references/api/concrete.ml.common.debugging.custom_assert.md) + - [concrete.ml.common.debugging.md](references/api/concrete.ml.common.debugging.md) + - [concrete.ml.common.md](references/api/concrete.ml.common.md) + - [concrete.ml.common.serialization.decoder.md](references/api/concrete.ml.common.serialization.decoder.md) + - [concrete.ml.common.serialization.dumpers.md](references/api/concrete.ml.common.serialization.dumpers.md) + - [concrete.ml.common.serialization.encoder.md](references/api/concrete.ml.common.serialization.encoder.md) + - [concrete.ml.common.serialization.loaders.md](references/api/concrete.ml.common.serialization.loaders.md) + - [concrete.ml.common.serialization.md](references/api/concrete.ml.common.serialization.md) + - [concrete.ml.common.utils.md](references/api/concrete.ml.common.utils.md) + - [concrete.ml.deployment.deploy_to_aws.md](references/api/concrete.ml.deployment.deploy_to_aws.md) + - [concrete.ml.deployment.deploy_to_docker.md](references/api/concrete.ml.deployment.deploy_to_docker.md) + - [concrete.ml.deployment.fhe_client_server.md](references/api/concrete.ml.deployment.fhe_client_server.md) + - [concrete.ml.deployment.md](references/api/concrete.ml.deployment.md) + - [concrete.ml.deployment.server.md](references/api/concrete.ml.deployment.server.md) + - [concrete.ml.deployment.utils.md](references/api/concrete.ml.deployment.utils.md) + - [concrete.ml.onnx.convert.md](references/api/concrete.ml.onnx.convert.md) + - [concrete.ml.onnx.md](references/api/concrete.ml.onnx.md) + - [concrete.ml.onnx.onnx_impl_utils.md](references/api/concrete.ml.onnx.onnx_impl_utils.md) + - [concrete.ml.onnx.onnx_model_manipulations.md](references/api/concrete.ml.onnx.onnx_model_manipulations.md) + - [concrete.ml.onnx.onnx_utils.md](references/api/concrete.ml.onnx.onnx_utils.md) + - [concrete.ml.onnx.ops_impl.md](references/api/concrete.ml.onnx.ops_impl.md) + - [concrete.ml.pytest.md](references/api/concrete.ml.pytest.md) + - [concrete.ml.pytest.torch_models.md](references/api/concrete.ml.pytest.torch_models.md) + - [concrete.ml.pytest.utils.md](references/api/concrete.ml.pytest.utils.md) + - [concrete.ml.quantization.base_quantized_op.md](references/api/concrete.ml.quantization.base_quantized_op.md) + - [concrete.ml.quantization.md](references/api/concrete.ml.quantization.md) + - [concrete.ml.quantization.post_training.md](references/api/concrete.ml.quantization.post_training.md) + - [concrete.ml.quantization.quantized_module.md](references/api/concrete.ml.quantization.quantized_module.md) + - [concrete.ml.quantization.quantized_module_passes.md](references/api/concrete.ml.quantization.quantized_module_passes.md) + - [concrete.ml.quantization.quantized_ops.md](references/api/concrete.ml.quantization.quantized_ops.md) + - [concrete.ml.quantization.quantizers.md](references/api/concrete.ml.quantization.quantizers.md) + - [concrete.ml.search_parameters.md](references/api/concrete.ml.search_parameters.md) + - [concrete.ml.search_parameters.p_error_search.md](references/api/concrete.ml.search_parameters.p_error_search.md) + - [concrete.ml.sklearn.base.md](references/api/concrete.ml.sklearn.base.md) + - [concrete.ml.sklearn.glm.md](references/api/concrete.ml.sklearn.glm.md) + - [concrete.ml.sklearn.linear_model.md](references/api/concrete.ml.sklearn.linear_model.md) + - [concrete.ml.sklearn.md](references/api/concrete.ml.sklearn.md) + - [concrete.ml.sklearn.neighbors.md](references/api/concrete.ml.sklearn.neighbors.md) + - [concrete.ml.sklearn.qnn.md](references/api/concrete.ml.sklearn.qnn.md) + - [concrete.ml.sklearn.qnn_module.md](references/api/concrete.ml.sklearn.qnn_module.md) + - [concrete.ml.sklearn.rf.md](references/api/concrete.ml.sklearn.rf.md) + - [concrete.ml.sklearn.svm.md](references/api/concrete.ml.sklearn.svm.md) + - [concrete.ml.sklearn.tree.md](references/api/concrete.ml.sklearn.tree.md) + - [concrete.ml.sklearn.tree_to_numpy.md](references/api/concrete.ml.sklearn.tree_to_numpy.md) + - [concrete.ml.sklearn.xgb.md](references/api/concrete.ml.sklearn.xgb.md) + - [concrete.ml.torch.compile.md](references/api/concrete.ml.torch.compile.md) + - [concrete.ml.torch.hybrid_model.md](references/api/concrete.ml.torch.hybrid_model.md) + - [concrete.ml.torch.md](references/api/concrete.ml.torch.md) + - [concrete.ml.torch.numpy_module.md](references/api/concrete.ml.torch.numpy_module.md) + - [concrete.ml.version.md](references/api/concrete.ml.version.md) + +## Explanations + +- [Quantization](explanations/quantization.md) +- [Pruning](explanations/pruning.md) +- [Compilation](explanations/compilation.md) +- [Advanced features](explanations/advanced_features.md) +- [Project architecture](explanations/inner-workings/README.md) + - [Importing ONNX](explanations/inner-workings/onnx_pipeline.md) + - [Quantization tools](explanations/inner-workings/quantization_internal.md) + - [FHE Op-graph design](explanations/inner-workings/fhe-op-graphs.md) + - [External libraries](explanations/inner-workings/external_libraries.md) + +## Developer + +- [Set up the project](developer/project_setup.md) +- [Set up Docker](developer/docker_setup.md) +- [Documentation](developer/documenting.md) +- [Support and issues](developer/debug_support_submit_issues.md) +- [Contributing](developer/contributing.md) +- [Release note](https://github.com/zama-ai/concrete-ml/releases) +- [Feature request](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=feature&projects=&template=feature_request.md) +- [Bug report](https://github.com/zama-ai/concrete-ml/issues/new?assignees=&labels=bug&projects=&template=bug_report.md) diff --git a/docs/built-in-models/linear.md b/docs/built-in-models/linear.md index d8cf7b4a1..77dd3c5fe 100644 --- a/docs/built-in-models/linear.md +++ b/docs/built-in-models/linear.md @@ -1,20 +1,20 @@ -# Linear Models +# Linear models Concrete ML provides several of the most popular linear models for `regression` and `classification` that can be found in [scikit-learn](https://scikit-learn.org/stable/): -| Concrete ML | scikit-learn | -| :-------------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------: | -| [LinearRegression](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-linearregression) | [LinearRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html#sklearn.linear_model.LinearRegression) | -| [LogisticRegression](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-logisticregression) | [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression) | -| [LinearSVC](../developer-guide/api/concrete.ml.sklearn.svm.md#class-linearsvc) | [LinearSVC](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html#sklearn.svm.LinearSVC) | -| [LinearSVR](../developer-guide/api/concrete.ml.sklearn.svm.md#class-linearsvr) | [LinearSVR](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVR.html#sklearn.svm.LinearSVR) | -| [PoissonRegressor](../developer-guide/api/concrete.ml.sklearn.glm.md#class-poissonregressor) | [PoissonRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.PoissonRegressor.html#sklearn.linear_model.PoissonRegressor) | -| [TweedieRegressor](../developer-guide/api/concrete.ml.sklearn.glm.md#class-tweedieregressor) | [TweedieRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.TweedieRegressor.html#sklearn.linear_model.TweedieRegressor) | -| [GammaRegressor](../developer-guide/api/concrete.ml.sklearn.glm.md#class-gammaregressor) | [GammaRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.GammaRegressor.html#sklearn.linear_model.GammaRegressor) | -| [Lasso](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-lasso) | [Lasso](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso) | -| [Ridge](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-ridge) | [Ridge](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html#sklearn.linear_model.Ridge) | -| [ElasticNet](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-elasticnet) | [ElasticNet](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ElasticNet.html#sklearn.linear_model.ElasticNet) | -| [SGDRegressor](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-sgdregressor) | [SGDRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html) | +| Concrete ML | scikit-learn | +| :--------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------------: | +| [LinearRegression](../references/api/concrete.ml.sklearn.linear_model.md#class-linearregression) | [LinearRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html#sklearn.linear_model.LinearRegression) | +| [LogisticRegression](../references/api/concrete.ml.sklearn.linear_model.md#class-logisticregression) | [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html#sklearn.linear_model.LogisticRegression) | +| [LinearSVC](../references/api/concrete.ml.sklearn.svm.md#class-linearsvc) | [LinearSVC](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVC.html#sklearn.svm.LinearSVC) | +| [LinearSVR](../references/api/concrete.ml.sklearn.svm.md#class-linearsvr) | [LinearSVR](https://scikit-learn.org/stable/modules/generated/sklearn.svm.LinearSVR.html#sklearn.svm.LinearSVR) | +| [PoissonRegressor](../references/api/concrete.ml.sklearn.glm.md#class-poissonregressor) | [PoissonRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.PoissonRegressor.html#sklearn.linear_model.PoissonRegressor) | +| [TweedieRegressor](../references/api/concrete.ml.sklearn.glm.md#class-tweedieregressor) | [TweedieRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.TweedieRegressor.html#sklearn.linear_model.TweedieRegressor) | +| [GammaRegressor](../references/api/concrete.ml.sklearn.glm.md#class-gammaregressor) | [GammaRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.GammaRegressor.html#sklearn.linear_model.GammaRegressor) | +| [Lasso](../references/api/concrete.ml.sklearn.linear_model.md#class-lasso) | [Lasso](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html#sklearn.linear_model.Lasso) | +| [Ridge](../references/api/concrete.ml.sklearn.linear_model.md#class-ridge) | [Ridge](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Ridge.html#sklearn.linear_model.Ridge) | +| [ElasticNet](../references/api/concrete.ml.sklearn.linear_model.md#class-elasticnet) | [ElasticNet](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.ElasticNet.html#sklearn.linear_model.ElasticNet) | +| [SGDRegressor](../references/api/concrete.ml.sklearn.linear_model.md#class-sgdregressor) | [SGDRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html) | Using these models in FHE is extremely similar to what can be done with scikit-learn's [API](https://scikit-learn.org/stable/modules/classes.html#module-sklearn.linear_model), making it easy for data scientists who have used this framework to get started with Concrete ML. @@ -22,7 +22,7 @@ Models are also compatible with some of scikit-learn's main workflows, such as ` ## Pre-trained models -It is possible to convert an already trained scikit-learn linear model to a Concrete ML one by using the [`from_sklearn_model`](../developer-guide/api/concrete.ml.sklearn.base.md#classmethod-from_sklearn_model) method. See [below for an example](#loading-a-pre-trained-model). This functionality is only available for linear models. +It is possible to convert an already trained scikit-learn linear model to a Concrete ML one by using the [`from_sklearn_model`](../references/api/concrete.ml.sklearn.base.md#classmethod-from_sklearn_model) method. See [below for an example](linear.md#loading-a-pre-trained-model). This functionality is only available for linear models. ## Quantization parameters @@ -30,12 +30,11 @@ The `n_bits` parameter controls the bit-width of the inputs and weights of the l The `n_bits` parameter can be set to `8` or more bits for models with up to `300` input dimensions. When the input has more dimensions, `n_bits` must be reduced to `6-7`. All performance metrics are preserved down to `n_bits=6`, compared to the non-quantized float models from scikit-learn. -The same quantization parameters (i.e., scale and zero-point) are applied on all features, so it can be beneficial to make all feature distribution similar by using standard or min-max normalization. -For a more detailed comparison of the impact of such pre-processing please refer to [the logistic regression notebook](../advanced_examples/LogisticRegression.ipynb). +The same quantization parameters (i.e., scale and zero-point) are applied on all features, so it can be beneficial to make all feature distribution similar by using standard or min-max normalization. For a more detailed comparison of the impact of such pre-processing please refer to [the logistic regression notebook](../advanced_examples/LogisticRegression.ipynb). ## Example -The following snippet gives an example about training a LogisticRegression model on a simple data-set followed by inference on encrypted data with FHE. A more complete example can be found in the [LogisticRegression notebook](ml_examples.md). +The following snippet gives an example about training a LogisticRegression model on a simple data-set followed by inference on encrypted data with FHE. A more complete example can be found in the [LogisticRegression notebook](../tutorials/ml_examples.md). ```python from sklearn.datasets import make_classification @@ -81,7 +80,7 @@ print( # 100 examples over 100 have an FHE inference equal to the clear inference ``` -We can then plot the decision boundary of the classifier and compare those results with a scikit-learn model executed in clear. The complete code can be found in the [LogisticRegression notebook](ml_examples.md). +We can then plot the decision boundary of the classifier and compare those results with a scikit-learn model executed in clear. The complete code can be found in the [LogisticRegression notebook](../tutorials/ml_examples.md). ![Sklearn model decision boundaries](../figures/logistic_regression_clear.png) ![FHE model decision boundarires](../figures/logistic_regression_fhe.png) @@ -91,8 +90,6 @@ The overall accuracy scores are identical (93%) between the scikit-learn model ( An alternative to the example above is to train a scikit-learn model in a separate step and then to convert it to Concrete ML. - - ``` from sklearn.linear_model import LogisticRegression as SKlearnLogisticRegression diff --git a/docs/built-in-models/nearest-neighbors.md b/docs/built-in-models/nearest-neighbors.md index 5e77d57d5..9016a5791 100644 --- a/docs/built-in-models/nearest-neighbors.md +++ b/docs/built-in-models/nearest-neighbors.md @@ -1,10 +1,10 @@ -# Nearest-neighbors +# Nearest neighbors Concrete ML offers nearest neighbors non-parametric classification models with a scikit-learn interface through the `KNeighborsClassifier` class. -| Concrete ML | scikit-learn | -| :--------------------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------- | -| [KNeighborsClassifier](../developer-guide/api/concrete.ml.sklearn.neighbors.md#class-kneighborsclassifier) | [KNeighborsClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) | +| Concrete ML | scikit-learn | +| :---------------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------- | +| [KNeighborsClassifier](../references/api/concrete.ml.sklearn.neighbors.md#class-kneighborsclassifier) | [KNeighborsClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) | ## Example usage diff --git a/docs/built-in-models/neural-networks.md b/docs/built-in-models/neural-networks.md index f88d3cc7e..5b2920f61 100644 --- a/docs/built-in-models/neural-networks.md +++ b/docs/built-in-models/neural-networks.md @@ -1,13 +1,13 @@ -# Neural Networks +# Neural networks Concrete ML provides simple built-in neural networks models with a scikit-learn interface through the `NeuralNetClassifier` and `NeuralNetRegressor` classes. -| Concrete ML | scikit-learn | -| :------------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------ | -| [NeuralNetClassifier](../developer-guide/api/concrete.ml.sklearn.qnn.md#class-neuralnetclassifier) | [MLPClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html) | -| [NeuralNetRegressor](../developer-guide/api/concrete.ml.sklearn.qnn.md#class-neuralnetregressor) | [MLPRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html) | +| Concrete ML | scikit-learn | +| :-------------------------------------------------------------------------------------------: | ------------------------------------------------------------------------------------------------------------ | +| [NeuralNetClassifier](../references/api/concrete.ml.sklearn.qnn.md#class-neuralnetclassifier) | [MLPClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPClassifier.html) | +| [NeuralNetRegressor](../references/api/concrete.ml.sklearn.qnn.md#class-neuralnetregressor) | [MLPRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html) | -The neural network models are implemented with [skorch](https://skorch.readthedocs.io/en/stable/index.html), which provides a scikit-learn-like interface to Torch models (more [here](../developer-guide/external_libraries.md#skorch)). +The neural network models are implemented with [skorch](https://skorch.readthedocs.io/en/stable/index.html), which provides a scikit-learn-like interface to Torch models (more [here](../explanations/inner-workings/external_libraries.md#skorch)). Concrete ML models are multi-layer, fully-connected, networks with customizable activation functions and have a number of neurons in each layer. This approach is similar to what is available in scikit-learn when using the `MLPClassifier`/`MLPRegressor` classes. The built-in models train easily with a single call to `.fit()`, which will automatically quantize weights and activations. These models use Quantization Aware Training, allowing good performance for low precision (down to 2-3 bits) weights and activations. @@ -18,7 +18,7 @@ Good quantization parameter values are critical to make models [respect FHE cons {% endhint %} {% hint style="warning" %} -Using `nn.ReLU` as the activation function benefits from an optimization where [quantization uses powers-of-two scales](../advanced-topics/quantization.md#quantization-special-cases). This results in much faster inference times in FHE, thanks to a TFHE primitive that performs fast division by powers of two. +Using `nn.ReLU` as the activation function benefits from an optimization where [quantization uses powers-of-two scales](../explanations/quantization.md#quantization-special-cases). This results in much faster inference times in FHE, thanks to a TFHE primitive that performs fast division by powers of two. {% endhint %} ## Example usage @@ -39,7 +39,7 @@ params = { concrete_classifier = NeuralNetClassifier(**params) ``` -The [Classifier Comparison notebook](ml_examples.md) shows the behavior of built-in neural networks on several synthetic data-sets. +The [Classifier Comparison notebook](../tutorials/ml_examples.md) shows the behavior of built-in neural networks on several synthetic data-sets. ![Comparison neural networks](../figures/neural_nets_builtin.png) @@ -54,8 +54,8 @@ The figure above right shows the Concrete ML neural network, trained with Quanti - `n_w_bits` (default 3): number of bits for weights - `n_a_bits` (default 3): number of bits for activations and inputs -- `n_accum_bits`: maximum accumulator bit-width that is desired. By default, this is unbounded, which, for weight and activation bit-width settings, [may make the trained networks fail in compilation](#overflow-errors). When used, the implementation will attempt to keep accumulators under this bit-width through [pruning](../advanced-topics/pruning.md) (i.e., setting some weights to zero) -- `power_of_two_scaling` (default True): forces quantization scales to be powers-of-two, which, when coupled with the ReLU activation, benefits from strong FHE inference time optimization. See this [section](../advanced-topics/quantization.md#quantization-special-cases) in the quantization documentation for more details. +- `n_accum_bits`: maximum accumulator bit-width that is desired. By default, this is unbounded, which, for weight and activation bit-width settings, [may make the trained networks fail in compilation](neural-networks.md#overflow-errors). When used, the implementation will attempt to keep accumulators under this bit-width through [pruning](../explanations/pruning.md) (i.e., setting some weights to zero) +- `power_of_two_scaling` (default True): forces quantization scales to be powers-of-two, which, when coupled with the ReLU activation, benefits from strong FHE inference time optimization. See this [section](../explanations/quantization.md#quantization-special-cases) in the quantization documentation for more details. ### Training parameters (from skorch) @@ -67,7 +67,7 @@ Other parameters from skorch can be found in the [skorch documentation](https:// ### Advanced parameters -- `module__n_hidden_neurons_multiplier`: The number of hidden neurons will be automatically set proportional to the dimensionality of the input. This parameter controls the proportionality factor and is set to 4 by default. This value gives good accuracy while avoiding accumulator overflow. See the [pruning](../advanced-topics/pruning.md) and [quantization](../advanced-topics/quantization.md) sections for more info. +- `module__n_hidden_neurons_multiplier`: The number of hidden neurons will be automatically set proportional to the dimensionality of the input. This parameter controls the proportionality factor and is set to 4 by default. This value gives good accuracy while avoiding accumulator overflow. See the [pruning](../explanations/pruning.md) and [quantization](../explanations/quantization.md) sections for more info. ### Class weights diff --git a/docs/built-in-models/training.md b/docs/built-in-models/training.md index 0bd1f29d0..53144b478 100644 --- a/docs/built-in-models/training.md +++ b/docs/built-in-models/training.md @@ -1,6 +1,6 @@ -# Training on Encrypted Data +# Encrypted training -Concrete ML offers the possibility to train [SGD Logistic Regression](../developer-guide/api/concrete.ml.sklearn.linear_model.md#class-sgdclassifier) on encrypted data. The [logistic regression training](../advanced_examples/LogisticRegressionTraining.ipynb) example shows this feature in action. +Concrete ML offers the possibility to train [SGD Logistic Regression](../references/api/concrete.ml.sklearn.linear_model.md#class-sgdclassifier) on encrypted data. The [logistic regression training](../advanced_examples/LogisticRegressionTraining.ipynb) example shows this feature in action. This example shows how to instantiate a logistic regression model that trains on encrypted data: @@ -16,8 +16,7 @@ model = SGDClassifier( ) ``` -To activate encrypted training simply set `fit_encrypted=True` in the constructor. If this value is not set, training is performed -on clear data using `scikit-learn` gradient descent. +To activate encrypted training simply set `fit_encrypted=True` in the constructor. If this value is not set, training is performed on clear data using `scikit-learn` gradient descent. Next, to perform the training on encrypted data, call the `fit` function with the `fhe="execute"` argument: @@ -28,9 +27,7 @@ model.fit(X_binary, y_binary, fhe="execute") ``` {% hint style="info" %} -Training on encrypted data provides the highest level of privacy but is slower than training on clear data. Federated learning is an alternative approach, where data privacy can be ensured by using a trusted gradient aggregator, coupled with optional _differential privacy_ instead of encryption. Concrete ML -can import linear models, including logistic regression, that are trained using federated learning using the [`from_sklearn` function](linear.md#pre-trained-models). - +Training on encrypted data provides the highest level of privacy but is slower than training on clear data. Federated learning is an alternative approach, where data privacy can be ensured by using a trusted gradient aggregator, coupled with optional _differential privacy_ instead of encryption. Concrete ML can import linear models, including logistic regression, that are trained using federated learning using the [`from_sklearn` function](linear.md#pre-trained-models). {% endhint %} ## Training configuration @@ -43,5 +40,4 @@ The `parameters_range` parameter determines the initialization of the coefficien The logistic model that can be trained uses Stochastic Gradient Descent (SGD) and quantizes for data, weights, gradients and the error measure. It currently supports training 6-bit models, training both the coefficients and the bias. -The `SGDClassifier` does not currently support training models with other values for the bit-widths. The execution time to train a model -is proportional to the number of features and the number of training examples in the batch. The `SGDClassifier` training does not currently support client/server deployment for training. +The `SGDClassifier` does not currently support training models with other values for the bit-widths. The execution time to train a model is proportional to the number of features and the number of training examples in the batch. The `SGDClassifier` training does not currently support client/server deployment for training. diff --git a/docs/built-in-models/tree.md b/docs/built-in-models/tree.md index 383c1dbd8..8e4d67950 100644 --- a/docs/built-in-models/tree.md +++ b/docs/built-in-models/tree.md @@ -1,33 +1,32 @@ -# Tree-based Models +# Tree-based models Concrete ML provides several of the most popular `classification` and `regression` tree models that can be found in [scikit-learn](https://scikit-learn.org/stable/): -| Concrete ML | scikit-learn | -| :-------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------: | -| [DecisionTreeClassifier](../developer-guide/api/concrete.ml.sklearn.tree.md#class-decisiontreeclassifier) | [DecisionTreeClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html#sklearn.tree.DecisionTreeClassifier) | -| [DecisionTreeRegressor](../developer-guide/api/concrete.ml.sklearn.tree.md#class-decisiontreeregressor) | [DecisionTreeRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeRegressor.html#sklearn.tree.DecisionTreeRegressor) | -| [RandomForestClassifier](../developer-guide/api/concrete.ml.sklearn.rf.md#class-randomforestclassifier) | [RandomForestClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier) | -| [RandomForestRegressor](../developer-guide/api/concrete.ml.sklearn.rf.md#class-randomforestregressor) | [RandomForestRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html#sklearn.ensemble.RandomForestRegressor) | +| Concrete ML | scikit-learn | +| :--------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------: | +| [DecisionTreeClassifier](../references/api/concrete.ml.sklearn.tree.md#class-decisiontreeclassifier) | [DecisionTreeClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html#sklearn.tree.DecisionTreeClassifier) | +| [DecisionTreeRegressor](../references/api/concrete.ml.sklearn.tree.md#class-decisiontreeregressor) | [DecisionTreeRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeRegressor.html#sklearn.tree.DecisionTreeRegressor) | +| [RandomForestClassifier](../references/api/concrete.ml.sklearn.rf.md#class-randomforestclassifier) | [RandomForestClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html#sklearn.ensemble.RandomForestClassifier) | +| [RandomForestRegressor](../references/api/concrete.ml.sklearn.rf.md#class-randomforestregressor) | [RandomForestRegressor](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html#sklearn.ensemble.RandomForestRegressor) | Concrete ML also supports [XGBoost](https://xgboost.ai/)'s `XGBClassifier` and `XGBRegressor`: -| Concrete ML | XGboost | -| :------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | -| [XGBClassifier](../developer-guide/api/concrete.ml.sklearn.xgb.md#class-xgbclassifier) | [XGBClassifier](https://xgboost.readthedocs.io/en/stable/python/python_api.html#xgboost.XGBClassifier) | -| [XGBRegressor](../developer-guide/api/concrete.ml.sklearn.xgb.md#class-xgbregressor) | [XGBRegressor](https://xgboost.readthedocs.io/en/stable/python/python_api.html#xgboost.XGBRegressor) | +| Concrete ML | XGboost | +| :-------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: | +| [XGBClassifier](../references/api/concrete.ml.sklearn.xgb.md#class-xgbclassifier) | [XGBClassifier](https://xgboost.readthedocs.io/en/stable/python/python_api.html#xgboost.XGBClassifier) | +| [XGBRegressor](../references/api/concrete.ml.sklearn.xgb.md#class-xgbregressor) | [XGBRegressor](https://xgboost.readthedocs.io/en/stable/python/python_api.html#xgboost.XGBRegressor) | {% hint style="info" %} For a formal explanation of the mechanisms that enable FHE-compatible decision trees, please see the following paper: [Privacy-Preserving Tree-Based Inference with Fully Homomorphic Encryption, arXiv:2303.01254](https://arxiv.org/abs/2303.01254) {% endhint %} {% hint style="info" %} -As the maximum depth parameter of decision trees and tree-ensemble models strongly increases the number of nodes in the trees, we recommend -using the XGBoost models which achieve better performance with lower depth. +As the maximum depth parameter of decision trees and tree-ensemble models strongly increases the number of nodes in the trees, we recommend using the XGBoost models which achieve better performance with lower depth. {% endhint %} ## Example -Here's an example of how to use this model in FHE on a popular data-set using some of scikit-learn's pre-processing tools. A more complete example can be found in the [XGBClassifier notebook](ml_examples.md). +Here's an example of how to use this model in FHE on a popular data-set using some of scikit-learn's pre-processing tools. A more complete example can be found in the [XGBClassifier notebook](../tutorials/ml_examples.md). ```python from sklearn.datasets import load_breast_cancer @@ -111,7 +110,7 @@ print(f"{(y_pred_fhe == y_pred_clear[:N_TEST_FHE]).sum()} " # 1 examples over 1 have an FHE inference equal to the clear inference ``` -Similarly, the decision boundaries of the Concrete ML model can be plotted and compared to the results of the classical XGBoost model executed in the clear. A 6-bit model is shown in order to illustrate the impact of quantization on classification. Similar plots can be found in the [Classifier Comparison notebook](ml_examples.md). +Similarly, the decision boundaries of the Concrete ML model can be plotted and compared to the results of the classical XGBoost model executed in the clear. A 6-bit model is shown in order to illustrate the impact of quantization on classification. Similar plots can be found in the [Classifier Comparison notebook](../tutorials/ml_examples.md). ![Comparison of clasification decision boundaries between FHE and plaintext models](../figures/xgb_comparison_pipeline.png) @@ -127,9 +126,7 @@ The following graph shows that using 5-6 bits of quantization is usually suffici ## FHE Inference time considerations -The inference time in FHE is strongly dependant on the maximum circuit bit-width. For trees, in most cases, the quantization bit-width -will be the same as the circuit bit-width. Therefore, reducing the quantization bit-width to 4 or less will result in fast inference times. -Adding more bits will increase FHE inference time exponentially. +The inference time in FHE is strongly dependant on the maximum circuit bit-width. For trees, in most cases, the quantization bit-width will be the same as the circuit bit-width. Therefore, reducing the quantization bit-width to 4 or less will result in fast inference times. Adding more bits will increase FHE inference time exponentially. In some rare cases, the bit-width of the circuit can be higher than the quantization bit-width. This could happen when the quantization bit-width is low but the tree-depth is high. In such cases, the circuit bit-width is upper bounded by `ceil(log2(max_depth + 1) + 1)`. diff --git a/docs/conf.py b/docs/conf.py index c8cc2ed4b..5c4ca01dc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -58,11 +58,8 @@ "Thumbs.db", ".DS_Store", "SUMMARY.md", - "developer-guide/api.md", "advanced_examples/*.ipynb", - "developer-guide/api/*.md", - "developer-guide/workflow/README.md", - "developer-guide/inner-workings/README.md", + "references/api/*.md", "conventions.md", ] diff --git a/docs/deep-learning/examples.md b/docs/deep-learning/examples.md deleted file mode 100644 index 9d6999c9e..000000000 --- a/docs/deep-learning/examples.md +++ /dev/null @@ -1,23 +0,0 @@ -# Deep Learning Examples - -These examples illustrate the basic usage of Concrete ML to build various types of neural networks. They use simple data-sets, focusing on the syntax and usage of Concrete ML. For examples showing how to train high-accuracy models on more complex data-sets, see the [Demos and Tutorials](../getting-started/showcase.md) section. - -## FHE constraints considerations - -The examples listed here make use of [simulation](../advanced-topics/compilation.md#fhe-simulation) to perform evaluation over large test sets. Since FHE execution can be slow, only a few FHE executions can be performed. The [correctness guarantees](../getting-started/concepts.md#cryptography-concepts) of Concrete ML ensure that accuracy measured with simulation is the same as that which will be obtained during FHE execution. - -Some examples constrain accumulators to 7-8 bits, which can be sufficient for simple data-sets. Up to 16-bit accumulators can be used, but this introduces a slowdown of 4-5x compared to 8-bit accumulators. - -## List of Examples - -### 1. Step-by-step guide to building a custom NN - -[  Quantization aware training example](../advanced_examples/QuantizationAwareTraining.ipynb) - -This shows how to use Quantization Aware Training and pruning when starting out from a classical PyTorch network. This example uses a simple data-set and a small NN, which achieves good accuracy with low accumulator size. - -### 2. Custom convolutional NN on the [Digits](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html) data-set - -[   Convolutional Neural Network](../advanced_examples/ConvolutionalNeuralNetwork.ipynb) - -Following the [Step-by-step guide](fhe_friendly_models.md), this notebook implements a Quantization Aware Training convolutional neural network on the MNIST data-set. It uses 3-bit weights and activations, giving a 7-bit accumulator. diff --git a/docs/deep-learning/fhe_assistant.md b/docs/deep-learning/fhe_assistant.md index 12a3111d8..924ab2de6 100644 --- a/docs/deep-learning/fhe_assistant.md +++ b/docs/deep-learning/fhe_assistant.md @@ -1,15 +1,14 @@ -# Debugging Models +# Debugging models -This section provides a set of tools and guidelines to help users build optimized FHE-compatible models. It discusses -FHE simulation, the key-cache functionality that helps speed-up FHE result debugging, and gives a guide to evaluate circuit complexity. +This section provides a set of tools and guidelines to help users build optimized FHE-compatible models. It discusses FHE simulation, the key-cache functionality that helps speed-up FHE result debugging, and gives a guide to evaluate circuit complexity. ## Simulation -The [simulation functionality](../advanced-topics/compilation.md#fhe-simulation) of Concrete ML provides a way to evaluate, using clear data, the results that ML models produce on encrypted data. The simulation includes any probabilistic behavior FHE may induce. The simulation is implemented with [Concrete's simulation](https://docs.zama.ai/concrete/tutorials/simulation). +The [simulation functionality](../explanations/compilation.md#fhe-simulation) of Concrete ML provides a way to evaluate, using clear data, the results that ML models produce on encrypted data. The simulation includes any probabilistic behavior FHE may induce. The simulation is implemented with [Concrete's simulation](https://docs.zama.ai/concrete/tutorials/simulation). The simulation mode can be useful when developing and iterating on an ML model implementation. As FHE non-linear models work with integers up to 16 bits, with a trade-off between the number of bits and the FHE execution speed, the simulation can help to find the optimal model design. -Simulation is much faster than FHE execution. This allows for faster debugging and model optimization. For example, this was used for the red/blue contours in the [Classifier Comparison notebook](../built-in-models/ml_examples.md), as computing in FHE for the whole grid and all the classifiers would take significant time. +Simulation is much faster than FHE execution. This allows for faster debugging and model optimization. For example, this was used for the red/blue contours in the [Classifier Comparison notebook](../tutorials/ml_examples.md), as computing in FHE for the whole grid and all the classifiers would take significant time. The following example shows how to use the simulation mode in Concrete ML. @@ -32,8 +31,7 @@ y_preds_clear = concrete_clf.predict(X, fhe="simulate") ## Caching keys during debugging -It is possible to avoid re-generating the keys of the models you are debugging. This feature is unsafe and -should not be used in production. Here is an example that shows how to enable key-caching: +It is possible to avoid re-generating the keys of the models you are debugging. This feature is unsafe and should not be used in production. Here is an example that shows how to enable key-caching: ```python from sklearn.datasets import fetch_openml, make_circles @@ -116,13 +114,13 @@ Function you are trying to compile cannot be compiled: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this 17-bit value is used as an input to a table lookup ``` -The error `this 17-bit value is used as an input to a table lookup` indicates that the 16-bit limit on the input of the Table Lookup (TLU) operation has been exceeded. To pinpoint the model layer that causes the error, Concrete ML provides the [bitwidth_and_range_report](../developer-guide/api/concrete.ml.quantization.quantized_module.md#method-bitwidth_and_range_report) helper function. First, the model must be compiled so that it can be [simulated](#simulation). +The error `this 17-bit value is used as an input to a table lookup` indicates that the 16-bit limit on the input of the Table Lookup (TLU) operation has been exceeded. To pinpoint the model layer that causes the error, Concrete ML provides the [bitwidth_and_range_report](../references/api/concrete.ml.quantization.quantized_module.md#method-bitwidth_and_range_report) helper function. First, the model must be compiled so that it can be [simulated](fhe_assistant.md#simulation). ### Fixing compilation errors To make this network FHE-compatible one can apply several techniques: -1. use [rounded accumulators](../advanced-topics/advanced_features.md#rounded-activations-and-quantizers) by specifying the `rounding_threshold_bits` parameter. Please evaluate the accuracy of the model using simulation if you use this feature, as it may impact accuracy. Setting a value 2-bit higher than the quantization `n_bits` should be a good start. +1. use [rounded accumulators](../explanations/advanced_features.md#rounded-activations-and-quantizers) by specifying the `rounding_threshold_bits` parameter. Please evaluate the accuracy of the model using simulation if you use this feature, as it may impact accuracy. Setting a value 2-bit higher than the quantization `n_bits` should be a good start. @@ -151,7 +149,7 @@ quantized_numpy_module = compile_torch_model( ) ``` -3. adjust the tolerance for one-off errors using the `p_error` parameter. See [this section for more explanation](../advanced-topics/advanced_features.md#approximate-computations) on this tolerance. +3. adjust the tolerance for one-off errors using the `p_error` parameter. See [this section for more explanation](../explanations/advanced_features.md#approximate-computations) on this tolerance. diff --git a/docs/deep-learning/fhe_friendly_models.md b/docs/deep-learning/fhe_friendly_models.md index 1c7cd5929..5baee76fe 100644 --- a/docs/deep-learning/fhe_friendly_models.md +++ b/docs/deep-learning/fhe_friendly_models.md @@ -1,18 +1,18 @@ -# Step-by-step Guide +# Step-by-step guide This guide provides a complete example of converting a PyTorch neural network into its FHE-friendly, quantized counterpart. It focuses on Quantization Aware Training a simple network on a synthetic data-set. In general, quantization can be carried out in two different ways: either during Quantization Aware Training (QAT) or after the training phase with Post-Training Quantization (PTQ). -Regarding FHE-friendly neural networks, QAT is the best way to reach optimal accuracy under [FHE constraints](../README.md#current-limitations). This technique allows weights and activations to be reduced to very low bit-widths (e.g., 2-3 bits), which, combined with pruning, can keep accumulator bit-widths low. +Regarding FHE-friendly neural networks, QAT is the best way to reach optimal accuracy under [FHE constraints](../getting-started/README.md#current-limitations). This technique allows weights and activations to be reduced to very low bit-widths (e.g., 2-3 bits), which, combined with pruning, can keep accumulator bit-widths low. Concrete ML uses the third-party library [Brevitas](https://github.com/Xilinx/brevitas) to perform QAT for PyTorch NNs, but options exist for other frameworks such as Keras/Tensorflow. -Several [demos and tutorials](../getting-started/showcase.md) that use Brevitas are available in the Concrete ML library, such as the [CIFAR classification tutorial](../../use_case_examples/cifar/cifar_brevitas_finetuning/CifarQuantizationAwareTraining.ipynb). +Several [demos and tutorials](../tutorials/showcase.md) that use Brevitas are available in the Concrete ML library, such as the [CIFAR classification tutorial](../../use_case_examples/cifar/cifar_brevitas_finetuning/CifarQuantizationAwareTraining.ipynb). This guide is based on a [notebook tutorial](../advanced_examples/QuantizationAwareTraining.ipynb), from which some code blocks are documented. -For a more formal description of the usage of Brevitas to build FHE-compatible neural networks, please see the [Brevitas usage reference](../developer-guide/external_libraries.md#brevitas). +For a more formal description of the usage of Brevitas to build FHE-compatible neural networks, please see the [Brevitas usage reference](../explanations/inner-workings/external_libraries.md#brevitas). {% hint style="info" %} For a formal explanation of the mechanisms that enable FHE-compatible neural networks, please see the the following paper. @@ -51,7 +51,7 @@ class SimpleNet(nn.Module): The [notebook tutorial](../advanced_examples/QuantizationAwareTraining.ipynb), example shows how to train a FCNN, similarly to the one above, on a synthetic 2D data-set with a checkerboard grid pattern of 100 x 100 points. The data is split into 9500 training and 500 test samples. -Once trained, this PyTorch network can be imported using the [`compile_torch_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_torch_model) function. This function uses simple PTQ. +Once trained, this PyTorch network can be imported using the [`compile_torch_model`](../references/api/concrete.ml.torch.compile.md#function-compile_torch_model) function. This function uses simple PTQ. The network was trained using different numbers of neurons in the hidden layers, and quantized using 3-bits weights and activations. The mean accumulator size shown below is measured as the mean over 10 runs of the experiment. An accumulator of 6.6 means that 4 times out of 10 the accumulator measured was 6 bits while 6 times it was 7 bits. @@ -69,7 +69,7 @@ Accumulator size is determined by Concrete as being the maximum bit-width encoun ## Quantization Aware Training: -[Quantization Aware Training](../advanced-topics/quantization.md) using [Brevitas](https://github.com/Xilinx/brevitas) is the best way to guarantee a good accuracy for Concrete ML compatible neural networks. +[Quantization Aware Training](../explanations/quantization.md) using [Brevitas](https://github.com/Xilinx/brevitas) is the best way to guarantee a good accuracy for Concrete ML compatible neural networks. Brevitas provides a quantized version of almost all PyTorch layers (`Linear` layer becomes `QuantLinear`, `ReLU` layer becomes `QuantReLU` and so on), plus some extra quantization parameters, such as : @@ -177,7 +177,7 @@ By default, Concrete ML uses symmetric quantization for model weights, with valu In a typical setting, the weights will not all have the maximum or minimum values (e.g., $$-2^{n_{bits}-1}$$). Weights typically have a normal distribution around 0, which is one of the motivating factors for their symmetric quantization. A symmetric distribution and many zero-valued weights are desirable because opposite sign weights can cancel each other out and zero weights do not increase the accumulator size. -This fact can be leveraged to train a network with more neurons, while not overflowing the accumulator, using a technique called [pruning](../advanced-topics/pruning.md) where the developer can impose a number of zero-valued weights. Torch [provides support for pruning](https://pytorch.org/tutorials/intermediate/pruning_tutorial.html) out of the box. +This fact can be leveraged to train a network with more neurons, while not overflowing the accumulator, using a technique called [pruning](../explanations/pruning.md) where the developer can impose a number of zero-valued weights. Torch [provides support for pruning](https://pytorch.org/tutorials/intermediate/pruning_tutorial.html) out of the box. The following code shows how to use pruning in the previous example: diff --git a/docs/deep-learning/optimizing_inference.md b/docs/deep-learning/optimizing_inference.md index 98d030f9a..496ad9937 100644 --- a/docs/deep-learning/optimizing_inference.md +++ b/docs/deep-learning/optimizing_inference.md @@ -1,26 +1,21 @@ -# Optimizing inference latency +# Optimizing inference -Neural networks pose unique challenges with regards to encrypted inference. Each neuron in a network applies an activation function that requires a PBS operation. The latency -of a single PBS depends on the bit-width of the input of the PBS. +Neural networks pose unique challenges with regards to encrypted inference. Each neuron in a network applies an activation function that requires a PBS operation. The latency of a single PBS depends on the bit-width of the input of the PBS. Several approaches can be used to reduce the overall latency of a neural network. ## Circuit bit-width optimization -[Quantization Aware Training](../advanced-topics/quantization.md) and [pruning](../advanced-topics/pruning.md) introduce specific hyper-parameters that influence the accumulator sizes. -It is possible to chose quantization and pruning configurations that reduce the accumulator size. A trade-off between latency and accuracy can be obtained by varying these hyper-parameters as described in the [deep learning design guide](torch_support.md#configuring-quantization-parameters). +[Quantization Aware Training](../explanations/quantization.md) and [pruning](../explanations/pruning.md) introduce specific hyper-parameters that influence the accumulator sizes. It is possible to chose quantization and pruning configurations that reduce the accumulator size. A trade-off between latency and accuracy can be obtained by varying these hyper-parameters as described in the [deep learning design guide](torch_support.md#configuring-quantization-parameters). ## Structured pruning -While un-structured pruning is used to ensure the accumulator bit-width stays low, [structured pruning](https://pytorch.org/docs/stable/generated/torch.nn.utils.prune.ln_structured.html) can eliminate entire neurons from the network. Many neural networks are over-parametrized (since this enables easier training) and some neurons can be removed. Structured pruning, applied to a trained network as a fine-tuning step, can be applied to built-in neural networks using the [prune](../developer-guide/api/concrete.ml.sklearn.base.md#method-prune) helper function as shown in [this example](../advanced_examples/FullyConnectedNeuralNetworkOnMNIST.ipynb). To apply structured pruning to -custom models, it is recommended to use the [torch-pruning](https://github.com/VainF/Torch-Pruning) package. +While un-structured pruning is used to ensure the accumulator bit-width stays low, [structured pruning](https://pytorch.org/docs/stable/generated/torch.nn.utils.prune.ln_structured.html) can eliminate entire neurons from the network. Many neural networks are over-parametrized (since this enables easier training) and some neurons can be removed. Structured pruning, applied to a trained network as a fine-tuning step, can be applied to built-in neural networks using the [prune](../references/api/concrete.ml.sklearn.base.md#method-prune) helper function as shown in [this example](../advanced_examples/FullyConnectedNeuralNetworkOnMNIST.ipynb). To apply structured pruning to custom models, it is recommended to use the [torch-pruning](https://github.com/VainF/Torch-Pruning) package. ## Rounded activations and quantizers -Reducing the bit-width of the inputs to the Table Lookup (TLU) operations is a major source of improvements in the latency. Post-training, -it is possible to leverage some properties of the fused activation and quantization functions expressed in the TLUs to -further reduce the accumulator. This is achieved through the _rounded PBS_ feature as described in the [rounded activations and quantizers reference](../advanced-topics/advanced_features.md#rounded-activations-and-quantizers). Adjusting the rounding amount, relative to the initial accumulator size, can bring large improvements in latency while maintaining accuracy. +Reducing the bit-width of the inputs to the Table Lookup (TLU) operations is a major source of improvements in the latency. Post-training, it is possible to leverage some properties of the fused activation and quantization functions expressed in the TLUs to further reduce the accumulator. This is achieved through the _rounded PBS_ feature as described in the [rounded activations and quantizers reference](../explanations/advanced_features.md#rounded-activations-and-quantizers). Adjusting the rounding amount, relative to the initial accumulator size, can bring large improvements in latency while maintaining accuracy. ## TLU error tolerance adjustment -Finally, the TFHE scheme exposes a TLU error tolerance parameter that has an impact on crypto-system parameters that influence latency. A higher tolerance of TLU off-by-one errors results in faster computations but may reduce accuracy. One can think of the error of obtaining $$T[x]$$ as a Gaussian distribution centered on $$x$$: $$TLU[x]$$ is obtained with probability of `1 - p_error`, while $$T[x-1]$$, $$T[x+1]$$ are obtained with much lower probability, etc. In Deep NNs, these type of errors can be tolerated up to some point. See the [`p_error` documentation for details](../advanced-topics/advanced_features.md#approximate-computations) and more specifically the usage example of [the API for finding the best `p_error`](../advanced-topics/advanced_features.md#searching-for-the-best-error-probability). +Finally, the TFHE scheme exposes a TLU error tolerance parameter that has an impact on crypto-system parameters that influence latency. A higher tolerance of TLU off-by-one errors results in faster computations but may reduce accuracy. One can think of the error of obtaining $$T[x]$$ as a Gaussian distribution centered on $$x$$: $$TLU[x]$$ is obtained with probability of `1 - p_error`, while $$T[x-1]$$, $$T[x+1]$$ are obtained with much lower probability, etc. In Deep NNs, these type of errors can be tolerated up to some point. See the [`p_error` documentation for details](../explanations/advanced_features.md#approximate-computations) and more specifically the usage example of [the API for finding the best `p_error`](../explanations/advanced_features.md#searching-for-the-best-error-probability). diff --git a/docs/deep-learning/torch_support.md b/docs/deep-learning/torch_support.md index ebcae62dd..d63754114 100644 --- a/docs/deep-learning/torch_support.md +++ b/docs/deep-learning/torch_support.md @@ -2,12 +2,12 @@ In addition to the built-in models, Concrete ML supports generic machine learning models implemented with Torch, or [exported as ONNX graphs](onnx_support.md). -As [Quantization Aware Training (QAT)](../advanced-topics/quantization.md) is the most appropriate method of training neural networks that are compatible with [FHE constraints](../getting-started/concepts.md#model-accuracy-considerations-under-fhe-constraints), Concrete ML works with [Brevitas](../developer-guide/external_libraries.md#brevitas), a library providing QAT support for PyTorch. +As [Quantization Aware Training (QAT)](../explanations/quantization.md) is the most appropriate method of training neural networks that are compatible with [FHE constraints](../getting-started/concepts.md#model-accuracy-considerations-under-fhe-constraints), Concrete ML works with [Brevitas](../explanations/inner-workings/external_libraries.md#brevitas), a library providing QAT support for PyTorch. The following example uses a simple QAT PyTorch model that implements a fully connected neural network with two hidden layers. Due to its small size, making this model respect FHE constraints is relatively easy. {% hint style="info" %} -Converting neural networks to use FHE can be done with `compile_brevitas_qat_model` or with `compile_torch_model` for post-training quantization. If the model can not be converted to FHE two types of errors can be raised: (1) crypto-parameters can not be found and, (2) table look-up bit-width limit is exceeded. See the [debugging section](./fhe_assistant.md#compilation-error-debugging) if you encounter these errors. +Converting neural networks to use FHE can be done with `compile_brevitas_qat_model` or with `compile_torch_model` for post-training quantization. If the model can not be converted to FHE two types of errors can be raised: (1) crypto-parameters can not be found and, (2) table look-up bit-width limit is exceeded. See the [debugging section](fhe_assistant.md#compilation-error-debugging) if you encounter these errors. {% endhint %} ```python @@ -38,8 +38,7 @@ class QATSimpleNet(nn.Module): ``` -Once the model is trained, calling the [`compile_brevitas_qat_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_brevitas_qat_model) from Concrete ML will automatically perform conversion and compilation of a QAT network. Here, 3-bit quantization is used for both the weights and activations. The `compile_brevitas_qat_model` function automatically -identifies the number of quantization bits used in the Brevitas model. +Once the model is trained, calling the [`compile_brevitas_qat_model`](../references/api/concrete.ml.torch.compile.md#function-compile_brevitas_qat_model) from Concrete ML will automatically perform conversion and compilation of a QAT network. Here, 3-bit quantization is used for both the weights and activations. The `compile_brevitas_qat_model` function automatically identifies the number of quantization bits used in the Brevitas model. @@ -58,14 +57,9 @@ quantized_module = compile_brevitas_qat_model( ## Configuring quantization parameters -The PyTorch/Brevitas models, created following the example above, require the user to configure -quantization parameters such as `bit_width` (activation bit-width) and `weight_bit_width`. The -quantization parameters, along with the number of neurons on each layer, will determine the -accumulator bit-width of the network. Larger accumulator bit-widths result in higher accuracy -but slower FHE inference time. +The PyTorch/Brevitas models, created following the example above, require the user to configure quantization parameters such as `bit_width` (activation bit-width) and `weight_bit_width`. The quantization parameters, along with the number of neurons on each layer, will determine the accumulator bit-width of the network. Larger accumulator bit-widths result in higher accuracy but slower FHE inference time. -The following configurations were determined through experimentation for convolutional and -dense layers. +The following configurations were determined through experimentation for convolutional and dense layers. | target accumulator bit-width | activation bit-width | weight bit-width | number of active neurons | | ---------------------------- | -------------------- | ---------------- | ------------------------ | @@ -75,23 +69,20 @@ dense layers. | 14 | 6 | 6 | 110 | | 16 | 7 | 6 | 120 | -Using the templates above, the probability of obtaining the target accumulator -bit-width, for a single layer, was determined experimentally by training 10 models for each of -the following data-sets. +Using the templates above, the probability of obtaining the target accumulator bit-width, for a single layer, was determined experimentally by training 10 models for each of the following data-sets. -| probability of obtaining
the accumulator bit-width | 8 | 10 | 12 | 14 | 16 | -| ------------------------------------------------------ | --- | ---- | --- | --- | ---- | -| mnist,fashion | 72% | 100% | 72% | 85% | 100% | -| cifar10 | 88% | 88% | 75% | 75% | 88% | -| cifar100 | 73% | 88% | 61% | 66% | 100% | +|

probability of obtaining
the accumulator bit-width

| 8 | 10 | 12 | 14 | 16 | +| ------------------------------------------------------------ | --- | ---- | --- | --- | ---- | +| mnist,fashion | 72% | 100% | 72% | 85% | 100% | +| cifar10 | 88% | 88% | 75% | 75% | 88% | +| cifar100 | 73% | 88% | 61% | 66% | 100% | -Note that the accuracy on larger data-sets, when the accumulator size is low, is also reduced -strongly. +Note that the accuracy on larger data-sets, when the accumulator size is low, is also reduced strongly. -| accuracy for target
accumulator bit-width | 8 | 10 | 12 | 14 | 16 | -| ---------------------------------------------- | --- | --- | --- | --- | --- | -| cifar10 | 20% | 37% | 89% | 90% | 90% | -| cifar100 | 6% | 30% | 67% | 69% | 69% | +|

accuracy for target
accumulator bit-width

| 8 | 10 | 12 | 14 | 16 | +| --------------------------------------------------- | --- | --- | --- | --- | --- | +| cifar10 | 20% | 37% | 89% | 90% | 90% | +| cifar100 | 6% | 30% | 67% | 69% | 69% | ## Running encrypted inference @@ -105,20 +96,18 @@ x_test = numpy.array([numpy.random.randn(N_FEAT)]) y_pred = quantized_module.forward(x_test, fhe="execute") ``` -In this example, the input values `x_test` and the predicted values `y_pred` are floating points. -The quantization (resp. de-quantization) step is done in the clear within the `forward` method, before (resp. after) any FHE computations. +In this example, the input values `x_test` and the predicted values `y_pred` are floating points. The quantization (resp. de-quantization) step is done in the clear within the `forward` method, before (resp. after) any FHE computations. ## Simulated FHE Inference in the clear The user can also perform the inference on clear data. Two approaches exist: - `quantized_module.forward(quantized_x, fhe="simulate")`: simulates FHE execution taking into account Table Lookup errors.\ - De-quantization must be done in a second step as for actual FHE execution. Simulation takes into - account the `p_error`/`global_p_error` parameters + De-quantization must be done in a second step as for actual FHE execution. Simulation takes into account the `p_error`/`global_p_error` parameters - `quantized_module.forward(quantized_x, fhe="disable")`: computes predictions in the clear on quantized data, and then de-quantize the result. The return value of this function contains the de-quantized (float) output of running the model in the clear. Calling this function on clear data is useful when debugging, but this does not perform actual FHE simulation. {% hint style="info" %} -FHE simulation allows to measure the impact of the Table Lookup error on the model accuracy. The Table Lookup error can be adjusted using `p_error`/`global_p_error`, as described in the [approximate computation ](../advanced-topics/advanced_features.md#approximate-computations)section. +FHE simulation allows to measure the impact of the Table Lookup error on the model accuracy. The Table Lookup error can be adjusted using `p_error`/`global_p_error`, as described in the [approximate computation ](../explanations/advanced_features.md#approximate-computations)section. {% endhint %} ## Generic Quantization Aware Training import @@ -127,7 +116,7 @@ While the example above shows how to import a Brevitas/PyTorch model, Concrete M QAT models contain quantizers in the PyTorch graph. These quantizers ensure that the inputs to the Linear/Dense and Conv layers are quantized. -Suppose that `n_bits_qat` is the bit-width of activations and weights during the QAT process. To import a PyTorch QAT network, you can use the [`compile_torch_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_torch_model) library function, passing `import_qat=True`: +Suppose that `n_bits_qat` is the bit-width of activations and weights during the QAT process. To import a PyTorch QAT network, you can use the [`compile_torch_model`](../references/api/concrete.ml.torch.compile.md#function-compile_torch_model) library function, passing `import_qat=True`: @@ -143,7 +132,7 @@ quantized_module = compile_torch_model( ) ``` -Alternatively, if you want to import an ONNX model directly, please see [the ONNX guide](onnx_support.md). The [`compile_onnx_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_onnx_model) also supports the `import_qat` parameter. +Alternatively, if you want to import an ONNX model directly, please see [the ONNX guide](onnx_support.md). The [`compile_onnx_model`](../references/api/concrete.ml.torch.compile.md#function-compile_onnx_model) also supports the `import_qat` parameter. {% hint style="warning" %} When importing QAT models using this generic pipeline, a representative calibration set should be given as quantization parameters in the model need to be inferred from the statistics of the values encountered during inference. diff --git a/docs/developer-guide/inner-workings/README.md b/docs/developer-guide/inner-workings/README.md deleted file mode 100644 index 9b5114266..000000000 --- a/docs/developer-guide/inner-workings/README.md +++ /dev/null @@ -1 +0,0 @@ -# Inner Workings diff --git a/docs/developer-guide/workflow/README.md b/docs/developer-guide/workflow/README.md deleted file mode 100644 index dd049b139..000000000 --- a/docs/developer-guide/workflow/README.md +++ /dev/null @@ -1 +0,0 @@ -# Workflow diff --git a/docs/developer-guide/contributing.md b/docs/developer/contributing.md similarity index 100% rename from docs/developer-guide/contributing.md rename to docs/developer/contributing.md diff --git a/docs/developer-guide/debug_support_submit_issues.md b/docs/developer/debug_support_submit_issues.md similarity index 100% rename from docs/developer-guide/debug_support_submit_issues.md rename to docs/developer/debug_support_submit_issues.md diff --git a/docs/developer-guide/docker_setup.md b/docs/developer/docker_setup.md similarity index 100% rename from docs/developer-guide/docker_setup.md rename to docs/developer/docker_setup.md diff --git a/docs/developer-guide/documenting.md b/docs/developer/documenting.md similarity index 100% rename from docs/developer-guide/documenting.md rename to docs/developer/documenting.md diff --git a/docs/developer-guide/project_setup.md b/docs/developer/project_setup.md similarity index 98% rename from docs/developer-guide/project_setup.md rename to docs/developer/project_setup.md index e2d5d5aac..4bbfaa4d6 100644 --- a/docs/developer-guide/project_setup.md +++ b/docs/developer/project_setup.md @@ -1,15 +1,15 @@ -# Set Up the Project +# Set up the project Concrete ML is a `Python` library, so `Python` should be installed to develop Concrete ML. `v3.8` and `v3.9` are the only supported versions. Concrete ML also uses `Poetry` and `Make`. First of all, you need to `git clone` the project: - + @@ -19,8 +19,6 @@ git clone https://github.com/zama-ai/concrete-ml Several files are tracked by [git-lfs](https://git-lfs.github.com/). While a few are required for running some tests, most of them are used for benchmarking and use case examples. By default, `git clone` downloads all LFS files, which can add up to several hundreds of MB to the directory. Is it however possible to disable such behavior by running the running the following command instead : - - ```bash @@ -168,7 +166,7 @@ rm -rf .venv make setup_env ``` -At this point, you should consider using Docker as nobody will have the exact same setup as you. If, however, you need to develop on your OS directly, you can [ask Zama for help](../README.md#support). +At this point, you should consider using Docker as nobody will have the exact same setup as you. If, however, you need to develop on your OS directly, you can [ask Zama for help](../README.md#supports). #### in Docker diff --git a/docs/advanced-topics/advanced_features.md b/docs/explanations/advanced_features.md similarity index 99% rename from docs/advanced-topics/advanced_features.md rename to docs/explanations/advanced_features.md index d30180a9b..e0963ea0c 100644 --- a/docs/advanced-topics/advanced_features.md +++ b/docs/explanations/advanced_features.md @@ -1,4 +1,4 @@ -# Advanced Features +# Advanced features Concrete ML provides features for advanced users to adjust cryptographic parameters generated by the Concrete stack. This allows users to identify the best trade-off between latency and performance for their specific machine learning models. @@ -26,7 +26,7 @@ In Concrete ML, there are three different ways to define the tolerance to off-by The first way to set error probabilities in Concrete ML is at the local level, by directly setting the tolerance to error of each individual TLU operation (such as activation functions for a neuron output). This tolerance is referred to as `p_error`. A given PBS operation has a `1 - p_error` chance of being correct 100% of the time. The successful evaluation here means that the value decrypted after FHE evaluation is exactly the same as the one that would be computed in the clear. Otherwise, off-by-one errors might occur, but, in practice, these errors are not necessarily problematic if they are sufficiently rare. -For simplicity, it is best to use [default options](advanced_features.md#using-default-error-probability), irrespective of the type of model. Especially for deep neural networks, default values may be too pessimistic, reducing computation speed without any improvement in accuracy. For deep neural networks, some TLU errors might not affect the accuracy of the network, so `p_error` can be safely increased (e.g., see CIFAR classifications in [our showcase](../getting-started/showcase.md)). +For simplicity, it is best to use [default options](advanced_features.md#using-default-error-probability), irrespective of the type of model. Especially for deep neural networks, default values may be too pessimistic, reducing computation speed without any improvement in accuracy. For deep neural networks, some TLU errors might not affect the accuracy of the network, so `p_error` can be safely increased (e.g., see CIFAR classifications in [our showcase](../tutorials/showcase.md)). Here is a visualization of the effect of the `p_error` on a neural network model with a `p_error = 0.1` compared to execution in the clear (i.e., no error): @@ -162,7 +162,7 @@ $$t = L - P$$ Then, the rounding operation can be computed as: -$$ \mathrm{round\_to\_P\_bits}(x, t) = \left\lfloor \frac{x}{2^t} \right\rceil \cdot 2^t $$ +$$\mathrm{round\_to\_P\_bits}(x, t) = \left\lfloor \frac{x}{2^t} \right\rceil \cdot 2^t$$ where $$x$$ is the input number, and $$\lfloor \cdot \rceil$$ denotes the operation that rounds to the nearest integer. diff --git a/docs/advanced-topics/compilation.md b/docs/explanations/compilation.md similarity index 91% rename from docs/advanced-topics/compilation.md rename to docs/explanations/compilation.md index 298cfafcb..261f5bd05 100644 --- a/docs/advanced-topics/compilation.md +++ b/docs/explanations/compilation.md @@ -14,13 +14,13 @@ From the perspective of the Concrete ML user, the compilation process performed 1. checking the op-graph for FHE compatability 1. producing machine code for the op-graph (this step automatically determines cryptographic parameters) -Additionally, the [client/server API](client_server.md) packages the result of the last step in a way that allows the deployment of the encrypted circuit to a server, as well as key generation, encryption, and decryption on the client side. +Additionally, the [client/server API](../guides/client_server.md) packages the result of the last step in a way that allows the deployment of the encrypted circuit to a server, as well as key generation, encryption, and decryption on the client side. ### Built-in models Compilation is performed for built-in models with the `compile` method : - + ```python clf.compile(X_train) @@ -28,8 +28,7 @@ Compilation is performed for built-in models with the `compile` method : ### scikit-learn pipelines -When using a pipeline, the Concrete ML model can predict with FHE during the pipeline execution, but it needs -to be compiled beforehand. The compile function must be called on the Concrete ML model: +When using a pipeline, the Concrete ML model can predict with FHE during the pipeline execution, but it needs to be compiled beforehand. The compile function must be called on the Concrete ML model: ```python import numpy @@ -71,7 +70,7 @@ model_pca.predict(X_test[[0]], fhe="execute") For custom models, with one of the `compile_brevitas_qat_model` (for Brevitas models with Quantization Aware Training) or `compile_torch_model` (PyTorch models using Post-Training Quantization) functions: - + ```python quantized_numpy_module = compile_brevitas_qat_model(torch_model, X_train) @@ -88,7 +87,7 @@ The result of this single step of the compilation pipeline allows the: Simulation is enabled for all Concrete ML models once they are compiled as shown above. Obtaining the simulated predictions of the models is done by setting the `fhe="simulate"` argument to prediction methods: - + ```python Z = clf.predict_proba(X, fhe="simulate") @@ -96,7 +95,7 @@ Simulation is enabled for all Concrete ML models once they are compiled as shown Moreover, the maximum accumulator bit-width is determined as follows: - + ```python bit_width = clf.quantized_module_.fhe_circuit.graph.maximum_integer_bit_width() diff --git a/docs/explanations/inner-workings/README.md b/docs/explanations/inner-workings/README.md new file mode 100644 index 000000000..ec1fb4694 --- /dev/null +++ b/docs/explanations/inner-workings/README.md @@ -0,0 +1,3 @@ +# Project architecture + +
Importing ONNXonnx_pipeline.md
Quantization toolsquantization_internal.md
FHE op-graph designfhe-op-graphs.md
External librariesexternal_libraries.md
diff --git a/docs/developer-guide/external_libraries.md b/docs/explanations/inner-workings/external_libraries.md similarity index 85% rename from docs/developer-guide/external_libraries.md rename to docs/explanations/inner-workings/external_libraries.md index 28918e9aa..7e0da2b2c 100644 --- a/docs/developer-guide/external_libraries.md +++ b/docs/explanations/inner-workings/external_libraries.md @@ -1,4 +1,4 @@ -# External Libraries +# External libraries ## Hummingbird @@ -48,9 +48,9 @@ Concrete ML uses [skorch](https://skorch.readthedocs.io/en/stable/) to implement This wrapper implements Torch training boilerplate code, lessening the work required of the user. It is possible to add hooks during the training phase, for example once an epoch is finished. -skorch allows the user to easily create a classifier or regressor around a neural network (NN), implemented in Torch as a `nn.Module`, which is used by Concrete ML to provide a fully-connected, multi-layer NN with a configurable number of layers and optional pruning (see [pruning](../advanced-topics/pruning.md) and the [neural network documentation](../built-in-models/neural-networks.md) for more information). +skorch allows the user to easily create a classifier or regressor around a neural network (NN), implemented in Torch as a `nn.Module`, which is used by Concrete ML to provide a fully-connected, multi-layer NN with a configurable number of layers and optional pruning (see [pruning](../pruning.md) and the [neural network documentation](../../built-in-models/neural-networks.md) for more information). -Under the hood, Concrete ML uses a skorch wrapper around a single PyTorch module, `SparseQuantNeuralNetwork`. More information can be found [in the API guide](./api/concrete.ml.sklearn.qnn_module.md#class-sparsequantneuralnetwork). +Under the hood, Concrete ML uses a skorch wrapper around a single PyTorch module, `SparseQuantNeuralNetwork`. More information can be found [in the API guide](../../references/api/concrete.ml.sklearn.qnn_module.md#class-sparsequantneuralnetwork). ``` class SparseQuantNeuralNetImpl(nn.Module): @@ -64,7 +64,7 @@ class SparseQuantNeuralNetImpl(nn.Module): While Brevitas provides many types of quantization, for Concrete ML, a custom _"mixed integer"_ quantization applies. This _"mixed integer"_ quantization is much simpler than the _"integer only"_ mode of Brevitas. The _"mixed integer"_ network design is defined as: - all weights and activations of convolutional, linear and pooling layers must be quantized (e.g., using Brevitas layers, `QuantConv2D`, `QuantAvgPool2D`, `QuantLinear`) -- PyTorch floating-point versions of univariate functions can be used (e.g., `torch.relu`, `nn.BatchNormalization2D`, `torch.max` (encrypted vs. constant), `torch.add`, `torch.exp`). See the [PyTorch supported layers page](../deep-learning/torch_support.md) for a full list. +- PyTorch floating-point versions of univariate functions can be used (e.g., `torch.relu`, `nn.BatchNormalization2D`, `torch.max` (encrypted vs. constant), `torch.add`, `torch.exp`). See the [PyTorch supported layers page](../../deep-learning/torch_support.md) for a full list. The _"mixed integer"_ mode used in Concrete ML neural networks is based on the [_"integer only"_ Brevitas quantization](https://github.com/Xilinx/brevitas#low-precision-integer-only-lenet) that makes both weights and activations representable as integers during training. However, through the use of lookup tables in Concrete ML, floating point univariate PyTorch functions are supported. @@ -88,7 +88,7 @@ class QATnetwork(nn.Module): For examples of such a _"mixed integer"_ network design, please see the Quantization Aware Training examples: -- [QuantizationAwareTraining.ipynb](../../docs/advanced_examples/QuantizationAwareTraining.ipynb) -- [ConvolutionalNeuralNetwork.ipynb](../../docs/advanced_examples/ConvolutionalNeuralNetwork.ipynb) +- [QuantizationAwareTraining.ipynb](../../advanced_examples/QuantizationAwareTraining.ipynb) +- [ConvolutionalNeuralNetwork.ipynb](../../advanced_examples/ConvolutionalNeuralNetwork.ipynb) -You can also refer to the [`SparseQuantNeuralNetImpl`](./api/concrete.ml.sklearn.qnn_module.md#class-sparsequantneuralnetwork) class, which is the basis of the built-in `NeuralNetworkClassifier`. +You can also refer to the [`SparseQuantNeuralNetImpl`](../../references/api/concrete.ml.sklearn.qnn_module.md#class-sparsequantneuralnetwork) class, which is the basis of the built-in `NeuralNetworkClassifier`. diff --git a/docs/developer-guide/fhe-op-graphs.md b/docs/explanations/inner-workings/fhe-op-graphs.md similarity index 97% rename from docs/developer-guide/fhe-op-graphs.md rename to docs/explanations/inner-workings/fhe-op-graphs.md index 22c511431..a83bf1e46 100644 --- a/docs/developer-guide/fhe-op-graphs.md +++ b/docs/explanations/inner-workings/fhe-op-graphs.md @@ -1,4 +1,4 @@ -# FHE Op-graph Design +# FHE Op-graph design The [ONNX import](onnx_pipeline.md) section gave an overview of the conversion of a generic ONNX graph to an FHE-compatible Concrete ML op-graph. This section describes the implementation of operations in the Concrete ML op-graph and the way floating point can be used in some parts of the op-graphs through table lookup operations. @@ -9,13 +9,13 @@ Concrete, the underlying implementation of TFHE that powers Concrete ML, enables 1. **arithmetic operations**: the addition of two encrypted values and multiplication of encrypted values with clear scalars. These are used, for example, in dot-products, matrix multiplication (linear layers), and convolution. 1. **table lookup operations (TLU)**: using an encrypted value as an index, return the value of a lookup table at that index. This is implemented using Programmable Bootstrapping. This operation is used to perform any non-linear computation such as activation functions, quantization, and normalization. -Since machine learning models use floating point inputs and weights, they first need to be converted to integers using [quantization](../advanced-topics/quantization.md). +Since machine learning models use floating point inputs and weights, they first need to be converted to integers using [quantization](../quantization.md). Alternatively, it is possible to use a table lookup to avoid the quantization of the entire graph, by converting floating-point ONNX subgraphs into lambdas and computing their corresponding lookup tables to be evaluated directly in FHE. This operator-fusion technique only requires the input and output of the lambdas to be integers. For example, in the following graph there is a single input, which must be an encrypted integer tensor. The following series of univariate functions is then fed into a matrix multiplication (MatMul) and fused into a single table lookup with integer inputs and outputs. -![](../.gitbook/assets/image_3.png) +![](../../.gitbook/assets/image_3.png) ## ONNX operations @@ -30,7 +30,7 @@ Thus, `QuantizedOp` instances may need to quantize their inputs or the result of The `QuantizedOp` class provides a generic implementation of an ONNX operation, including the quantization of inputs and outputs, with the computation implemented in NumPy in `ops_impl.py`. It is possible to picture the architecture of the `QuantizedOp` as the following structure: -![](../.gitbook/assets/image_4.png) +![](../../.gitbook/assets/image_4.png) This figure shows that the `QuantizedOp` has a body that implements the computation of the operation, following the [ONNX spec](https://github.com/onnx/onnx/blob/main/docs/Operators.md). The operation's body can take either integer or float inputs and can output float or integer values. Two quantizers are attached to the operation: one that takes float inputs and produces integer inputs and one that does the same for the output. @@ -38,7 +38,7 @@ This figure shows that the `QuantizedOp` has a body that implements the computat Depending on the position of the op in the graph and its inputs, the `QuantizedOp` can be fully fused to a TLU. -![](../.gitbook/assets/image_8.png) +![](../../.gitbook/assets/image_8.png) Many ONNX ops are trivially univariate, as they multiply variable inputs with constants or apply univariate functions such as ReLU, Sigmoid, etc. This includes operations between the input and the MatMul in the graph above (subtraction, comparison, multiplication, etc. between inputs and constants). @@ -46,15 +46,15 @@ Many ONNX ops are trivially univariate, as they multiply variable inputs with co Operations, such as matrix multiplication of encrypted inputs with a constant matrix or convolution with constant weights, require that the encrypted inputs be integers. In this case, the input quantizer of the `QuantizedOp` is applied. These types of operations are implemented with a class that derives from `QuantizedOp` and implements `q_impl`, such as `QuantizedGemm` and `QuantizedConv`. -![](../.gitbook/assets/image_5.png) +![](../../.gitbook/assets/image_5.png) ### Operations that produce graph outputs Finally, some operations produce graph outputs, which must be integers. These operations need to quantize their outputs as follows: -![](../.gitbook/assets/image_1.png) +![](../../.gitbook/assets/image_1.png) -![](../.gitbook/assets/image_9.png) +![](../../.gitbook/assets/image_9.png) The diagram above shows that both float ops and integer ops need to quantize their outputs to integers when placed at the end of the graph. @@ -62,7 +62,7 @@ The diagram above shows that both float ops and integer ops need to quantize the To chain the operation types described above following the ONNX graph, Concrete ML constructs a function that calls the `q_impl` of the `QuantizedOp` instances in the graph in sequence, and uses Concrete to trace the execution and compile to FHE. Thus, in this chain of function calls, all groups of that instruction that operate in floating point will be fused to TLUs. In FHE, this lookup table is computed with a PBS. -![](../.gitbook/assets/image_6.png) +![](../../.gitbook/assets/image_6.png) The red contours show the groups of elementary Concrete instructions that will be converted to TLUs. diff --git a/docs/developer-guide/onnx_pipeline.md b/docs/explanations/inner-workings/onnx_pipeline.md similarity index 79% rename from docs/developer-guide/onnx_pipeline.md rename to docs/explanations/inner-workings/onnx_pipeline.md index 91fb21076..58a65d66a 100644 --- a/docs/developer-guide/onnx_pipeline.md +++ b/docs/explanations/inner-workings/onnx_pipeline.md @@ -14,17 +14,17 @@ All Concrete ML built-in models follow the same pattern for FHE conversion: 1. All models have a PyTorch implementation for inference. This implementation is provided either by a third-party tool such as [Hummingbird](external_libraries.md#hummingbird) or implemented directly in Concrete ML. 1. The PyTorch model is exported to ONNX. For more information on the use of ONNX in Concrete ML, see [here](onnx_pipeline.md#torch-to-numpy-conversion-using-onnx). 1. The Concrete ML ONNX parser checks that all the operations in the ONNX graph are supported and assigns reference NumPy operations to them. This step produces a `NumpyModule`. -1. Quantization is performed on the [`NumpyModule`](./api/concrete.ml.torch.numpy_module.md#class-numpymodule), producing a [`QuantizedModule`](./api/concrete.ml.quantization.quantized_module.md#class-quantizedmodule). Two steps are performed: calibration and assignment of equivalent [`QuantizedOp`](./api/concrete.ml.quantization.base_quantized_op.md#class-quantizedop) objects to each ONNX operation. The `QuantizedModule` class is the quantized counterpart of the `NumpyModule`. +1. Quantization is performed on the [`NumpyModule`](../../references/api/concrete.ml.torch.numpy_module.md#class-numpymodule), producing a [`QuantizedModule`](../../references/api/concrete.ml.quantization.quantized_module.md#class-quantizedmodule). Two steps are performed: calibration and assignment of equivalent [`QuantizedOp`](../../references/api/concrete.ml.quantization.base_quantized_op.md#class-quantizedop) objects to each ONNX operation. The `QuantizedModule` class is the quantized counterpart of the `NumpyModule`. 1. Once the `QuantizedModule` is built, Concrete is used to trace the `._forward()` function of the `QuantizedModule`. -Moreover, by passing a user provided `nn.Module` to step 2 of the above process, Concrete ML supports custom user models. See the associated [FHE-friendly model documentation](../deep-learning/fhe_friendly_models.md) for instructions about working with such models. +Moreover, by passing a user provided `nn.Module` to step 2 of the above process, Concrete ML supports custom user models. See the associated [FHE-friendly model documentation](../../deep-learning/fhe_friendly_models.md) for instructions about working with such models. -![Torch compilation flow with ONNX](../.gitbook/assets/torch_to_numpy_with_onnx.svg) +![Torch compilation flow with ONNX](../../.gitbook/assets/torch_to_numpy_with_onnx.svg) Once an ONNX model is imported, it is converted to a `NumpyModule`, then to a `QuantizedModule` and, finally, to an FHE circuit. However, as the diagram shows, it is perfectly possible to stop at the `NumpyModule` level if you just want to run the PyTorch model as NumPy code without doing quantization. {% hint style="info" %} -Note that the `NumpyModule` interpreter currently [supports the following ONNX operators](../deep-learning/onnx_support.md#supported-operators). +Note that the `NumpyModule` interpreter currently [supports the following ONNX operators](../../deep-learning/onnx_support.md#supported-operators). {% endhint %} ## Inspecting the ONNX models diff --git a/docs/developer-guide/quantization_internal.md b/docs/explanations/inner-workings/quantization_internal.md similarity index 93% rename from docs/developer-guide/quantization_internal.md rename to docs/explanations/inner-workings/quantization_internal.md index 370e87d6c..69fac2c29 100644 --- a/docs/developer-guide/quantization_internal.md +++ b/docs/explanations/inner-workings/quantization_internal.md @@ -1,17 +1,17 @@ -# Quantization Tools +# Quantization tools ## Quantizing data Concrete ML has support for quantized ML models and also provides quantization tools for Quantization Aware Training and Post-Training Quantization. The core of this functionality is the conversion of floating point values to integers and back. This is done using `QuantizedArray` in `concrete.ml.quantization`. -The [`QuantizedArray`](./api/concrete.ml.quantization.quantizers.md#class-quantizedarray) class takes several arguments that determine how float values are quantized: +The [`QuantizedArray`](../../references/api/concrete.ml.quantization.quantizers.md#class-quantizedarray) class takes several arguments that determine how float values are quantized: - `n_bits` defines the precision used in quantization - `values` are floating point values that will be converted to integers - `is_signed` determines if the quantized integer values should allow negative values - `is_symmetric` determines if the range of floating point values to be quantized should be taken as symmetric around zero -See also the [UniformQuantizer](./api/concrete.ml.quantization.quantizers.md#class-uniformquantizer) reference for more information: +See also the [UniformQuantizer](../../references/api/concrete.ml.quantization.quantizers.md#class-uniformquantizer) reference for more information: ```python from concrete.ml.quantization import QuantizedArray @@ -92,7 +92,7 @@ Calibration is the process of determining the typical distributions of values en To perform calibration, an interpreter goes through the ONNX graph in [topological order](https://en.wikipedia.org/wiki/Topological_sorting) and stores the intermediate results as it goes. The statistics of these values determine quantization parameters. {% endhint %} -That `QuantizedModule` generates the Concrete function that is compiled to FHE. The compilation will succeed if the intermediate values conform to the 16-bits precision limit of the Concrete stack. See [the compilation section](../advanced-topics/compilation.md) for details. +That `QuantizedModule` generates the Concrete function that is compiled to FHE. The compilation will succeed if the intermediate values conform to the 16-bits precision limit of the Concrete stack. See [the compilation section](../compilation.md) for details. ## Resources diff --git a/docs/advanced-topics/pruning.md b/docs/explanations/pruning.md similarity index 97% rename from docs/advanced-topics/pruning.md rename to docs/explanations/pruning.md index 45fdc990d..33989917b 100644 --- a/docs/advanced-topics/pruning.md +++ b/docs/explanations/pruning.md @@ -33,7 +33,7 @@ Fixing some of the weights to 0 makes the network graph look more similar to the ![Pruned Fully Connected Neural Network](../figures/prunednet.png) -While pruning weights can reduce the prediction performance of the neural network, studies show that a high level of pruning (above 50%) can often be applied. See here how Concrete ML uses pruning in [Fully Connected Neural Networks](../developer-guide/api/concrete.ml.sklearn.qnn.md#class-neuralnetclassifier). +While pruning weights can reduce the prediction performance of the neural network, studies show that a high level of pruning (above 50%) can often be applied. See here how Concrete ML uses pruning in [Fully Connected Neural Networks](../references/api/concrete.ml.sklearn.qnn.md#class-neuralnetclassifier). ## Pruning in practice diff --git a/docs/advanced-topics/quantization.md b/docs/explanations/quantization.md similarity index 98% rename from docs/advanced-topics/quantization.md rename to docs/explanations/quantization.md index 66f549ec9..c9866ddc4 100644 --- a/docs/advanced-topics/quantization.md +++ b/docs/explanations/quantization.md @@ -63,7 +63,7 @@ For built-in **neural networks**, the maximum accumulator bit-width cannot be pr The models implemented in Concrete ML provide features to let the user quantize the input data and de-quantize the output data. -In a client/server setting, the client is responsible for quantizing inputs before sending them, encrypted, to the server. The client must then de-quantize the encrypted integer results received from the server. See the [Production Deployment](client_server.md) section for more details. +In a client/server setting, the client is responsible for quantizing inputs before sending them, encrypted, to the server. The client must then de-quantize the encrypted integer results received from the server. See the [Production Deployment](../guides/client_server.md) section for more details. Here is a simple example showing how to perform inference, starting from float values and ending up with float values. The FHE engine that is compiled for ML models does not support data batching. diff --git a/docs/getting-started/README.md b/docs/getting-started/README.md new file mode 100644 index 000000000..5202c2dc7 --- /dev/null +++ b/docs/getting-started/README.md @@ -0,0 +1,114 @@ +# What is Concrete ML? + +
+ +Concrete ML is an open source, privacy-preserving, machine learning framework based on Fully Homomorphic Encryption (FHE). It enables data scientists without any prior knowledge of cryptography to automatically turn machine learning models into their FHE equivalent, using familiar APIs from scikit-learn and PyTorch (see how it looks for [linear models](../built-in-models/linear.md), [tree-based models](../built-in-models/tree.md), and [neural networks](../built-in-models/neural-networks.md)). Concrete ML supports converting models for inference with FHE but can also [train some models](../built-in-models/training.md) on encrypted data. + +Fully Homomorphic Encryption is an encryption technique that allows computing directly on encrypted data, without needing to decrypt it. With FHE, you can build private-by-design applications without compromising on features. You can learn more about FHE in [this introduction](https://www.zama.ai/post/tfhe-deep-dive-part-1) or by joining the [FHE.org](https://fhe.org) community. + +Training on encrypted data provides the highest level of privacy but is slower than training on clear data. Federated learning is an alternative approach, where data privacy can be ensured by using a trusted gradient aggregator, coupled with optional _differential privacy_ instead of encryption. Concrete ML can import linear models, including logistic regression, that are trained using federated learning using the [`from_sklearn` function](../built-in-models/linear.md#pre-trained-models). + +## Example usage + +Here is a simple example of classification on encrypted data using logistic regression. More examples can be found [here](../tutorials/ml_examples.md). + +```python +from sklearn.datasets import make_classification +from sklearn.model_selection import train_test_split +from concrete.ml.sklearn import LogisticRegression + +# Lets create a synthetic data-set +x, y = make_classification(n_samples=100, class_sep=2, n_features=30, random_state=42) + +# Split the data-set into a train and test set +X_train, X_test, y_train, y_test = train_test_split( + x, y, test_size=0.2, random_state=42 +) + +# Now we train in the clear and quantize the weights +model = LogisticRegression(n_bits=8) +model.fit(X_train, y_train) + +# We can simulate the predictions in the clear +y_pred_clear = model.predict(X_test) + +# We then compile on a representative set +model.compile(X_train) + +# Finally we run the inference on encrypted inputs +y_pred_fhe = model.predict(X_test, fhe="execute") + +print(f"In clear : {y_pred_clear}") +print(f"In FHE : {y_pred_fhe}") +print(f"Similarity: {(y_pred_fhe == y_pred_clear).mean():.1%}") + +# Output: + # In clear : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0] + # In FHE : [0 0 0 0 1 0 1 0 1 1 0 0 1 0 0 1 1 1 0 0] + # Similarity: 100.0% +``` + +It is also possible to call encryption, model prediction, and decryption functions separately as follows. Executing these steps separately is equivalent to calling `predict_proba` on the model instance. + + + +```python +# Predict probability for a single example +y_proba_fhe = model.predict_proba(X_test[[0]], fhe="execute") + +# Quantize an original float input +q_input = model.quantize_input(X_test[[0]]) + +# Encrypt the input +q_input_enc = model.fhe_circuit.encrypt(q_input) + +# Execute the linear product in FHE +q_y_enc = model.fhe_circuit.run(q_input_enc) + +# Decrypt the result (integer) +q_y = model.fhe_circuit.decrypt(q_y_enc) + +# De-quantize and post-process the result +y0 = model.post_processing(model.dequantize_output(q_y)) + +print("Probability with `predict_proba`: ", y_proba_fhe) +print("Probability with encrypt/run/decrypt calls: ", y0) +``` + +This example shows the typical flow of a Concrete ML model: + +- The model is trained on unencrypted (plaintext) data using scikit-learn. As FHE operates over integers, Concrete ML quantizes the model to use only integers during inference. +- The quantized model is compiled to an FHE equivalent. Under the hood, the model is first converted to a Concrete Python program, then compiled. +- Inference can then be done on encrypted data. The above example shows encrypted inference in the model-development phase. Alternatively, during [deployment](cloud.md) in a client/server setting, the data is encrypted by the client, processed securely by the server, and then decrypted by the client. + +## Current limitations + +To make a model work with FHE, the only constraint is to make it run within the supported precision limitations of Concrete ML (currently 16-bit integers). Thus, machine learning models must be quantized, which sometimes leads to a loss of accuracy versus the original model, which operates on plaintext. + +Additionally, Concrete ML currently only supports training on encrypted data for some models, while it supports _inference_ for a large variety of models. + +Finally, there is currently no support for pre-processing model inputs and post-processing model outputs. These processing stages may involve text-to-numerical feature transformation, dimensionality reduction, KNN or clustering, featurization, normalization, and the mixing of results of ensemble models. + +These issues are currently being addressed, and significant improvements are expected to be released in the near future. + +## Concrete stack + +Concrete ML is built on top of Zama's [Concrete](https://github.com/zama-ai/concrete). + +## Online demos and tutorials + +Various tutorials are available for [built-in models](../tutorials/ml_examples.md) and [deep learning](../tutorials/dl_examples.md). Several stand-alone demos for use cases can be found in the [Demos and Tutorials](../tutorials/showcase.md) section. + +If you have built awesome projects using Concrete ML, feel free to let us know and we'll link to your work! + +## Additional resources + +- [Dedicated Concrete ML community support](https://community.zama.ai/c/concrete-ml/8) +- [Zama's blog](https://www.zama.ai/blog) +- [FHE.org community](https://fhe.org) + +## Support + +- Support forum: [https://community.zama.ai](https://community.zama.ai) (we answer in less than 24 hours). +- Live discussion on the FHE.org Discord server: [https://discord.fhe.org](https://discord.fhe.org) (inside the #**concrete** channel). +- Do you have a question about Zama? Write us on [Twitter](https://twitter.com/zama_fhe) or send us an email at: **hello@zama.ai** diff --git a/docs/getting-started/cloud.md b/docs/getting-started/cloud.md index 6422e6cab..b825c02b1 100644 --- a/docs/getting-started/cloud.md +++ b/docs/getting-started/cloud.md @@ -1,4 +1,4 @@ -# Inference in the Cloud +# Inference in the cloud Concrete ML models can be easily deployed in a client/server setting, enabling the creation of privacy-preserving services in the cloud. @@ -18,4 +18,4 @@ The steps detailed above are: 1. The server uses the _evaluation_ key to securely run inference on the user's data and sends back the encrypted result. 1. The client now decrypts the result and can send back new requests. -For more information on how to implement this basic secure inference protocol, refer to the [Production Deployment section](../advanced-topics/client_server.md) and to the [client/server example](../advanced_examples/ClientServer.ipynb). +For more information on how to implement this basic secure inference protocol, refer to the [Production Deployment section](../guides/client_server.md) and to the [client/server example](../advanced_examples/ClientServer.ipynb). diff --git a/docs/getting-started/concepts.md b/docs/getting-started/concepts.md index 5190449e7..9b1793db9 100644 --- a/docs/getting-started/concepts.md +++ b/docs/getting-started/concepts.md @@ -1,4 +1,4 @@ -# Key Concepts +# Key concepts Concrete ML is built on top of Concrete, which enables NumPy programs to be converted into FHE circuits. @@ -7,12 +7,12 @@ Concrete ML is built on top of Concrete, which enables NumPy programs to be conv ### I. Model development 1. **training:** A model is trained using plaintext, non-encrypted, training data. -1. **quantization:** The model is converted into an integer equivalent using quantization. Concrete ML performs this step either during training (Quantization Aware Training) or after training (Post-training Quantization), depending on model type. Quantization converts inputs, model weights, and all intermediate values of the inference computation to integers. More information is available [here](../advanced-topics/quantization.md). -1. **simulation:** Testing FHE models on very large data-sets can take a long time. Furthermore, not all models are compatible with FHE constraints out of the box. Simulation allows you to execute a model that was quantized, to measure the accuracy it would have in FHE, but also to determine the modifications required to make it FHE compatible. Simulation is described in more detail [here](../advanced-topics/compilation.md#fhe-simulation). -1. **compilation:** Once the model is quantized, simulation can confirm it has good accuracy in FHE. The model then needs to be compiled using Concrete's FHE Compiler to produce an equivalent FHE circuit. This circuit is represented as an MLIR program consisting of low level cryptographic operations. You can read more about FHE compilation [here](../advanced-topics/compilation.md), MLIR [here](https://mlir.llvm.org/), and about the low-level Concrete library [here](https://docs.zama.ai/concrete-core). +1. **quantization:** The model is converted into an integer equivalent using quantization. Concrete ML performs this step either during training (Quantization Aware Training) or after training (Post-training Quantization), depending on model type. Quantization converts inputs, model weights, and all intermediate values of the inference computation to integers. More information is available [here](../explanations/quantization.md). +1. **simulation:** Testing FHE models on very large data-sets can take a long time. Furthermore, not all models are compatible with FHE constraints out of the box. Simulation allows you to execute a model that was quantized, to measure the accuracy it would have in FHE, but also to determine the modifications required to make it FHE compatible. Simulation is described in more detail [here](../explanations/compilation.md#fhe-simulation). +1. **compilation:** Once the model is quantized, simulation can confirm it has good accuracy in FHE. The model then needs to be compiled using Concrete's FHE Compiler to produce an equivalent FHE circuit. This circuit is represented as an MLIR program consisting of low level cryptographic operations. You can read more about FHE compilation [here](../explanations/compilation.md), MLIR [here](https://mlir.llvm.org/), and about the low-level Concrete library [here](https://docs.zama.ai/concrete-core). 1. **inference:** The compiled model can then be executed on encrypted data, once the proper keys have been generated. The model can also be deployed to a server and used to run private inference on encrypted inputs. -You can find examples of the model development workflow [here](../built-in-models/ml_examples.md). +You can find examples of the model development workflow [here](../tutorials/ml_examples.md). ### II. Model deployment @@ -40,10 +40,10 @@ While Concrete ML users only need to understand the cryptography concepts above, To respect FHE constraints, all numerical programs that include non-linear operations over encrypted data must have all inputs, constants, and intermediate values represented with integers of a maximum of 16 bits. -Concrete ML quantizes the input data and model outputs in the same way as weights and activations. The main levers to control accumulator bit-width are the number of bits used for the inputs, weights, and activations of the model. These parameters are crucial to comply with the constraint on accumulator bit-widths. Please refer to [the quantization documentation](../advanced-topics/quantization.md) for more details about how to develop models with quantization in Concrete ML. +Concrete ML quantizes the input data and model outputs in the same way as weights and activations. The main levers to control accumulator bit-width are the number of bits used for the inputs, weights, and activations of the model. These parameters are crucial to comply with the constraint on accumulator bit-widths. Please refer to [the quantization documentation](../explanations/quantization.md) for more details about how to develop models with quantization in Concrete ML. -These methods may cause a reduction in the accuracy of the model since its representative power is diminished. Carefully choosing a quantization approach can alleviate accuracy loss, all the while allowing compilation to FHE. Concrete ML offers built-in models that include quantization algorithms, and users only need to configure some of their parameters, such as the number of bits, discussed above. See [the advanced quantization guide](../advanced-topics/quantization.md#configuring-model-quantization-parameters) for information about configuring these parameters for various models. +These methods may cause a reduction in the accuracy of the model since its representative power is diminished. Carefully choosing a quantization approach can alleviate accuracy loss, all the while allowing compilation to FHE. Concrete ML offers built-in models that include quantization algorithms, and users only need to configure some of their parameters, such as the number of bits, discussed above. See [the advanced quantization guide](../explanations/quantization.md#configuring-model-quantization-parameters) for information about configuring these parameters for various models. Additional specific methods can help to make models compatible with FHE constraints. For instance, dimensionality reduction can reduce the number of input features and, thus, the maximum accumulator bit-width reached within a circuit. Similarly, sparsity-inducing training methods, such as pruning, deactivate some features during inference. For now, dimensionality reduction is considered as a pre-processing step, while pruning is used in the [built-in neural networks](../built-in-models/neural-networks.md). -The configuration of model quantization parameters is illustrated in the advanced examples for [Linear and Logistic Regressions](../built-in-models/ml_examples.md) and dimensionality reduction is shown in the [Poisson regression example](../advanced_examples/PoissonRegression.ipynb). +The configuration of model quantization parameters is illustrated in the advanced examples for [Linear and Logistic Regressions](../tutorials/ml_examples.md) and dimensionality reduction is shown in the [Poisson regression example](../advanced_examples/PoissonRegression.ipynb). diff --git a/docs/getting-started/showcase.md b/docs/getting-started/showcase.md deleted file mode 100644 index e13bc2571..000000000 --- a/docs/getting-started/showcase.md +++ /dev/null @@ -1,129 +0,0 @@ -# Demos and Tutorials - -This section lists several demos that apply Concrete ML to some popular machine learning problems. They show -how to build ML models that perform well under FHE constraints, and then how to perform the conversion to FHE. - -Simpler tutorials that discuss only model usage and compilation are also available for [built-in models](../built-in-models/ml_examples.md) and [deep learning](../deep-learning/examples.md). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
GPT-2 in FHE -

-

Privacy-preserving text generation based on a user's prompt

-
health.pnguse_case_examples/llm
Titanic -

-

Train an XGB classifier that can perform encrypted prediction for the Kaggle Titanic competition

-
titanic.pnguse_case_examples/titanic
Federated Learning and Private Inference -

-

Use federated learning to train a Logistic Regression while preserving training data confidentiality. - Import the model into Concrete ML and perform encrypted prediction

-
mnist.pnguse_case_examples/federated_learning
Neural Network Fine-tuning -

-

Fine-tune a VGG network to classify the CIFAR image data-sets and predict on encrypted data

-
nn.pnguse_case_examples/cifar/cifar_brevitas_finetuning
Neural Network Splitting for SaaS deployment -

-

Train a VGG-like CNN that classifies CIFAR10 encrypted images, and where an initial feature extractor is executed client-side

-
client-server-1.pnguse_case_examples/cifar/cifar_brevitas_with_model_splitting
Encrypted Image filtering -

-

A Hugging Face space that applies a variety of image filters to encrypted images

-
blurring.pnguse_case_examples/image_filtering
Encrypted sentiment analysis -

-

A Hugging Face space that securely analyzes the sentiment expressed in a short text

-
sentiment.pnguse_case_examples/sentiment_analysis_with_transformer
Credit Scoring -

-

Predict the chance of a given loan applicant defaulting on loan repayment

-
credit.pnguse_case_examples/credit_scoring
Healthcare diagnosis -

-

Give a diagnosis using FHE to preserve the privacy of the patient

-
health.pnguse_case_examples/disease_prediction
diff --git a/docs/advanced-topics/client_server.md b/docs/guides/client_server.md similarity index 100% rename from docs/advanced-topics/client_server.md rename to docs/guides/client_server.md diff --git a/docs/advanced-topics/hybrid-models.md b/docs/guides/hybrid-models.md similarity index 70% rename from docs/advanced-topics/hybrid-models.md rename to docs/guides/hybrid-models.md index 1c3b4c4f4..0cfc107eb 100644 --- a/docs/advanced-topics/hybrid-models.md +++ b/docs/guides/hybrid-models.md @@ -1,4 +1,4 @@ -# Hybrid model deployment +# Hybrid models FHE enables cloud applications to process private user data without running the risk of data leaks. Furthermore, deploying ML models in the cloud is advantageous as it eases model updates, allows to scale to large numbers of users by using large amounts of compute power, and protects model IP by keeping the model on a trusted server instead of the client device. @@ -7,13 +7,10 @@ However, not all applications can be easily converted to FHE computation and the Hybrid models provide a balance between on-device deployment and cloud-based deployment. This approach entails executing parts of the model directly on the client side, while other parts are securely processed with FHE on the server side. Concrete ML facilitates the hybrid deployment of various neural network models, including MLP (multilayer perceptron), CNN (convolutional neural network), and Large Language Models. {% hint style="warning" %} -If model IP protection is important, care must be taken in choosing the parts of a model to be executed on the cloud. Some -black-box model stealing attacks rely on knowledge distillation -or on differential methods. As a general rule, the difficulty -to steal a machine learning model is proportional to the size of the model, in terms of numbers of parameters and model depth. +If model IP protection is important, care must be taken in choosing the parts of a model to be executed on the cloud. Some black-box model stealing attacks rely on knowledge distillation or on differential methods. As a general rule, the difficulty to steal a machine learning model is proportional to the size of the model, in terms of numbers of parameters and model depth. {% endhint %} -The hybrid model deployment API provides an easy way to integrate the [standard deployment procedure](client_server.md) into neural network style models that are compiled with [`compile_brevitas_qat_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_brevitas_qat_model) or [`compile_torch_model`](../developer-guide/api/concrete.ml.torch.compile.md#function-compile_torch_model). +The hybrid model deployment API provides an easy way to integrate the [standard deployment procedure](client_server.md) into neural network style models that are compiled with [`compile_brevitas_qat_model`](../references/api/concrete.ml.torch.compile.md#function-compile_brevitas_qat_model) or [`compile_torch_model`](../references/api/concrete.ml.torch.compile.md#function-compile_torch_model). ## Compilation @@ -71,11 +68,9 @@ hybrid_model.save_and_clear_private_info(model_dir, via_mlir=True) ## Server Side Deployment -The [`save_and_clear_private_info`](../developer-guide/api/concrete.ml.torch.hybrid_model.md#method-save_and_clear_private_info) function serializes the FHE circuits -corresponding to the various parts of the model that were chosen to be moved -server-side. It also saves the client-side model, removing the weights of the layers that are transferred server-side. Furthermore it saves all necessary information required to serve these sub-models with FHE, using the [`FHEModelDev`](../developer-guide/api/concrete.ml.deployment.fhe_client_server.md#class-fhemodeldev) class. +The [`save_and_clear_private_info`](../references/api/concrete.ml.torch.hybrid_model.md#method-save_and_clear_private_info) function serializes the FHE circuits corresponding to the various parts of the model that were chosen to be moved server-side. It also saves the client-side model, removing the weights of the layers that are transferred server-side. Furthermore it saves all necessary information required to serve these sub-models with FHE, using the [`FHEModelDev`](../references/api/concrete.ml.deployment.fhe_client_server.md#class-fhemodeldev) class. -The [`FHEModelServer`](../developer-guide/api/concrete.ml.deployment.fhe_client_server.md#class-fhemodelserver) class should be used to create a server application that creates end-points to serve these sub-models: +The [`FHEModelServer`](../references/api/concrete.ml.deployment.fhe_client_server.md#class-fhemodelserver) class should be used to create a server application that creates end-points to serve these sub-models: @@ -89,8 +84,7 @@ For more information about serving FHE models, see the [client/server section](c ## Client Side -A client application that deploys a model with hybrid deployment can be developed -in a very similar manner to on-premise deployment: the model is loaded normally with PyTorch, but an extra step is required to specify the remote endpoint and the model parts that are to be executed remotely. +A client application that deploys a model with hybrid deployment can be developed in a very similar manner to on-premise deployment: the model is loaded normally with PyTorch, but an extra step is required to specify the remote endpoint and the model parts that are to be executed remotely. @@ -105,8 +99,7 @@ hybrid_model = HybridFHEModel( ) ``` -Next, the client application must obtain the parameters necessary to encrypt and -quantize data, as detailed in the [client/server documentation](client_server.md#production-deployment). +Next, the client application must obtain the parameters necessary to encrypt and quantize data, as detailed in the [client/server documentation](client_server.md#production-deployment). @@ -115,8 +108,7 @@ path_to_clients = Path(__file__).parent / "clients" hybrid_model.init_client(path_to_clients=path_to_clients) ``` -When the client application is ready to make inference requests to the server, it must -set the operation mode of the `HybridFHEModel` instance to `HybridFHEMode.REMOTE`: +When the client application is ready to make inference requests to the server, it must set the operation mode of the `HybridFHEModel` instance to `HybridFHEMode.REMOTE`: diff --git a/docs/advanced-topics/prediction_with_fhe.md b/docs/guides/prediction_with_fhe.md similarity index 100% rename from docs/advanced-topics/prediction_with_fhe.md rename to docs/guides/prediction_with_fhe.md diff --git a/docs/advanced-topics/serialization.md b/docs/guides/serialization.md similarity index 100% rename from docs/advanced-topics/serialization.md rename to docs/guides/serialization.md diff --git a/docs/index.toc.txt b/docs/index.toc.txt index a9cbab77a..5b8a45c79 100644 --- a/docs/index.toc.txt +++ b/docs/index.toc.txt @@ -9,10 +9,10 @@ :hidden: :caption: Getting Started + getting-started/README.md getting-started/pip_installing.md getting-started/concepts.md getting-started/cloud.md - getting-started/showcase.md .. toctree:: :maxdepth: 0 @@ -24,7 +24,6 @@ built-in-models/neural-networks.md built-in-models/nearest-neighbors.md built-in-models/pandas.md - built-in-models/ml_examples.md built-in-models/training.md .. toctree:: @@ -34,7 +33,6 @@ deep-learning/torch_support.md deep-learning/onnx_support.md - deep-learning/examples.md deep-learning/fhe_friendly_models.md deep-learning/fhe_assistant.md deep-learning/optimizing_inference.md @@ -42,41 +40,59 @@ .. toctree:: :maxdepth: 0 :hidden: - :caption: Advanced topics + :caption: Guides - advanced-topics/quantization.md - advanced-topics/pruning.md - advanced-topics/compilation.md - advanced-topics/prediction_with_fhe.md - advanced-topics/client_server.md - advanced-topics/advanced_features.md - advanced-topics/serialization.md - advanced-topics/hybrid-models.md + guides/prediction_with_fhe.md + guides/client_server.md + guides/hybrid-models.md + guides/serialization.md .. toctree:: :maxdepth: 0 :hidden: - :caption: Developer - Workflow + :caption: Tutorials - developer-guide/project_setup.md - developer-guide/docker_setup.md - developer-guide/documenting.md - developer-guide/debug_support_submit_issues.md - developer-guide/contributing.md + tutorials/showcase.md + tutorials/ml_examples.md + tutorials/dl_examples.md + +.. toctree:: + :maxdepth: 1 + :hidden: + :caption: API + + API <_apidoc/modules.rst> .. toctree:: :maxdepth: 0 :hidden: - :caption: Developer - Inner Workings + :caption: Explanations + + explanations/quantization.md + explanations/pruning.md + explanations/compilation.md + explanations/advanced_features.md + +.. toctree:: + :maxdepth: 1 + :hidden: + :caption: Project Architecture - developer-guide/onnx_pipeline.md - developer-guide/quantization_internal.md - developer-guide/fhe-op-graphs.md - developer-guide/external_libraries.md + explanations/inner-workings/README.md + explanations/inner-workings/onnx_pipeline.md + explanations/inner-workings/quantization_internal.md + explanations/inner-workings/fhe-op-graphs.md + explanations/inner-workings/external_libraries.md .. toctree:: :maxdepth: 0 :hidden: - :caption: API + :caption: Developer + + developer/project_setup.md + developer/docker_setup.md + developer/documenting.md + developer/debug_support_submit_issues.md + developer/contributing.md + - API <_apidoc/modules.rst> diff --git a/docs/developer-guide/api/README.md b/docs/references/api/README.md similarity index 100% rename from docs/developer-guide/api/README.md rename to docs/references/api/README.md diff --git a/docs/developer-guide/api/concrete.ml.common.check_inputs.md b/docs/references/api/concrete.ml.common.check_inputs.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.check_inputs.md rename to docs/references/api/concrete.ml.common.check_inputs.md diff --git a/docs/developer-guide/api/concrete.ml.common.debugging.custom_assert.md b/docs/references/api/concrete.ml.common.debugging.custom_assert.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.debugging.custom_assert.md rename to docs/references/api/concrete.ml.common.debugging.custom_assert.md diff --git a/docs/developer-guide/api/concrete.ml.common.debugging.md b/docs/references/api/concrete.ml.common.debugging.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.debugging.md rename to docs/references/api/concrete.ml.common.debugging.md diff --git a/docs/developer-guide/api/concrete.ml.common.md b/docs/references/api/concrete.ml.common.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.md rename to docs/references/api/concrete.ml.common.md diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.decoder.md b/docs/references/api/concrete.ml.common.serialization.decoder.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.serialization.decoder.md rename to docs/references/api/concrete.ml.common.serialization.decoder.md diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.dumpers.md b/docs/references/api/concrete.ml.common.serialization.dumpers.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.serialization.dumpers.md rename to docs/references/api/concrete.ml.common.serialization.dumpers.md diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.encoder.md b/docs/references/api/concrete.ml.common.serialization.encoder.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.serialization.encoder.md rename to docs/references/api/concrete.ml.common.serialization.encoder.md diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.loaders.md b/docs/references/api/concrete.ml.common.serialization.loaders.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.serialization.loaders.md rename to docs/references/api/concrete.ml.common.serialization.loaders.md diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.md b/docs/references/api/concrete.ml.common.serialization.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.serialization.md rename to docs/references/api/concrete.ml.common.serialization.md diff --git a/docs/developer-guide/api/concrete.ml.common.utils.md b/docs/references/api/concrete.ml.common.utils.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.common.utils.md rename to docs/references/api/concrete.ml.common.utils.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.deploy_to_aws.md b/docs/references/api/concrete.ml.deployment.deploy_to_aws.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.deploy_to_aws.md rename to docs/references/api/concrete.ml.deployment.deploy_to_aws.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.deploy_to_docker.md b/docs/references/api/concrete.ml.deployment.deploy_to_docker.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.deploy_to_docker.md rename to docs/references/api/concrete.ml.deployment.deploy_to_docker.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md b/docs/references/api/concrete.ml.deployment.fhe_client_server.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md rename to docs/references/api/concrete.ml.deployment.fhe_client_server.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.md b/docs/references/api/concrete.ml.deployment.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.md rename to docs/references/api/concrete.ml.deployment.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.server.md b/docs/references/api/concrete.ml.deployment.server.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.server.md rename to docs/references/api/concrete.ml.deployment.server.md diff --git a/docs/developer-guide/api/concrete.ml.deployment.utils.md b/docs/references/api/concrete.ml.deployment.utils.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.deployment.utils.md rename to docs/references/api/concrete.ml.deployment.utils.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.convert.md b/docs/references/api/concrete.ml.onnx.convert.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.convert.md rename to docs/references/api/concrete.ml.onnx.convert.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.md b/docs/references/api/concrete.ml.onnx.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.md rename to docs/references/api/concrete.ml.onnx.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.onnx_impl_utils.md b/docs/references/api/concrete.ml.onnx.onnx_impl_utils.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.onnx_impl_utils.md rename to docs/references/api/concrete.ml.onnx.onnx_impl_utils.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.onnx_model_manipulations.md b/docs/references/api/concrete.ml.onnx.onnx_model_manipulations.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.onnx_model_manipulations.md rename to docs/references/api/concrete.ml.onnx.onnx_model_manipulations.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.onnx_utils.md b/docs/references/api/concrete.ml.onnx.onnx_utils.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.onnx_utils.md rename to docs/references/api/concrete.ml.onnx.onnx_utils.md diff --git a/docs/developer-guide/api/concrete.ml.onnx.ops_impl.md b/docs/references/api/concrete.ml.onnx.ops_impl.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.onnx.ops_impl.md rename to docs/references/api/concrete.ml.onnx.ops_impl.md diff --git a/docs/developer-guide/api/concrete.ml.pytest.md b/docs/references/api/concrete.ml.pytest.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.pytest.md rename to docs/references/api/concrete.ml.pytest.md diff --git a/docs/developer-guide/api/concrete.ml.pytest.torch_models.md b/docs/references/api/concrete.ml.pytest.torch_models.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.pytest.torch_models.md rename to docs/references/api/concrete.ml.pytest.torch_models.md diff --git a/docs/developer-guide/api/concrete.ml.pytest.utils.md b/docs/references/api/concrete.ml.pytest.utils.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.pytest.utils.md rename to docs/references/api/concrete.ml.pytest.utils.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.base_quantized_op.md b/docs/references/api/concrete.ml.quantization.base_quantized_op.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.base_quantized_op.md rename to docs/references/api/concrete.ml.quantization.base_quantized_op.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.md b/docs/references/api/concrete.ml.quantization.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.md rename to docs/references/api/concrete.ml.quantization.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.post_training.md b/docs/references/api/concrete.ml.quantization.post_training.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.post_training.md rename to docs/references/api/concrete.ml.quantization.post_training.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantized_module.md b/docs/references/api/concrete.ml.quantization.quantized_module.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.quantized_module.md rename to docs/references/api/concrete.ml.quantization.quantized_module.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md b/docs/references/api/concrete.ml.quantization.quantized_module_passes.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md rename to docs/references/api/concrete.ml.quantization.quantized_module_passes.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md b/docs/references/api/concrete.ml.quantization.quantized_ops.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md rename to docs/references/api/concrete.ml.quantization.quantized_ops.md diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantizers.md b/docs/references/api/concrete.ml.quantization.quantizers.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.quantization.quantizers.md rename to docs/references/api/concrete.ml.quantization.quantizers.md diff --git a/docs/developer-guide/api/concrete.ml.search_parameters.md b/docs/references/api/concrete.ml.search_parameters.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.search_parameters.md rename to docs/references/api/concrete.ml.search_parameters.md diff --git a/docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md b/docs/references/api/concrete.ml.search_parameters.p_error_search.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md rename to docs/references/api/concrete.ml.search_parameters.p_error_search.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.base.md b/docs/references/api/concrete.ml.sklearn.base.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.base.md rename to docs/references/api/concrete.ml.sklearn.base.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.glm.md b/docs/references/api/concrete.ml.sklearn.glm.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.glm.md rename to docs/references/api/concrete.ml.sklearn.glm.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.linear_model.md b/docs/references/api/concrete.ml.sklearn.linear_model.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.linear_model.md rename to docs/references/api/concrete.ml.sklearn.linear_model.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.md b/docs/references/api/concrete.ml.sklearn.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.md rename to docs/references/api/concrete.ml.sklearn.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.neighbors.md b/docs/references/api/concrete.ml.sklearn.neighbors.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.neighbors.md rename to docs/references/api/concrete.ml.sklearn.neighbors.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.qnn.md b/docs/references/api/concrete.ml.sklearn.qnn.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.qnn.md rename to docs/references/api/concrete.ml.sklearn.qnn.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md b/docs/references/api/concrete.ml.sklearn.qnn_module.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md rename to docs/references/api/concrete.ml.sklearn.qnn_module.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.rf.md b/docs/references/api/concrete.ml.sklearn.rf.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.rf.md rename to docs/references/api/concrete.ml.sklearn.rf.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.svm.md b/docs/references/api/concrete.ml.sklearn.svm.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.svm.md rename to docs/references/api/concrete.ml.sklearn.svm.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.tree.md b/docs/references/api/concrete.ml.sklearn.tree.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.tree.md rename to docs/references/api/concrete.ml.sklearn.tree.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.tree_to_numpy.md b/docs/references/api/concrete.ml.sklearn.tree_to_numpy.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.tree_to_numpy.md rename to docs/references/api/concrete.ml.sklearn.tree_to_numpy.md diff --git a/docs/developer-guide/api/concrete.ml.sklearn.xgb.md b/docs/references/api/concrete.ml.sklearn.xgb.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.sklearn.xgb.md rename to docs/references/api/concrete.ml.sklearn.xgb.md diff --git a/docs/developer-guide/api/concrete.ml.torch.compile.md b/docs/references/api/concrete.ml.torch.compile.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.torch.compile.md rename to docs/references/api/concrete.ml.torch.compile.md diff --git a/docs/developer-guide/api/concrete.ml.torch.hybrid_model.md b/docs/references/api/concrete.ml.torch.hybrid_model.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.torch.hybrid_model.md rename to docs/references/api/concrete.ml.torch.hybrid_model.md diff --git a/docs/developer-guide/api/concrete.ml.torch.md b/docs/references/api/concrete.ml.torch.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.torch.md rename to docs/references/api/concrete.ml.torch.md diff --git a/docs/developer-guide/api/concrete.ml.torch.numpy_module.md b/docs/references/api/concrete.ml.torch.numpy_module.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.torch.numpy_module.md rename to docs/references/api/concrete.ml.torch.numpy_module.md diff --git a/docs/developer-guide/api/concrete.ml.version.md b/docs/references/api/concrete.ml.version.md similarity index 100% rename from docs/developer-guide/api/concrete.ml.version.md rename to docs/references/api/concrete.ml.version.md diff --git a/docs/tutorials/dl_examples.md b/docs/tutorials/dl_examples.md new file mode 100644 index 000000000..6ff3017db --- /dev/null +++ b/docs/tutorials/dl_examples.md @@ -0,0 +1,23 @@ +# Deep learning examples + +These examples illustrate the basic usage of Concrete ML to build various types of neural networks. They use simple data-sets, focusing on the syntax and usage of Concrete ML. For examples showing how to train high-accuracy models on more complex data-sets, see the [Demos and Tutorials](showcase.md) section. + +## FHE constraints considerations + +The examples listed here make use of [simulation](../explanations/compilation.md#fhe-simulation) to perform evaluation over large test sets. Since FHE execution can be slow, only a few FHE executions can be performed. The [correctness guarantees](../getting-started/concepts.md#cryptography-concepts) of Concrete ML ensure that accuracy measured with simulation is the same as that which will be obtained during FHE execution. + +Some examples constrain accumulators to 7-8 bits, which can be sufficient for simple data-sets. Up to 16-bit accumulators can be used, but this introduces a slowdown of 4-5x compared to 8-bit accumulators. + +## List of Examples + +### 1. Step-by-step guide to building a custom NN + +[![](../.gitbook/assets/jupyter_logo.png) Quantization aware training example](../advanced_examples/QuantizationAwareTraining.ipynb) + +This shows how to use Quantization Aware Training and pruning when starting out from a classical PyTorch network. This example uses a simple data-set and a small NN, which achieves good accuracy with low accumulator size. + +### 2. Custom convolutional NN on the [Digits](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_digits.html) data-set + +[![](../.gitbook/assets/jupyter_logo.png) Convolutional Neural Network](../advanced_examples/ConvolutionalNeuralNetwork.ipynb) + +Following the [Step-by-step guide](../deep-learning/fhe_friendly_models.md), this notebook implements a Quantization Aware Training convolutional neural network on the MNIST data-set. It uses 3-bit weights and activations, giving a 7-bit accumulator. diff --git a/docs/built-in-models/ml_examples.md b/docs/tutorials/ml_examples.md similarity index 60% rename from docs/built-in-models/ml_examples.md rename to docs/tutorials/ml_examples.md index 4fac38868..0751fc613 100644 --- a/docs/built-in-models/ml_examples.md +++ b/docs/tutorials/ml_examples.md @@ -1,6 +1,6 @@ -# Built-in Model Examples +# Built-in model examples -These examples illustrate the basic usage of built-in Concrete ML models. For more examples showing how to train high-accuracy models on more complex data-sets, see the [Demos and Tutorials](../getting-started/showcase.md) section. +These examples illustrate the basic usage of built-in Concrete ML models. For more examples showing how to train high-accuracy models on more complex data-sets, see the [Demos and Tutorials](showcase.md) section. ## FHE constraints @@ -11,59 +11,53 @@ Tree-based models apply non-linear functions that enable comparisons of inputs a In the examples below, built-in neural networks can be configured to work with user-specified accumulator sizes, which allow the user to adjust the speed/accuracy trade-off. {% hint style="info" %} -It is recommended to use [simulation](../advanced-topics/compilation.md#fhe-simulation) to configure the speed/accuracy trade-off for tree-based models and neural networks, using grid-search or your own heuristics. +It is recommended to use [simulation](../explanations/compilation.md#fhe-simulation) to configure the speed/accuracy trade-off for tree-based models and neural networks, using grid-search or your own heuristics. {% endhint %} ## List of examples ### 1. Linear models -[   Linear Regression example](../advanced_examples/LinearRegression.ipynb) -[   Logistic Regression example](../advanced_examples/LogisticRegression.ipynb) -[   Linear Support Vector Regression example](../advanced_examples/LinearSVR.ipynb) -[   Linear SVM classification](../advanced_examples/SVMClassifier.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) Linear Regression example](../advanced_examples/LinearRegression.ipynb) [![](../.gitbook/assets/jupyter_logo.png) Logistic Regression example](../advanced_examples/LogisticRegression.ipynb) [![](../.gitbook/assets/jupyter_logo.png) Linear Support Vector Regression example](../advanced_examples/LinearSVR.ipynb) [![](../.gitbook/assets/jupyter_logo.png) Linear SVM classification](../advanced_examples/SVMClassifier.ipynb) These examples show how to use the built-in linear models on synthetic data, which allows for easy visualization of the decision boundaries or trend lines. Executing these 1D and 2D models in FHE takes around 1 millisecond. ### 2. Generalized linear models -[   Poisson Regression example](../advanced_examples/PoissonRegression.ipynb) -[   Generalized Linear Models comparison](../advanced_examples/GLMComparison.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) Poisson Regression example](../advanced_examples/PoissonRegression.ipynb) [![](../.gitbook/assets/jupyter_logo.png) Generalized Linear Models comparison](../advanced_examples/GLMComparison.ipynb) These two examples show generalized linear models (GLM) on the real-world [OpenML insurance](https://www.openml.org/d/41214) data-set. As the non-linear, inverse-link functions are computed, these models do not use [PBS](../getting-started/concepts.md#cryptography-concepts), and are, thus, very fast (~1ms execution time). ### 3. Decision tree -[    Decision Tree Classifier](../advanced_examples/DecisionTreeClassifier.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) Decision Tree Classifier](../advanced_examples/DecisionTreeClassifier.ipynb) Using the [OpenML spams](https://www.openml.org/d/44) data-set, this example shows how to train a classifier that detects spam, based on features extracted from email messages. A grid-search is performed over decision-tree hyper-parameters to find the best ones. -[    Decision Tree Regressor](../advanced_examples/DecisionTreeRegressor.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) Decision Tree Regressor](../advanced_examples/DecisionTreeRegressor.ipynb) Using the [House Price prediction](https://www.openml.org/search?type=data&sort=runs&id=537) data-set, this example shows how to train regressor that predicts house prices. ### 4. XGBoost and Random Forest classifier -[   XGBoost/Random Forest example](../advanced_examples/XGBClassifier.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) XGBoost/Random Forest example](../advanced_examples/XGBClassifier.ipynb) This example shows how to train tree-ensemble models (either XGBoost or Random Forest), first on a synthetic data-set, and then on the [Diabetes](https://www.openml.org/d/37) data-set. Grid-search is used to find the best number of trees in the ensemble. ### 5. XGBoost regression -[   XGBoost Regression example](../advanced_examples/XGBRegressor.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) XGBoost Regression example](../advanced_examples/XGBRegressor.ipynb) Privacy-preserving prediction of house prices is shown in this example, using the [House Prices](https://www.openml.org/d/43926) data-set. Using 50 trees in the ensemble, with 5 bits of precision for the input features, the FHE regressor obtains an $$R^2$$ score of 0.90 and an execution time of 7-8 seconds. ### 6. Fully connected neural network -[   NN Iris example](../advanced_examples/FullyConnectedNeuralNetwork.ipynb) -[   NN MNIST example](../advanced_examples/FullyConnectedNeuralNetworkOnMNIST.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) NN Iris example](../advanced_examples/FullyConnectedNeuralNetwork.ipynb) [![](../.gitbook/assets/jupyter_logo.png) NN MNIST example](../advanced_examples/FullyConnectedNeuralNetworkOnMNIST.ipynb) Two different configurations of the built-in, fully-connected neural networks are shown. First, a small bit-width accumulator network is trained on [Iris](https://www.openml.org/d/61) and compared to a PyTorch floating point network. Second, a larger accumulator (>8 bits) is demonstrated on [MNIST](http://yann.lecun.com/exdb/mnist/). ### 7. Comparison of models -[   Classifier comparison](../advanced_examples/ClassifierComparison.ipynb) -[   Regressor comparison](../advanced_examples/RegressorComparison.ipynb) +[![](../.gitbook/assets/jupyter_logo.png) Classifier comparison](../advanced_examples/ClassifierComparison.ipynb) [![](../.gitbook/assets/jupyter_logo.png) Regressor comparison](../advanced_examples/RegressorComparison.ipynb) Based on three different synthetic data-sets, all the built-in classifiers are demonstrated in this notebook, showing accuracies, inference times, accumulator bit-widths, and decision boundaries. diff --git a/docs/tutorials/showcase.md b/docs/tutorials/showcase.md new file mode 100644 index 000000000..666350e8a --- /dev/null +++ b/docs/tutorials/showcase.md @@ -0,0 +1,43 @@ +# See all tutorials + +## Start here + +- [Build-in model examples](ml_examples.md) +- [Deep learning examples](dl_examples.md) + +## Go further + +### Live demos on Hugging Face: + +- [Credit card approval](https://huggingface.co/spaces/zama-fhe/credit_card_approval_prediction): Predicting credit scoring card approval application in which sensitive data can be shared and analyzed without exposing the actual information to neither the three parties involved, nor the server processing it. + - Check the code [here](https://huggingface.co/spaces/zama-fhe/credit_card_approval_prediction/tree/main) +- [Sentiment analysis with transformers](https://huggingface.co/blog/sentiment-analysis-fhe): predicting if an encrypted tweet / short message is positive, negative or neutral, using FHE. + - Check the code [here](https://huggingface.co/spaces/zama-fhe/encrypted_sentiment_analysis/tree/main) and the [blog post](https://huggingface.co/blog/sentiment-analysis-fhe) +- [Health diagnosis](https://huggingface.co/spaces/zama-fhe/encrypted_health_prediction): giving a diagnosis using FHE to preserve the privacy of the patient based on a patient's symptoms, history and other health factors. + - Check the code [here](https://huggingface.co/spaces/zama-fhe/encrypted_health_prediction/tree/main) +- [Encrypted image filtering](https://huggingface.co/spaces/zama-fhe/encrypted_image_filtering): filtering encrypted images by applying filters such as black-and-white, ridge detection, or your own filter. + - Check the code [here](https://huggingface.co/spaces/zama-fhe/encrypted_image_filtering/tree/main) + +### Code examples on Github: + +- [GPT-2 in FHE](../../use_case_examples/llm/README.md): Privacy-preserving text generation based on a user's prompt +- [Titanic](../../use_case_examples/titanic/README.md): Train an XGB classifier that can perform encrypted prediction for the [Kaggle Titanic competition](https://www.kaggle.com/c/titanic/) +- [Federated learning and private inference](../../use_case_examples/federated_learning/README.md): Use federated learning to train a Logistic Regression while preserving training data confidentiality. Import the model into Concrete ML and perform encrypted prediction +- [Neutral network fine-tuning](../../use_case_examples/cifar/cifar_brevitas_finetuning/README.md): Fine-tune a VGG network to classify the CIFAR image data-sets and predict on encrypted data +- [Encrypted sentiment analysis](../../use_case_examples/sentiment_analysis_with_transformer/README.md):A Hugging Face space that securely analyzes the sentiment expressed in a short text +- [Credit scoring](../../use_case_examples/credit_scoring/README.md): Predict the chance of a given loan applicant defaulting on loan repayment + +### Blog tutorials: + +- [Build an end-to-end encrypted Shazam application using Concrete ML](https://www.zama.ai/post/encrypted-shazam-using-fully-homomorphic-encryption-concrete-ml-tutorial) - February 2024 +- [Linear regression over encrypted data with homomorphic encryption](https://www.zama.ai/post/linear-regression-using-linear-svr-and-concrete-ml-homomorphic-encryption) - June 2023 +- [Comparison of Concrete ML regressors](https://www.zama.ai/post/comparison-of-concrete-ml-regressors) - June 2023 +- [How to deploy a machine learning model with Concrete ML](https://www.zama.ai/post/how-to-deploy-machine-learning-models-with-concrete-ml) - May 2023 +- [Encrypted image filtering using homomorphic encryption](https://www.zama.ai/post/encrypted-image-filtering-using-homomorphic-encryption) - February 2023 +- [Sentiment analysis over encrypted data](https://huggingface.co/blog/sentiment-analysis-fhe) - November 2022 +- [Titanic Competition with Privacy Preserving Machine Learning](https://www.zama.ai/post/titanic-competition-with-privacy-preserving-machine-learning-using-concrete-ml) - August 2022 + +### Video tutorials + +- [Train a linear classifier on encrypted data using Concrete ML and Fully Homomorphic Encryption (FHE)](https://www.zama.ai/post/video-tutorial-train-a-linear-classifier-on-encrypted-data-using-concrete-ml-and-fully-homomorphic-encryption-fhe) - February 2024 +- [How to convert a scikit-learn model into its homomorphic equivalent](https://www.zama.ai/post/how-to-convert-a-scikit-learn-model-into-its-homomorphic-equivalent) - June 2023 diff --git a/script/doc_utils/check_apidocs.sh b/script/doc_utils/check_apidocs.sh index 958e831c1..d507f23bd 100755 --- a/script/doc_utils/check_apidocs.sh +++ b/script/doc_utils/check_apidocs.sh @@ -2,11 +2,11 @@ set -e -rm -rf docs/developer-guide/tmp.api_for_check -APIDOCS_OUTPUT=./docs/developer-guide/tmp.api_for_check make apidocs -rm -f docs/developer-guide/tmp.api_for_check/.pages -rm -f docs/developer-guide/api/.pages -diff ./docs/developer-guide/api ./docs/developer-guide/tmp.api_for_check -rm -rf docs/developer-guide/tmp.api_for_check +rm -rf docs/references/tmp.api_for_check +APIDOCS_OUTPUT=./docs/references/tmp.api_for_check make apidocs +rm -f docs/references/tmp.api_for_check/.pages +rm -f docs/references/api/.pages +diff ./docs/references/api ./docs/references/tmp.api_for_check +rm -rf docs/references/tmp.api_for_check diff --git a/script/doc_utils/check_forbidden_words.py b/script/doc_utils/check_forbidden_words.py index f4903aa4e..11e7cc5b6 100644 --- a/script/doc_utils/check_forbidden_words.py +++ b/script/doc_utils/check_forbidden_words.py @@ -49,7 +49,7 @@ def process_file(file_str: str, do_open_problematic_files=False): file_path = Path(file_str).resolve() # Don't do it on API or advanced example data files - if "docs/developer-guide/api" in file_str or "docs/advanced_examples/data" in file_str: + if "docs/references/api" in file_str or "docs/advanced_examples/data" in file_str: return True, 0 # Don't do it for conventions.md file that explains what should or not be done diff --git a/script/doc_utils/fix_api_readme_reference.py b/script/doc_utils/fix_api_readme_reference.py new file mode 100644 index 000000000..5d0d164cb --- /dev/null +++ b/script/doc_utils/fix_api_readme_reference.py @@ -0,0 +1,68 @@ +"""Helper script to replace Replace `references/api/README.md` with `_apidoc/modules.html`.""" + +import argparse +import multiprocessing +import re +import sys +from pathlib import Path + + +def process_file(file_str: str) -> bool: + """Replace `references/api/README.md` with `_apidoc/modules.html`. + + Also changes "references/api" pattern to Sphinx's "_apidoc" + + Args: + file_str (str): the path to the file to process. + + Returns: + bool: True once done + """ + verbose = False + + file_path = Path(file_str).resolve() + file_path_output = Path(file_str).resolve() + + if verbose: + print(f"Fix api reference problems for {str(file_path)} into {str(file_path_output)}") + + api_pattern = "references/api/README.md" + apidoc_pattern = "_apidoc/modules.html" + + processed_content = "" + with open(file_path, "r", encoding="utf-8") as f: + + for line in f: + newline = re.sub(api_pattern, apidoc_pattern, line) + processed_content += newline + + with open(file_path_output, "w", encoding="utf-8") as fout: + print(processed_content, file=fout, end="") + + return True + + +def main(args): + """Entry point. + + Args: + args (List[str]): a list of arguments + """ + with multiprocessing.Pool(multiprocessing.cpu_count()) as pool: + res = pool.map(process_file, args.files) + # Exit 0 if all went well as True == 1 + sys.exit(not all(res)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + "Replace `references/api/README.md` with `_apidoc/modules.html`.", + allow_abbrev=False, + ) + + parser.add_argument( + "--files", type=str, nargs="+", required=True, help="The files to modify in place" + ) + + cli_args = parser.parse_args() + main(cli_args) diff --git a/script/doc_utils/fix_gitbook_table.py b/script/doc_utils/fix_gitbook_table.py deleted file mode 100644 index d538a84bf..000000000 --- a/script/doc_utils/fix_gitbook_table.py +++ /dev/null @@ -1,101 +0,0 @@ -"""Helper script to turn GitBook card boards into something sphinx-style.""" - -import argparse -import multiprocessing -import sys -from functools import partial -from pathlib import Path - - -def process_file(file_str: str): - """Change table-car from gitbook-style to sphinx-style - - Args: - file_str (str): the path to the file to process. - - Raises: - ValueError: value error - - Returns: - True if everything went alright. - """ - - file_path = Path(file_str).resolve() - file_path_output = Path(file_str).resolve() - - processed_content = "" - has_started = False - which_line = 0 - how_many = 0 - - with open(file_path, "r", encoding="utf-8") as f: - - for line in f: - - line = line.rstrip() - - if "" in line: - assert not has_started - has_started = True - which_line = 0 - - processed_content += line - - elif "" in line: - assert has_started - has_started = False - how_many += 1 - - processed_content += line - elif has_started: - if which_line == 0: - # Find the png - which_line += 1 - png = line.split(".gitbook/assets/")[1].split('"')[0] - elif which_line == 1: - # Find link - link = line.split('a href="')[1].split('">')[0] - # Add the line - processed_content += ( - f'' - ) - - else: - raise ValueError - else: - processed_content += line - - processed_content += "\n" - - with open(file_path_output, "w", encoding="utf-8") as fout: - print(processed_content, file=fout) - - assert how_many == 9 - - return True - - -def main(args): - """Entry point. - - Args: - args: a Namespace object - - """ - with multiprocessing.Pool(multiprocessing.cpu_count()) as pool: - res = pool.map(partial(process_file), args.files) - # Exit 0 if all went well as True == 1 - sys.exit(not all(res)) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - "Change table-cards from gitbook-style to sphinx-style", allow_abbrev=False - ) - - parser.add_argument( - "--files", type=str, nargs="+", required=True, help="The files to modify in place" - ) - - cli_args = parser.parse_args() - main(cli_args) diff --git a/script/doc_utils/fix_md_to_html_conversion_from_sphinx_in_href.py b/script/doc_utils/fix_md_to_html_conversion_from_sphinx_in_href.py new file mode 100644 index 000000000..3aaa6f1df --- /dev/null +++ b/script/doc_utils/fix_md_to_html_conversion_from_sphinx_in_href.py @@ -0,0 +1,68 @@ +"""Helper script to replace `href="*.md` patterns with `href="*.html`.""" + +import argparse +import multiprocessing +import re +import sys +from pathlib import Path + + +def process_file(file_str: str) -> bool: + """Replace `href="*.md` patterns with `href="*.html` because Sphinx does not handle them. + + Args: + file_str (str): the path to the file to process. + + Returns: + bool: True once done + """ + verbose = False + + file_path = Path(file_str).resolve() + file_path_output = Path(file_str).resolve() + + if verbose: + print( + f"Fix 'md to html in href' problems for {str(file_path)} into {str(file_path_output)}" + ) + + md_pattern = r'href="([^"]*)\.md' + html_pattern = r'href="\1.html' + + processed_content = "" + with open(file_path, "r", encoding="utf-8") as f: + + for line in f: + newline = re.sub(md_pattern, html_pattern, line) + processed_content += newline + + with open(file_path_output, "w", encoding="utf-8") as fout: + print(processed_content, file=fout, end="") + + return True + + +def main(args): + """Entry point. + + Args: + args (List[str]): a list of arguments + """ + with multiprocessing.Pool(multiprocessing.cpu_count()) as pool: + res = pool.map(process_file, args.files) + # Exit 0 if all went well as True == 1 + sys.exit(not all(res)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + 'Replace `href="*.md` patterns with `href="*.html` because Sphinx does not handle them.', + allow_abbrev=False, + ) + + parser.add_argument( + "--files", type=str, nargs="+", required=True, help="The files to modify in place" + ) + + cli_args = parser.parse_args() + main(cli_args) diff --git a/script/doc_utils/update_apidocs_files_in_SUMMARY.sh b/script/doc_utils/update_apidocs_files_in_SUMMARY.sh index 545ca61dc..fd34379a7 100755 --- a/script/doc_utils/update_apidocs_files_in_SUMMARY.sh +++ b/script/doc_utils/update_apidocs_files_in_SUMMARY.sh @@ -2,7 +2,7 @@ set -e -FILES=$(cd docs && find developer-guide/api -name "*.md") +FILES=$(cd docs && find references/api -name "*.md") # New apidocs section TMP_FILE=$(mktemp /tmp/apidocs.XXXXXX) diff --git a/script/make_utils/check_double_dollars_in_doc.sh b/script/make_utils/check_double_dollars_in_doc.sh index 66af321dc..e030ac2ec 100755 --- a/script/make_utils/check_double_dollars_in_doc.sh +++ b/script/make_utils/check_double_dollars_in_doc.sh @@ -12,9 +12,9 @@ # MacOS's grep is different from GNU's so we need to differenciate here. if [[ $(uname) == "Darwin" ]]; then - OUT=$(find docs -name "*.md" -not -path "docs/developer-guide/*" -print0 | xargs -0 grep -n -E '((^| |^$)\$[^$])|([^$]\$$)|([^$]$[^$])') + OUT=$(find docs -name "*.md" -not -path "docs/developer/*" -print0 | xargs -0 grep -n -E '((^| |^$)\$[^$])|([^$]\$$)|([^$]$[^$])') else - OUT=$(find docs -name "*.md" -not -path "docs/developer-guide/*" -print0 | xargs -0 grep -n -P '((^| |^$)\$[^$])|([^$]\$$)|([^$]$[^$])') + OUT=$(find docs -name "*.md" -not -path "docs/developer/*" -print0 | xargs -0 grep -n -P '((^| |^$)\$[^$])|([^$]\$$)|([^$]$[^$])') fi if [ -n "${OUT}" ]; then diff --git a/script/make_utils/fix_api_readme_reference.sh b/script/make_utils/fix_api_readme_reference.sh new file mode 100755 index 000000000..9cc7fefa7 --- /dev/null +++ b/script/make_utils/fix_api_readme_reference.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +DIRECTORY=$1 + +MD_FILES=$(find "$DIRECTORY" -type f -name "index.rst") + +# Replace `references/api/README.md` with `_apidoc/modules.html`. +# shellcheck disable=SC2086 +poetry run python script/doc_utils/fix_api_readme_reference.py --files $MD_FILES diff --git a/script/make_utils/fix_md_to_html_conversion_from_sphinx_in_href.sh b/script/make_utils/fix_md_to_html_conversion_from_sphinx_in_href.sh new file mode 100755 index 000000000..83f87c3b7 --- /dev/null +++ b/script/make_utils/fix_md_to_html_conversion_from_sphinx_in_href.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -e +DIRECTORY=$1 + +MD_FILES=$(find "$DIRECTORY" -type f -name "*.md") + +# Replace `href="*.md` patterns with `href="*.html` because Sphinx does not handle these +# shellcheck disable=SC2086 +poetry run python script/doc_utils/fix_md_to_html_conversion_from_sphinx_in_href.py --files $MD_FILES diff --git a/use_case_examples/cifar/cifar_brevitas_with_model_splitting/README.md b/use_case_examples/cifar/cifar_brevitas_with_model_splitting/README.md index 30ff736e2..5bcc8a2cb 100644 --- a/use_case_examples/cifar/cifar_brevitas_with_model_splitting/README.md +++ b/use_case_examples/cifar/cifar_brevitas_with_model_splitting/README.md @@ -53,7 +53,7 @@ Once we had this `p_error` validated we re-run the FHE inference using this new - Time to keygen: 30 seconds - Time to infer: 1738 seconds -We see a 20x improvement with a simple change in the `p_error` parameter, for more details on how to handle `p_error` please refer to the [documentation](../../../docs/advanced-topics/advanced_features.md#approximate-computations). +We see a 20x improvement with a simple change in the `p_error` parameter, for more details on how to handle `p_error` please refer to the [documentation](../../../docs/explanations/advanced_features.md#approximate-computations). ## Results diff --git a/use_case_examples/deployment/breast_cancer_builtin/README.md b/use_case_examples/deployment/breast_cancer_builtin/README.md index a97998ab5..167e0aee0 100644 --- a/use_case_examples/deployment/breast_cancer_builtin/README.md +++ b/use_case_examples/deployment/breast_cancer_builtin/README.md @@ -9,7 +9,7 @@ To do so please refer to [AWS documentation](https://docs.aws.amazon.com/cli/lat One can also run this example locally using Docker, or just by running the scripts locally. 1. To train your model you can use `train.py`, or `train_with_docker.sh` to use Docker (recommended way). - This will train a model and [serialize the FHE circuit](../../../docs/advanced-topics/client_server.md) in a new folder called `./dev`. + This will train a model and [serialize the FHE circuit](../../../docs/guides/client_server.md) in a new folder called `./dev`. 1. Once that's done you can use the script provided in Concrete ML in `src/concrete/ml/deployment/`, either use `deploy_to_aws.py` or `deploy_to_docker.py` according to your need. - `python -m concrete.ml.deployment.deploy_to_docker --path-to-model ./dev` diff --git a/use_case_examples/deployment/cifar_8_bit/README.md b/use_case_examples/deployment/cifar_8_bit/README.md index f7395efae..d6357df28 100644 --- a/use_case_examples/deployment/cifar_8_bit/README.md +++ b/use_case_examples/deployment/cifar_8_bit/README.md @@ -11,7 +11,7 @@ One can also run this example locally using Docker, or just by running the scrip Deployment this model on your personal machine is not recommended as running a VGG in FHE is computationally intensive. It is recommended to run this on a `m6i.metal` instance from AWS. -1. To compile your model you can use `compile.py`, or `compile_with_docker.py` to use Docker. This will compile the model to an FHE circuit and [serialize it](../../../docs/advanced-topics/client_server.md). This will result in a new folder called `./dev`. +1. To compile your model you can use `compile.py`, or `compile_with_docker.py` to use Docker. This will compile the model to an FHE circuit and [serialize it](../../../docs/guides/client_server.md). This will result in a new folder called `./dev`. 1. Once that's done you can use the script provided in Concrete ML in `src/concrete/ml/deployment/`, either use `deploy_to_aws.py` or `deploy_to_docker.py` according to your need. - `python -m concrete.ml.deployment.deploy_to_docker` diff --git a/use_case_examples/deployment/sentiment_analysis/README.md b/use_case_examples/deployment/sentiment_analysis/README.md index 93f28bcee..a1e77b12a 100644 --- a/use_case_examples/deployment/sentiment_analysis/README.md +++ b/use_case_examples/deployment/sentiment_analysis/README.md @@ -10,7 +10,7 @@ To do so please refer to [AWS documentation](https://docs.aws.amazon.com/cli/lat One can also run this example locally using Docker, or just by running the scripts locally. 1. To train your model you can use `train.py`, or `train_with_docker.sh` to use Docker (recommended). This operation might take some time. - This will train a model and [serialize the FHE circuit](../../../docs/advanced-topics/client_server.md). + This will train a model and [serialize the FHE circuit](../../../docs/guides/client_server.md). This will result in a new folder called `./dev`. 1. Once that's done you can use the script provided in Concrete ML in `src/concrete/ml/deployment/`, either use `deploy_to_aws.py` or `deploy_to_docker.py` according to your need.