Skip to content

Commit 9d9669d

Browse files
chore: update docs for v1.9.0 (#1071)
Co-authored-by: Andrei Stoian <95410270+andrei-stoian-zama@users.noreply.github.com>
1 parent 2c5f1ab commit 9d9669d

File tree

14 files changed

+1605
-1391
lines changed

14 files changed

+1605
-1391
lines changed

docs/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@
1818
- [Encrypted dataframe](built-in-models/encrypted_dataframe.md)
1919
- [Encrypted training](built-in-models/training.md)
2020

21+
## LLMs
22+
23+
- [Inference](llm/inference.md)
24+
- [Encrypted fine-tuning](llm/lora_training.md)
25+
2126
## Deep Learning
2227

2328
- [Using Torch](deep-learning/torch_support.md)
2429
- [Using ONNX](deep-learning/onnx_support.md)
2530
- [Step-by-step guide](deep-learning/fhe_friendly_models.md)
2631
- [Debugging models](deep-learning/fhe_assistant.md)
2732
- [Optimizing inference](deep-learning/optimizing_inference.md)
28-
- [Encrypted fine-tuning](deep-learning/lora_training.md)
2933

3034
## Guides
3135

docs/built-in-models/linear.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ In addition to predicting on encrypted data, the following models support train
2626

2727
| [SGDClassifier](../references/api/concrete.ml.sklearn.linear_model.md#class-sgdclassifier) | [SGDClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.SGDRegressor.html) |
2828

29+
## Ciphertext format compatibility
30+
31+
These models only support _Concrete_ ciphertexts. See [the ciphertexts format](../getting-started/concepts.md#ciphertext-formats) documentation for more details.
32+
2933
## Quantization parameters
3034

3135
The `n_bits` parameter controls the bit-width of the inputs and weights of the linear models. Linear models do not use table lookups and thus allows weight and inputs to be high precision integers.

docs/built-in-models/nearest-neighbors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ This document introduces the nearest neighbors non-parametric classification mod
66
| :---------------------------------------------------------------------------------------------------: | --------------------------------------------------------------------------------------------------------------------- |
77
| [KNeighborsClassifier](../references/api/concrete.ml.sklearn.neighbors.md#class-kneighborsclassifier) | [KNeighborsClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) |
88

9+
## Ciphertext format compatibility
10+
11+
These models only support _Concrete_ ciphertexts. See [the ciphertexts format](../getting-started/concepts.md#ciphertext-formats) documentation for more details.
12+
913
## Example
1014

1115
```python

docs/built-in-models/neural-networks.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Good quantization parameter values are critical to make models [respect FHE cons
2323
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.
2424
{% endhint %}
2525

26+
## Ciphertext format compatibility
27+
28+
These models only support _Concrete_ ciphertexts. See [the ciphertexts format](../getting-started/concepts.md#ciphertext-formats) documentation for more details.
29+
2630
## Example
2731

2832
To create an instance of a Fully Connected Neural Network (FCNN), you need to instantiate one of the `NeuralNetClassifier` and `NeuralNetRegressor` classes and configure a number of parameters that are passed to their constructor.

docs/built-in-models/training.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ See the [deployment](#deployment) section for more details.
1717
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 models trained through federated learning using 3rd party tools. All model types are supported - linear, tree-based and neural networks - through the [`from_sklearn_model` function](linear.md#pre-trained-models) and the [`compile_torch_model`](../deep-learning/torch_support.md) function.
1818
{% endhint %}
1919

20+
## Ciphertext format compatibility
21+
22+
These models only support _Concrete_ ciphertexts. See [the ciphertexts format](../getting-started/concepts.md#ciphertext-formats) documentation for more details.
23+
2024
## Example
2125

2226
The [logistic regression training](../advanced_examples/LogisticRegressionTraining.ipynb) example shows logistic regression training on encrypted data in action.

docs/built-in-models/tree.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ For a formal explanation of the mechanisms that enable FHE-compatible decision t
2626
Using the maximum depth parameter of decision trees and tree-ensemble models strongly increases the number of nodes in the trees. Therefore, we recommend using the XGBoost models which achieve better performance with lower depth.
2727
{% endhint %}
2828

29+
## Ciphertext format compatibility
30+
31+
The `DecisionTreeClassifier`, `RandomForestClassifier`, and `XGBClassifier` support [TFHE-rs radix ciphertexts](../getting-started/concepts.md#ciphertext-formats) when `n_bits` is set to 8. The other tree-based models, or different `n_bits` configurations only support _Concrete_ ciphertexts.
32+
33+
To compile a model to use _TFHE-rs ciphertexts_ as inputs and outputs, set `ciphertext_mode=CiphertextFormat.TFHE-RS` in the `compile` call.
34+
2935
## Pre-trained models
3036

3137
You can convert an already trained scikit-learn tree-based model to a Concrete ML one by using the [`from_sklearn_model`](../references/api/concrete.ml.sklearn.base.md#classmethod-from_sklearn_model) method.

docs/getting-started/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
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 perform:
66

77
- **Automatic model conversion**: Use familiar APIs from scikit-learn and PyTorch to convert machine learning models to their FHE equivalent. This is applicable 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)).
8-
- **Encrypted data training**: [Train models](../built-in-models/training.md) directly on encrypted data to maintain privacy.
8+
- **Encrypted data training**: [Train linear models](../built-in-models/training.md) or [fine-tune LLMs](../llm/lora_training.md) directly on encrypted data to maintain privacy.
99
- **Encrypted data pre-processing**: [Pre-process encrypted data](../built-in-models/encrypted_dataframe.md) using a DataFrame paradigm.
1010

1111
## Key features
1212

13+
- **Model inference on encrypted data**: Concrete ML converts models such as decision trees, LLMs, neural networks, etc.. to predict on encrypted data. Those models can be trained either on clear data or on encrypted data.
14+
1315
- **Training on encrypted data**: FHE 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. Learn more about FHE in [this introduction](https://www.zama.ai/post/tfhe-deep-dive-part-1) or join the [FHE.org](https://fhe.org) community.
1416

1517
- **Federated learning**: 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 all types of models: linear, tree-based and neural networks, that are trained using federated learning using the [`from_sklearn_model` function](../built-in-models/linear.md#pre-trained-models) and the [`compile_torch_model`](../deep-learning/torch_support.md) function.

docs/getting-started/concepts.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ This document explains the essential cryptographic terms and the important conce
44

55
Concrete ML is built on top of Concrete, which enables the conversion from NumPy programs into FHE circuits.
66

7+
## Table of Contents
8+
9+
1. [Lifecycle of a Concrete ML model](#lifecycle-of-a-concrete-ml-model)
10+
1. [Cryptography concepts](#cryptography-concepts)
11+
1. [Ciphertext formats](#ciphertext-formats)
12+
1. [Model accuracy considerations under FHE constraints](#model-accuracy-considerations-under-fhe-constraints)
13+
714
## Lifecycle of a Concrete ML model
815

916
With Concrete ML, you can train a model on clear or encrypted data, then deploy it to predict on encrypted inputs. During deployment, data can be pre-processed while being encrypted. Therefore, data stay encrypted during the entire lifecycle of the machine learning model, with some limitations.
@@ -39,6 +46,8 @@ You can find examples of the model development workflow [here](../tutorials/ml_e
3946
- A private encryption key to encrypt/decrypt their data and results
4047
- A public evaluation key for the model's FHE evaluation on the server.
4148

49+
1. **Ciphertext formats** The server-side application can be configured to accept different types of ciphertexts from the client, depending on the type of application. See [Ciphertext formats](#ciphertext-formats) for more details.
50+
4251
You can find an example of the model deployment workflow [here](../advanced_examples/ClientServer.ipynb).
4352

4453
## Cryptography concepts
@@ -59,8 +68,30 @@ Concrete ML and Concrete abstract the details of the underlying cryptography sch
5968

6069
- **Programmable Boostrapping (PBS)** : Programmable Bootstrapping enables the homomorphic evaluation of any function of a ciphertext, with a controlled level of noise. Learn more about PBS in [this paper](https://eprint.iacr.org/2021/091).
6170

71+
- **Ciphertext formats**: To represent encrypted values, Concrete ML offers two options: the default Concrete ciphertext format, which is supported by all ML models and highly optimized for performance, or the block-based TFHE-rs radix format, which supports larger values, is forward-compatible, and suitable for Blockchain applications, but is limited to certain types of ML models.
72+
6273
For a deeper understanding of the cryptography behind the Concrete stack, refer to the [whitepaper on TFHE and Programmable Boostrapping](https://whitepaper.zama.ai/) or [this series of blogs](https://www.zama.ai/post/tfhe-deep-dive-part-1).
6374

75+
## Ciphertext formats
76+
77+
Two different types of ciphertexts are usable by Concrete ML for model input/outputs.
78+
79+
1. _Concrete_ LWE ciphertexts (default):
80+
81+
By default, Concrete ML uses Concrete LWE ciphertexts with crypto-system parameters that are tailored to each ML model. These parameters may vary between different versions of Concrete ML. Thus, the encryption crypto-parameters may change at any point. Some implications are:
82+
83+
- Typically, a server-side application provides the client with its encryption cryptographic parameters.
84+
- When the application is updated, the client downloads the new cryptographic parameters.
85+
- Ciphertexts encrypted with a set of cryptographic parameters can not be re-used for a model compiled with different cryptographic parameters
86+
87+
2. _TFHE-rs radix_ ciphertexts:
88+
89+
Concrete ML also supports \_TFHE-rs radix _ ciphertexts, which rely on a universal and forward-compatible parameter set. Therefore:
90+
In this setting, a conversion layer is added to the ML model, potentially resulting in a 4–5× latency overhead.
91+
92+
- Ciphertexts encrypted with the universal cryptographic parameters can be used at any point in the future with any ML model.
93+
- In this setting, a conversion layer is added to the ML model. This conversion may imply a 4-5x slowdown for model latency.
94+
6495
## Model accuracy considerations under FHE constraints
6596

6697
FHE requires all inputs, constants, and intermediate values to be integers of maximum 16 bits. To make machine learning models compatible with FHE, Concrete ML implements some techniques with accuracy considerations:

docs/guides/client_server.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import numpy as np
6262
fhe_directory = '/tmp/fhe_client_server_files/'
6363

6464
# Initialize the Decision Tree model
65-
model = DecisionTreeClassifier()
65+
model = DecisionTreeClassifier(n_bits=8)
6666

6767
# Generate some random data for training
6868
X = np.random.rand(100, 20)
@@ -102,6 +102,43 @@ result = client.deserialize_decrypt_dequantize(encrypted_result)
102102

103103
These objects are serialized into bytes to streamline the data transfer between the client and server.
104104

105+
#### Ciphertext formats and keys
106+
107+
Two types of ciphertext formats are [available in Concrete ML](../getting-started/concepts.md#ciphertext-formats) and both are available for deployment. To use the _TFHE-rs radix_ format, pass the `ciphertext_format` option to the compilation call as follows:
108+
109+
<!--pytest-codeblocks:cont-->
110+
111+
```python
112+
from concrete.ml.common.utils import CiphertextFormat
113+
model.compile(X, ciphertext_format=CiphertextFormat.TFHE_RS)
114+
115+
fhe_directory = '/tmp/fhe_client_server_files_tfhers/'
116+
117+
# Setup the development environment
118+
dev = FHEModelDev(path_dir=fhe_directory, model=model)
119+
dev.save()
120+
121+
# Setup the client
122+
client = FHEModelClient(path_dir=fhe_directory, key_dir="/tmp/keys_client_tfhers")
123+
serialized_evaluation_keys, tfhers_evaluation_keys = client.get_serialized_evaluation_keys(include_tfhers_key=True)
124+
125+
# Client pre-processes new data
126+
X_new = np.random.rand(1, 20)
127+
encrypted_data = client.quantize_encrypt_serialize(X_new)
128+
129+
# Setup the server
130+
server = FHEModelServer(path_dir=fhe_directory)
131+
server.load()
132+
133+
# Server processes the encrypted data
134+
encrypted_result = server.run(encrypted_data, serialized_evaluation_keys)
135+
136+
# Client decrypts the result
137+
result = client.deserialize_decrypt_dequantize(encrypted_result[0])
138+
```
139+
140+
In the example above, a second evaluation key is obtained in the `tfhers_evaluation_keys` variable. This key can be loaded by TFHE-rs Rust programs to perform further computation on the model output ciphertexts.
141+
105142
## Serving
106143

107144
The client-side deployment of a secured inference machine learning model is illustrated as follows:

docs/guides/using_gpu.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ a model is compiled for CUDA, executing it on a non-CUDA-enabled machine will ra
77

88
## Support
99

10-
| Feature | Built-in models | Custom models | Deployment | DataFrame |
11-
| ----------- | --------------- | ------------- | ---------- | --------- |
12-
| GPU support |||||
13-
| | | | | |
10+
| Feature | Built-in models | Deep NNs and LLMs | Deployment | DataFrame |
11+
| ----------- | --------------- | ----------------- | ---------- | --------- |
12+
| GPU support || |||
13+
| | | | | |
1414

1515
{% hint style="warning" %}
1616
When compiling a model for GPU, the model is assigned GPU-specific crypto-system parameters. These parameters are more constrained than the CPU-specific ones.
@@ -29,6 +29,10 @@ on a desktop CPU.
2929

3030
## Prerequisites
3131

32+
### Built-in models and deep NNs
33+
34+
This section pertains to models that are compiled using the `sklearn`-style built-in model classes or that are compiled using `compile_torch_model` or `compile_brevitas_qat_model`.
35+
3236
To use the CUDA-enabled backend, install the GPU-enabled Concrete compiler:
3337

3438
```bash
@@ -65,3 +69,12 @@ To compile a model for CUDA, simply supply the `device='cuda'` argument to its c
6569

6670
- For built-in models, use `.compile` function.
6771
- For custom models, use either`compile_torch_model` or `compile_brevitas_qat_model`.
72+
73+
## LLMs
74+
75+
This section pertains to models that are compiled with `HybridFHEModel`.
76+
77+
The models compiled as described in [the LLM section](../llm/inference.md) will
78+
use GPU acceleration if a GPU is available on the machine where the models
79+
are executed. No specific compilation configuration is required to enable GPU
80+
execution for these models.

0 commit comments

Comments
 (0)