From dbeed7e9703eda2fb0e23e810cb40e8fc31cc2f2 Mon Sep 17 00:00:00 2001 From: Andrei Stoian Date: Thu, 21 Sep 2023 22:50:08 +0200 Subject: [PATCH] chore: fix links --- README.md | 6 +- docs/SUMMARY.md | 12 +- docs/advanced-topics/advanced_features.md | 2 +- docs/advanced-topics/hybrid-models.md | 10 +- docs/built-in-models/nearest-neighbors.md | 8 +- docs/built-in-models/neural-networks.md | 2 +- docs/deep-learning/fhe_friendly_models.md | 2 +- docs/developer-guide/api/README.md | 12 +- ...oncrete.ml.common.serialization.decoder.md | 6 +- .../api/concrete.ml.common.utils.md | 47 +- ...oncrete.ml.deployment.fhe_client_server.md | 18 +- .../api/concrete.ml.onnx.convert.md | 38 +- .../api/concrete.ml.onnx.ops_impl.md | 140 +-- .../api/concrete.ml.pytest.torch_models.md | 78 +- .../api/concrete.ml.pytest.utils.md | 12 +- .../concrete.ml.quantization.post_training.md | 10 +- ...ml.quantization.quantized_module_passes.md | 4 +- .../concrete.ml.quantization.quantized_ops.md | 174 +-- .../concrete.ml.quantization.quantizers.md | 102 +- ...ete.ml.search_parameters.p_error_search.md | 12 +- .../api/concrete.ml.sklearn.base.md | 1020 ++++++++++++++--- .../api/concrete.ml.sklearn.linear_model.md | 26 +- .../api/concrete.ml.sklearn.md | 34 +- .../api/concrete.ml.sklearn.neighbors.md | 103 ++ .../api/concrete.ml.sklearn.qnn.md | 56 +- .../api/concrete.ml.sklearn.qnn_module.md | 22 +- .../api/concrete.ml.sklearn.rf.md | 34 +- .../api/concrete.ml.sklearn.svm.md | 26 +- .../api/concrete.ml.sklearn.tree.md | 34 +- .../api/concrete.ml.sklearn.xgb.md | 36 +- .../api/concrete.ml.torch.compile.md | 6 +- .../api/concrete.ml.torch.hybrid_model.md | 122 +- .../api/concrete.ml.torch.numpy_module.md | 4 +- docs/getting-started/showcase.md | 4 +- docs/index.toc.txt | 2 + use_case_examples/cifar/README.md | 14 +- .../README.md | 2 +- .../deployment/cifar_8_bit/README.md | 2 +- 38 files changed, 1669 insertions(+), 573 deletions(-) create mode 100644 docs/developer-guide/api/concrete.ml.sklearn.neighbors.md diff --git a/README.md b/README.md index 966efd6798..e69f3a3df2 100644 --- a/README.md +++ b/README.md @@ -132,11 +132,11 @@ Various tutorials are proposed for the [built-in models](docs/built-in-models/ml - [Sentiment analysis with transformers](use_case_examples/sentiment_analysis_with_transformer): a gradio demo which predicts if a tweet / short message is positive, negative or neutral, with FHE of course! The [live interactive](https://huggingface.co/spaces/zama-fhe/encrypted_sentiment_analysis) demo is available on Hugging Face. This [blog post](https://huggingface.co/blog/sentiment-analysis-fhe) explains how this demo works! -- [CIFAR10 FHE-friendly model with Brevitas](use_case_examples/cifar_brevitas_training): code for training from scratch a VGG-like FHE-compatible neural network using Brevitas, and a script to run the neural network in FHE. Execution in FHE takes ~20 minutes per image and shows an accuracy of 88.7%. +- [CIFAR10 FHE-friendly model with Brevitas](use_case_examples/cifar/cifar_brevitas_training): code for training from scratch a VGG-like FHE-compatible neural network using Brevitas, and a script to run the neural network in FHE. Execution in FHE takes ~20 minutes per image and shows an accuracy of 88.7%. -- [CIFAR10 / CIFAR100 FHE-friendly models with Transfer Learning approach](use_case_examples/cifar_brevitas_finetuning): series of three notebooks, that show how to convert a pre-trained FP32 VGG11 neural network into a quantized model using Brevitas. The model is fine-tuned on the CIFAR data-sets, converted for FHE execution with Concrete ML and evaluated using FHE simulation. For CIFAR10 and CIFAR100, respectively, our simulations show an accuracy of 90.2% and 68.2%. +- [CIFAR10 / CIFAR100 FHE-friendly models with Transfer Learning approach](use_case_examples/cifar/cifar_brevitas_finetuning): series of three notebooks, that show how to convert a pre-trained FP32 VGG11 neural network into a quantized model using Brevitas. The model is fine-tuned on the CIFAR data-sets, converted for FHE execution with Concrete ML and evaluated using FHE simulation. For CIFAR10 and CIFAR100, respectively, our simulations show an accuracy of 90.2% and 68.2%. -- [FHE neural network splitting for client/server deployment](use_case_examples/cifar_brevitas_with_model_splitting): we explain how to split a computationally-intensive neural network model in two parts. First, we execute the first part on the client side in the clear, and the output of this step is encrypted. Next, to complete the computation, the second part of the model is evaluated with FHE. This tutorial also shows the impact of FHE speed/accuracy trade-off on CIFAR10, limiting PBS to 8-bit, and thus achieving 62% accuracy. +- [FHE neural network splitting for client/server deployment](use_case_examples/cifar/cifar_brevitas_with_model_splitting): we explain how to split a computationally-intensive neural network model in two parts. First, we execute the first part on the client side in the clear, and the output of this step is encrypted. Next, to complete the computation, the second part of the model is evaluated with FHE. This tutorial also shows the impact of FHE speed/accuracy trade-off on CIFAR10, limiting PBS to 8-bit, and thus achieving 62% accuracy. - [Encrypted image filtering](use_case_examples/image_filtering): finally, the live demo for our [6-min](https://6min.zama.ai) is available, in the form of a gradio application. We take encrypted images, and apply some filters (for example black-and-white, ridge detection, or your own filter). diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index 1a2fe59f23..fb668d389b 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -14,6 +14,7 @@ - [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) - [Built-in Model Examples](built-in-models/ml_examples.md) @@ -26,15 +27,19 @@ - [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) -- [Prediction with FHE](advanced-topics/prediction_with_fhe.md) -- [Production Deployment](advanced-topics/client_server.md) - [Advanced Features](advanced-topics/advanced_features.md) -- [Serialization](advanced-topics/serialization.md) ## Developer Guide @@ -89,6 +94,7 @@ - [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) diff --git a/docs/advanced-topics/advanced_features.md b/docs/advanced-topics/advanced_features.md index 009be0a4c3..cc9fccbe77 100644 --- a/docs/advanced-topics/advanced_features.md +++ b/docs/advanced-topics/advanced_features.md @@ -187,7 +187,7 @@ In practice, the process looks like this: 1. Update P = P - 1 1. repeat steps 2 and 3 until the accuracy loss is above a certain, acceptable threshold. -An example of such implementation is available in [evaluate_torch_cml.py](../../use_case_examples/cifar_brevitas_training/evaluate_one_example_fhe.py) and [CifarInFheWithSmallerAccumulators.ipynb](../../use_case_examples/cifar_brevitas_finetuning/CifarInFheWithSmallerAccumulators.ipynb) +An example of such implementation is available in [evaluate_torch_cml.py](../../use_case_examples/cifar/cifar_brevitas_training/evaluate_one_example_fhe.py) and [CifarInFheWithSmallerAccumulators.ipynb](../../use_case_examples/cifar/cifar_brevitas_finetuning/CifarInFheWithSmallerAccumulators.ipynb) ## Seeing compilation information diff --git a/docs/advanced-topics/hybrid-models.md b/docs/advanced-topics/hybrid-models.md index 785cee1eb0..e4ad237096 100644 --- a/docs/advanced-topics/hybrid-models.md +++ b/docs/advanced-topics/hybrid-models.md @@ -13,7 +13,7 @@ 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#kbdfunctionkbd-compilebrevitasqatmodel) or [`compile_torch_model`](../developer-guide/api/concrete.ml.torch.compile.md#kbdfunctionkbd-compiletorchmodel). +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). ## Compilation @@ -71,12 +71,12 @@ hybrid_model.save_and_clear_private_info(model_dir, via_mlir=True) ## Server Side Deployment -The [`save_and_clear_private_info`](<>) function serializes the FHE circuits +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. 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#kbdclasskbd-fhemodeldev) class. +to serve these sub-models with FHE, using the [`FHEModelDev`](../developer-guide/api/concrete.ml.deployment.fhe_client_server.md#class-fhemodeldev) class. -The [`FHEModelServer`](../developer-guide/api/concrete.ml.deployment.fhe_client_server.md#kbdclasskbd-fhemodelserver) class should be used to create a server application that creates end-points to serve these sub-models: +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: @@ -91,7 +91,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. +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. diff --git a/docs/built-in-models/nearest-neighbors.md b/docs/built-in-models/nearest-neighbors.md index 39adbf0a32..b2c23469fc 100644 --- a/docs/built-in-models/nearest-neighbors.md +++ b/docs/built-in-models/nearest-neighbors.md @@ -4,7 +4,7 @@ Concrete ML offers nearest neighbors non-parametric classification models with a | Concrete ML | scikit-learn | | :------------------------: | --------------------------------------------------------------------------------------------------------------------- | -| [KNeighborsClassifier](<>) | [KNeighborsClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) | +| [KNeighborsClassifier](../developer-guide/api/concrete.ml.sklearn.neighbors.md#class-kneighborsclassifier) | [KNeighborsClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html) | ## Example usage @@ -14,8 +14,8 @@ from concrete.ml.sklearn import KNeighborsClassifier concrete_classifier = KNeighborsClassifier(n_bits=2, n_neighbors=3) ``` -The `KNeighborsClassifier` class quantizes the training dataset that is given to `.fit` with the specified number of bits, `n_bits`. As this value must be kept low to comply with [accumulator size constraints](../getting-started/concepts.md#model-accuracy-considerations-under-fhe-constraints) the accuracy of the model will depend heavily a well-chosen value `n_bits` and the dimensionality of the data. +The `KNeighborsClassifier` class quantizes the training data-set that is given to `.fit` with the specified number of bits, `n_bits`. As this value must be kept low to comply with [accumulator size constraints](../getting-started/concepts.md#model-accuracy-considerations-under-fhe-constraints) the accuracy of the model will depend heavily a well-chosen value `n_bits` and the dimensionality of the data. -The FHE inference latency of this model is heavily influenced by the `n_bits`, the dimensionality of the data. Furthermore, the size of the dataset has a linear impact on the complexity of the data and the number of nearest neighbors, `n_neighbors`, also plays a role. +The FHE inference latency of this model is heavily influenced by the `n_bits`, the dimensionality of the data. Furthermore, the size of the data-set has a linear impact on the complexity of the data and the number of nearest neighbors, `n_neighbors`, also plays a role. -The KNN computation executes in FHE in $$O(Nlog^2k)$$ steps, where $$N$$ is the training dataset size and $$k$$ is `n_neighbors`. Each step requires several PBS of the precision required to represent the distances between test vectors and the training dataset. +The KNN computation executes in FHE in $$O(Nlog^2k)$$ steps, where $$N$$ is the training data-set size and $$k$$ is `n_neighbors`. Each step requires several PBS of the precision required to represent the distances between test vectors and the training data-set. diff --git a/docs/built-in-models/neural-networks.md b/docs/built-in-models/neural-networks.md index fc3cd711d9..c13b406d24 100644 --- a/docs/built-in-models/neural-networks.md +++ b/docs/built-in-models/neural-networks.md @@ -54,7 +54,7 @@ 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 bitwidth 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) +- `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`: forces quantization scales to be powers-of-two, which, when coupled with the ReLU activation, benefits from strong FHE inference time optimization ### Training parameters (from skorch) diff --git a/docs/deep-learning/fhe_friendly_models.md b/docs/deep-learning/fhe_friendly_models.md index acc925c699..1c7cd59294 100644 --- a/docs/deep-learning/fhe_friendly_models.md +++ b/docs/deep-learning/fhe_friendly_models.md @@ -8,7 +8,7 @@ Regarding FHE-friendly neural networks, QAT is the best way to reach optimal acc 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_brevitas_finetuning/CifarQuantizationAwareTraining.ipynb). +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). This guide is based on a [notebook tutorial](../advanced_examples/QuantizationAwareTraining.ipynb), from which some code blocks are documented. diff --git a/docs/developer-guide/api/README.md b/docs/developer-guide/api/README.md index cb8750f4b4..b978180f26 100644 --- a/docs/developer-guide/api/README.md +++ b/docs/developer-guide/api/README.md @@ -42,6 +42,7 @@ - [`concrete.ml.sklearn.base`](./concrete.ml.sklearn.base.md#module-concretemlsklearnbase): Base classes for all estimators. - [`concrete.ml.sklearn.glm`](./concrete.ml.sklearn.glm.md#module-concretemlsklearnglm): Implement sklearn's Generalized Linear Models (GLM). - [`concrete.ml.sklearn.linear_model`](./concrete.ml.sklearn.linear_model.md#module-concretemlsklearnlinear_model): Implement sklearn linear model. +- [`concrete.ml.sklearn.neighbors`](./concrete.ml.sklearn.neighbors.md#module-concretemlsklearnneighbors): Implement sklearn linear model. - [`concrete.ml.sklearn.qnn`](./concrete.ml.sklearn.qnn.md#module-concretemlsklearnqnn): Scikit-learn interface for fully-connected quantized neural networks. - [`concrete.ml.sklearn.qnn_module`](./concrete.ml.sklearn.qnn_module.md#module-concretemlsklearnqnn_module): Sparse Quantized Neural Network torch module. - [`concrete.ml.sklearn.rf`](./concrete.ml.sklearn.rf.md#module-concretemlsklearnrf): Implement RandomForest models. @@ -175,6 +176,8 @@ - [`base.BaseTreeEstimatorMixin`](./concrete.ml.sklearn.base.md#class-basetreeestimatormixin): Mixin class for tree-based estimators. - [`base.BaseTreeRegressorMixin`](./concrete.ml.sklearn.base.md#class-basetreeregressormixin): Mixin class for tree-based regressors. - [`base.QuantizedTorchEstimatorMixin`](./concrete.ml.sklearn.base.md#class-quantizedtorchestimatormixin): Mixin that provides quantization for a torch module and follows the Estimator API. +- [`base.SklearnKNeighborsClassifierMixin`](./concrete.ml.sklearn.base.md#class-sklearnkneighborsclassifiermixin): A Mixin class for sklearn KNeighbors classifiers with FHE. +- [`base.SklearnKNeighborsMixin`](./concrete.ml.sklearn.base.md#class-sklearnkneighborsmixin): A Mixin class for sklearn KNeighbors models with FHE. - [`base.SklearnLinearClassifierMixin`](./concrete.ml.sklearn.base.md#class-sklearnlinearclassifiermixin): A Mixin class for sklearn linear classifiers with FHE. - [`base.SklearnLinearModelMixin`](./concrete.ml.sklearn.base.md#class-sklearnlinearmodelmixin): A Mixin class for sklearn linear models with FHE. - [`base.SklearnLinearRegressorMixin`](./concrete.ml.sklearn.base.md#class-sklearnlinearregressormixin): A Mixin class for sklearn linear regressors with FHE. @@ -186,6 +189,7 @@ - [`linear_model.LinearRegression`](./concrete.ml.sklearn.linear_model.md#class-linearregression): A linear regression model with FHE. - [`linear_model.LogisticRegression`](./concrete.ml.sklearn.linear_model.md#class-logisticregression): A logistic regression model with FHE. - [`linear_model.Ridge`](./concrete.ml.sklearn.linear_model.md#class-ridge): A Ridge regression model with FHE. +- [`neighbors.KNeighborsClassifier`](./concrete.ml.sklearn.neighbors.md#class-kneighborsclassifier): A k-nearest classifier model with FHE. - [`qnn.NeuralNetClassifier`](./concrete.ml.sklearn.qnn.md#class-neuralnetclassifier): A Fully-Connected Neural Network classifier with FHE. - [`qnn.NeuralNetRegressor`](./concrete.ml.sklearn.qnn.md#class-neuralnetregressor): A Fully-Connected Neural Network regressor with FHE. - [`qnn_module.SparseQuantNeuralNetwork`](./concrete.ml.sklearn.qnn_module.md#class-sparsequantneuralnetwork): Sparse Quantized Neural Network. @@ -197,6 +201,7 @@ - [`tree.DecisionTreeRegressor`](./concrete.ml.sklearn.tree.md#class-decisiontreeregressor): Implements the sklearn DecisionTreeClassifier. - [`xgb.XGBClassifier`](./concrete.ml.sklearn.xgb.md#class-xgbclassifier): Implements the XGBoost classifier. - [`xgb.XGBRegressor`](./concrete.ml.sklearn.xgb.md#class-xgbregressor): Implements the XGBoost regressor. +- [`hybrid_model.HybridFHEMode`](./concrete.ml.torch.hybrid_model.md#class-hybridfhemode): Simple enum for different modes of execution of HybridModel. - [`hybrid_model.HybridFHEModel`](./concrete.ml.torch.hybrid_model.md#class-hybridfhemodel): Convert a model to a hybrid model. - [`hybrid_model.RemoteModule`](./concrete.ml.torch.hybrid_model.md#class-remotemodule): A wrapper class for the modules to be done remotely with FHE. - [`numpy_module.NumpyModule`](./concrete.ml.torch.numpy_module.md#class-numpymodule): General interface to transform a torch.nn.Module to numpy module. @@ -250,8 +255,9 @@ - [`utils.filter_logs`](./concrete.ml.deployment.utils.md#function-filter_logs): Filter logs based on previous logs. - [`utils.is_connection_available`](./concrete.ml.deployment.utils.md#function-is_connection_available): Check if ssh connection is available. - [`utils.wait_for_connection_to_be_available`](./concrete.ml.deployment.utils.md#function-wait_for_connection_to_be_available): Wait for connection to be available. -- [`convert.get_equivalent_numpy_forward`](./concrete.ml.onnx.convert.md#function-get_equivalent_numpy_forward): Get the numpy equivalent forward of the provided ONNX model. -- [`convert.get_equivalent_numpy_forward_and_onnx_model`](./concrete.ml.onnx.convert.md#function-get_equivalent_numpy_forward_and_onnx_model): Get the numpy equivalent forward of the provided torch Module. +- [`convert.fuse_matmul_bias_to_gemm`](./concrete.ml.onnx.convert.md#function-fuse_matmul_bias_to_gemm): Fuse sequence of matmul -> add into a gemm node. +- [`convert.get_equivalent_numpy_forward_from_onnx`](./concrete.ml.onnx.convert.md#function-get_equivalent_numpy_forward_from_onnx): Get the numpy equivalent forward of the provided ONNX model. +- [`convert.get_equivalent_numpy_forward_from_torch`](./concrete.ml.onnx.convert.md#function-get_equivalent_numpy_forward_from_torch): Get the numpy equivalent forward of the provided torch Module. - [`onnx_impl_utils.compute_conv_output_dims`](./concrete.ml.onnx.onnx_impl_utils.md#function-compute_conv_output_dims): Compute the output shape of a pool or conv operation. - [`onnx_impl_utils.compute_onnx_pool_padding`](./concrete.ml.onnx.onnx_impl_utils.md#function-compute_onnx_pool_padding): Compute any additional padding needed to compute pooling layers. - [`onnx_impl_utils.numpy_onnx_pad`](./concrete.ml.onnx.onnx_impl_utils.md#function-numpy_onnx_pad): Pad a tensor according to ONNX spec, using an optional custom pad value. @@ -345,6 +351,7 @@ - [`p_error_search.compile_and_simulated_fhe_inference`](./concrete.ml.search_parameters.p_error_search.md#function-compile_and_simulated_fhe_inference): Get the quantized module of a given model in FHE, simulated or not. - [`sklearn.get_sklearn_linear_models`](./concrete.ml.sklearn.md#function-get_sklearn_linear_models): Return the list of available linear models in Concrete ML. - [`sklearn.get_sklearn_models`](./concrete.ml.sklearn.md#function-get_sklearn_models): Return the list of available models in Concrete ML. +- [`sklearn.get_sklearn_neighbors_models`](./concrete.ml.sklearn.md#function-get_sklearn_neighbors_models): Return the list of available neighbor models in Concrete ML. - [`sklearn.get_sklearn_neural_net_models`](./concrete.ml.sklearn.md#function-get_sklearn_neural_net_models): Return the list of available neural net models in Concrete ML. - [`sklearn.get_sklearn_tree_models`](./concrete.ml.sklearn.md#function-get_sklearn_tree_models): Return the list of available tree models in Concrete ML. - [`tree_to_numpy.add_transpose_after_last_node`](./concrete.ml.sklearn.tree_to_numpy.md#function-add_transpose_after_last_node): Add transpose after last node. @@ -360,3 +367,4 @@ - [`compile.compile_torch_model`](./concrete.ml.torch.compile.md#function-compile_torch_model): Compile a torch module into an FHE equivalent. - [`compile.convert_torch_tensor_or_numpy_array_to_numpy_array`](./concrete.ml.torch.compile.md#function-convert_torch_tensor_or_numpy_array_to_numpy_array): Convert a torch tensor or a numpy array to a numpy array. - [`hybrid_model.convert_conv1d_to_linear`](./concrete.ml.torch.hybrid_model.md#function-convert_conv1d_to_linear): Convert all Conv1D layers in a module or a Conv1D layer itself to nn.Linear. +- [`hybrid_model.tuple_to_underscore_str`](./concrete.ml.torch.hybrid_model.md#function-tuple_to_underscore_str): Convert a tuple to a string representation. diff --git a/docs/developer-guide/api/concrete.ml.common.serialization.decoder.md b/docs/developer-guide/api/concrete.ml.common.serialization.decoder.md index f381a65ed1..15b94b5e2e 100644 --- a/docs/developer-guide/api/concrete.ml.common.serialization.decoder.md +++ b/docs/developer-guide/api/concrete.ml.common.serialization.decoder.md @@ -16,7 +16,7 @@ Custom decoder for serialization. ______________________________________________________________________ - + ## function `object_hook` @@ -42,13 +42,13 @@ If the input's type is non-native, then we expect it to have the following forma ______________________________________________________________________ - + ## class `ConcreteDecoder` Custom json decoder to handle non-native types found in serialized Concrete ML objects. - + ### method `__init__` diff --git a/docs/developer-guide/api/concrete.ml.common.utils.md b/docs/developer-guide/api/concrete.ml.common.utils.md index ab287dc134..d8efaff262 100644 --- a/docs/developer-guide/api/concrete.ml.common.utils.md +++ b/docs/developer-guide/api/concrete.ml.common.utils.md @@ -13,10 +13,11 @@ Utils that can be re-used by other pieces of code in the module. - **SUPPORTED_TYPES** - **MAX_BITWIDTH_BACKWARD_COMPATIBLE** - **USE_OLD_VL** +- **QUANT_ROUND_LIKE_ROUND_PBS** ______________________________________________________________________ - + ## function `replace_invalid_arg_name_chars` @@ -38,7 +39,7 @@ This does not check that the starting character of arg_name is valid. ______________________________________________________________________ - + ## function `generate_proxy_function` @@ -64,7 +65,7 @@ This returns a runtime compiled function with the sanitized argument names passe ______________________________________________________________________ - + ## function `get_onnx_opset_version` @@ -84,7 +85,7 @@ Return the ONNX opset_version. ______________________________________________________________________ - + ## function `manage_parameters_for_pbs_errors` @@ -121,7 +122,7 @@ Note that global_p_error is currently set to 0 in the FHE simulation mode. ______________________________________________________________________ - + ## function `check_there_is_no_p_error_options_in_configuration` @@ -139,7 +140,7 @@ It would be dangerous, since we set them in direct arguments in our calls to Con ______________________________________________________________________ - + ## function `get_model_class` @@ -158,7 +159,7 @@ The model's class. ______________________________________________________________________ - + ## function `is_model_class_in_a_list` @@ -178,7 +179,7 @@ If the model's class is in the list or not. ______________________________________________________________________ - + ## function `get_model_name` @@ -197,7 +198,7 @@ the model's name. ______________________________________________________________________ - + ## function `is_classifier_or_partial_classifier` @@ -217,7 +218,7 @@ Indicate if the model class represents a classifier. ______________________________________________________________________ - + ## function `is_regressor_or_partial_regressor` @@ -237,7 +238,7 @@ Indicate if the model class represents a regressor. ______________________________________________________________________ - + ## function `is_pandas_dataframe` @@ -259,7 +260,7 @@ This function is inspired from Scikit-Learn's test validation tools and avoids t ______________________________________________________________________ - + ## function `is_pandas_series` @@ -281,7 +282,7 @@ This function is inspired from Scikit-Learn's test validation tools and avoids t ______________________________________________________________________ - + ## function `is_pandas_type` @@ -301,7 +302,7 @@ Indicate if the input container is a Pandas DataFrame or Series. ______________________________________________________________________ - + ## function `check_dtype_and_cast` @@ -333,7 +334,7 @@ If values types don't match with any supported type or the expected dtype, raise ______________________________________________________________________ - + ## function `compute_bits_precision` @@ -353,7 +354,7 @@ Compute the number of bits required to represent x. ______________________________________________________________________ - + ## function `is_brevitas_model` @@ -373,7 +374,7 @@ Check if a model is a Brevitas type. ______________________________________________________________________ - + ## function `to_tuple` @@ -393,7 +394,7 @@ Make the input a tuple if it is not already the case. ______________________________________________________________________ - + ## function `all_values_are_integers` @@ -413,7 +414,7 @@ Indicate if all unpacked values are of a supported integer dtype. ______________________________________________________________________ - + ## function `all_values_are_floats` @@ -433,7 +434,7 @@ Indicate if all unpacked values are of a supported float dtype. ______________________________________________________________________ - + ## function `all_values_are_of_dtype` @@ -454,7 +455,7 @@ Indicate if all unpacked values are of the specified dtype(s). ______________________________________________________________________ - + ## function `set_multi_parameter_in_configuration` @@ -480,7 +481,7 @@ If the given Configuration instance is not None and the parameter strategy is se ______________________________________________________________________ - + ## function `force_mono_parameter_in_configuration` @@ -506,7 +507,7 @@ If the given Configuration instance is None, build a new instance with mono-para ______________________________________________________________________ - + ## class `FheMode` diff --git a/docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md b/docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md index 73cf8545f3..983e13748f 100644 --- a/docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md +++ b/docs/developer-guide/api/concrete.ml.deployment.fhe_client_server.md @@ -50,7 +50,7 @@ Load the circuit. ______________________________________________________________________ - + ### method `run` @@ -74,13 +74,13 @@ Run the model on the server over encrypted data. ______________________________________________________________________ - + ## class `FHEModelDev` Dev API to save the model and then load and run the FHE circuit. - + ### method `__init__` @@ -97,7 +97,7 @@ Initialize the FHE API. ______________________________________________________________________ - + ### method `save` @@ -140,7 +140,7 @@ Initialize the FHE API. ______________________________________________________________________ - + ### method `deserialize_decrypt` @@ -160,7 +160,7 @@ Deserialize and decrypt the values. ______________________________________________________________________ - + ### method `deserialize_decrypt_dequantize` @@ -182,7 +182,7 @@ Deserialize, decrypt and de-quantize the values. ______________________________________________________________________ - + ### method `generate_private_and_evaluation_keys` @@ -198,7 +198,7 @@ Generate the private and evaluation keys. ______________________________________________________________________ - + ### method `get_serialized_evaluation_keys` @@ -230,7 +230,7 @@ Load the quantizers along with the FHE specs. ______________________________________________________________________ - + ### method `quantize_encrypt_serialize` diff --git a/docs/developer-guide/api/concrete.ml.onnx.convert.md b/docs/developer-guide/api/concrete.ml.onnx.convert.md index 74fc9b1fce..53a0c820a8 100644 --- a/docs/developer-guide/api/concrete.ml.onnx.convert.md +++ b/docs/developer-guide/api/concrete.ml.onnx.convert.md @@ -13,16 +13,36 @@ ONNX conversion related code. ______________________________________________________________________ - + -## function `get_equivalent_numpy_forward_and_onnx_model` +## function `fuse_matmul_bias_to_gemm` ```python -get_equivalent_numpy_forward_and_onnx_model( +fuse_matmul_bias_to_gemm(onnx_model: ModelProto) +``` + +Fuse sequence of matmul -> add into a gemm node. + +**Args:** + +- `onnx_model` (onnx.ModelProto): A onnx model to optimize using Mat-Mult + Add -> Gemm + +**Returns:** + +- `onnx.ModelProto`: the optimized onnx model + +______________________________________________________________________ + + + +## function `get_equivalent_numpy_forward_from_torch` + +```python +get_equivalent_numpy_forward_from_torch( torch_module: Module, dummy_input: Union[Tensor, Tuple[Tensor, ]], - output_onnx_file: Optional[Path, str] = None -) → Tuple[Callable[, Tuple[ndarray, ]], GraphProto] + output_onnx_file: Union[NoneType, Path, str] = None +) → Tuple[Callable[, Tuple[ndarray, ]], ModelProto] ``` Get the numpy equivalent forward of the provided torch Module. @@ -39,15 +59,15 @@ Get the numpy equivalent forward of the provided torch Module. ______________________________________________________________________ - + -## function `get_equivalent_numpy_forward` +## function `get_equivalent_numpy_forward_from_onnx` ```python -get_equivalent_numpy_forward( +get_equivalent_numpy_forward_from_onnx( onnx_model: ModelProto, check_model: bool = True -) → Callable[, Tuple[ndarray, ]] +) → Tuple[Callable[, Tuple[ndarray, ]], ModelProto] ``` Get the numpy equivalent forward of the provided ONNX model. diff --git a/docs/developer-guide/api/concrete.ml.onnx.ops_impl.md b/docs/developer-guide/api/concrete.ml.onnx.ops_impl.md index 2e8511ed0a..b1e003e0e2 100644 --- a/docs/developer-guide/api/concrete.ml.onnx.ops_impl.md +++ b/docs/developer-guide/api/concrete.ml.onnx.ops_impl.md @@ -8,7 +8,7 @@ ONNX ops implementation in Python + NumPy. ______________________________________________________________________ - + ## function `cast_to_float` @@ -28,7 +28,7 @@ Cast values to floating points. ______________________________________________________________________ - + ## function `onnx_func_raw_args` @@ -49,7 +49,7 @@ Decorate a numpy onnx function to flag the raw/non quantized inputs. ______________________________________________________________________ - + ## function `numpy_where_body` @@ -73,7 +73,7 @@ This function is not mapped to any ONNX operator (as opposed to numpy_where). It ______________________________________________________________________ - + ## function `numpy_where` @@ -95,7 +95,7 @@ Compute the equivalent of numpy.where. ______________________________________________________________________ - + ## function `numpy_add` @@ -118,7 +118,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Add-13 ______________________________________________________________________ - + ## function `numpy_constant` @@ -140,7 +140,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Constant-13 ______________________________________________________________________ - + ## function `numpy_gemm` @@ -176,7 +176,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Gemm-13 ______________________________________________________________________ - + ## function `numpy_matmul` @@ -199,7 +199,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#MatMul-13 ______________________________________________________________________ - + ## function `numpy_relu` @@ -221,7 +221,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Relu-14 ______________________________________________________________________ - + ## function `numpy_sigmoid` @@ -243,7 +243,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sigmoid-13 ______________________________________________________________________ - + ## function `numpy_softmax` @@ -269,7 +269,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#softmax-13 ______________________________________________________________________ - + ## function `numpy_cos` @@ -291,7 +291,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Cos-7 ______________________________________________________________________ - + ## function `numpy_cosh` @@ -313,7 +313,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Cosh-9 ______________________________________________________________________ - + ## function `numpy_sin` @@ -335,7 +335,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sin-7 ______________________________________________________________________ - + ## function `numpy_sinh` @@ -357,7 +357,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sinh-9 ______________________________________________________________________ - + ## function `numpy_tan` @@ -379,7 +379,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Tan-7 ______________________________________________________________________ - + ## function `numpy_tanh` @@ -401,7 +401,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Tanh-13 ______________________________________________________________________ - + ## function `numpy_acos` @@ -423,7 +423,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Acos-7 ______________________________________________________________________ - + ## function `numpy_acosh` @@ -445,7 +445,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Acosh-9 ______________________________________________________________________ - + ## function `numpy_asin` @@ -467,7 +467,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Asin-7 ______________________________________________________________________ - + ## function `numpy_asinh` @@ -489,7 +489,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Asinh-9 ______________________________________________________________________ - + ## function `numpy_atan` @@ -511,7 +511,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Atan-7 ______________________________________________________________________ - + ## function `numpy_atanh` @@ -533,7 +533,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Atanh-9 ______________________________________________________________________ - + ## function `numpy_elu` @@ -556,7 +556,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Elu-6 ______________________________________________________________________ - + ## function `numpy_selu` @@ -584,7 +584,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Selu-6 ______________________________________________________________________ - + ## function `numpy_celu` @@ -607,7 +607,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Celu-12 ______________________________________________________________________ - + ## function `numpy_leakyrelu` @@ -630,7 +630,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#LeakyRelu-6 ______________________________________________________________________ - + ## function `numpy_thresholdedrelu` @@ -653,7 +653,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#ThresholdedRelu-10 ______________________________________________________________________ - + ## function `numpy_hardsigmoid` @@ -681,7 +681,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#HardSigmoid-6 ______________________________________________________________________ - + ## function `numpy_softplus` @@ -703,7 +703,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Softplus-1 ______________________________________________________________________ - + ## function `numpy_abs` @@ -725,7 +725,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Abs-13 ______________________________________________________________________ - + ## function `numpy_div` @@ -748,7 +748,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Div-14 ______________________________________________________________________ - + ## function `numpy_mul` @@ -771,7 +771,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Mul-14 ______________________________________________________________________ - + ## function `numpy_sub` @@ -794,7 +794,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sub-14 ______________________________________________________________________ - + ## function `numpy_log` @@ -816,7 +816,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Log-13 ______________________________________________________________________ - + ## function `numpy_erf` @@ -838,7 +838,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Erf-13 ______________________________________________________________________ - + ## function `numpy_hardswish` @@ -860,7 +860,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#hardswish-14 ______________________________________________________________________ - + ## function `numpy_exp` @@ -882,7 +882,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Exp-13 ______________________________________________________________________ - + ## function `numpy_equal` @@ -905,7 +905,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Equal-11 ______________________________________________________________________ - + ## function `numpy_not` @@ -927,7 +927,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Not-1 ______________________________________________________________________ - + ## function `numpy_not_float` @@ -949,7 +949,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Not-1 ______________________________________________________________________ - + ## function `numpy_greater` @@ -972,7 +972,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Greater-13 ______________________________________________________________________ - + ## function `numpy_greater_float` @@ -995,7 +995,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Greater-13 ______________________________________________________________________ - + ## function `numpy_greater_or_equal` @@ -1018,7 +1018,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#GreaterOrEqual-12 ______________________________________________________________________ - + ## function `numpy_greater_or_equal_float` @@ -1041,7 +1041,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#GreaterOrEqual-12 ______________________________________________________________________ - + ## function `numpy_less` @@ -1064,7 +1064,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Less-13 ______________________________________________________________________ - + ## function `numpy_less_float` @@ -1087,7 +1087,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Less-13 ______________________________________________________________________ - + ## function `numpy_less_or_equal` @@ -1110,7 +1110,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#LessOrEqual-12 ______________________________________________________________________ - + ## function `numpy_less_or_equal_float` @@ -1133,7 +1133,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#LessOrEqual-12 ______________________________________________________________________ - + ## function `numpy_identity` @@ -1155,7 +1155,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Identity-14 ______________________________________________________________________ - + ## function `numpy_transpose` @@ -1178,7 +1178,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Transpose-13 ______________________________________________________________________ - + ## function `numpy_conv` @@ -1219,7 +1219,7 @@ See: https://github.com/onnx/onnx/blob/main/docs/Operators.md#Conv ______________________________________________________________________ - + ## function `numpy_avgpool` @@ -1258,7 +1258,7 @@ See: https://github.com/onnx/onnx/blob/main/docs/Operators.md#AveragePool ______________________________________________________________________ - + ## function `numpy_maxpool` @@ -1299,7 +1299,7 @@ See: https://github.com/onnx/onnx/blob/main/docs/Operators.md#MaxPool ______________________________________________________________________ - + ## function `numpy_cast` @@ -1324,7 +1324,7 @@ See: https://github.com/onnx/onnx/blob/main/docs/Operators.md#Cast ______________________________________________________________________ - + ## function `numpy_batchnorm` @@ -1366,7 +1366,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#BatchNormalization- ______________________________________________________________________ - + ## function `numpy_flatten` @@ -1389,7 +1389,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Flatten-13. ______________________________________________________________________ - + ## function `numpy_or` @@ -1412,7 +1412,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Or-7 ______________________________________________________________________ - + ## function `numpy_or_float` @@ -1435,7 +1435,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Or-7 ______________________________________________________________________ - + ## function `numpy_round` @@ -1457,7 +1457,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Round-11 Remark tha ______________________________________________________________________ - + ## function `numpy_pow` @@ -1480,7 +1480,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Pow-13 ______________________________________________________________________ - + ## function `numpy_floor` @@ -1502,7 +1502,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Floor-1 ______________________________________________________________________ - + ## function `numpy_max` @@ -1527,7 +1527,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Max-1 ______________________________________________________________________ - + ## function `numpy_min` @@ -1552,7 +1552,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Max-1 ______________________________________________________________________ - + ## function `numpy_sign` @@ -1574,7 +1574,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sign-9 ______________________________________________________________________ - + ## function `numpy_neg` @@ -1596,7 +1596,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#Sign-9 ______________________________________________________________________ - + ## function `numpy_concatenate` @@ -1619,7 +1619,7 @@ See https://github.com/onnx/onnx/blob/main/docs/Changelog.md#concat-13 ______________________________________________________________________ - + ## class `RawOpOutput` @@ -1627,7 +1627,7 @@ Type construct that marks an ndarray as a raw output of a quantized op. ______________________________________________________________________ - + ## class `ONNXMixedFunction` @@ -1635,7 +1635,7 @@ A mixed quantized-raw valued onnx function. ONNX functions will take inputs which can be either quantized or float. Some functions only take quantized inputs, but some functions take both types. For mixed functions we need to tag the parameters that do not need quantization. Thus quantized ops can know which inputs are not QuantizedArray and we avoid unnecessary wrapping of float values as QuantizedArrays. - + ### method `__init__` diff --git a/docs/developer-guide/api/concrete.ml.pytest.torch_models.md b/docs/developer-guide/api/concrete.ml.pytest.torch_models.md index 88d054e336..a2489e0c4c 100644 --- a/docs/developer-guide/api/concrete.ml.pytest.torch_models.md +++ b/docs/developer-guide/api/concrete.ml.pytest.torch_models.md @@ -797,11 +797,11 @@ Construct the CNN with a configurable number of classes. - `n_active` (int): number of active (non-zero weight) neurons to keep - `signed` (bool): whether quantized integer values are signed - `narrow` (bool): whether the range of quantized integer values is narrow/symmetric -- `power_of_two_scaling` (bool): whether to use power-of-two scaling quantizers +- `power_of_two_scaling` (bool): whether to use power-of-two scaling quantizers which allows to test the round PBS optimization when the scales are power-of-two ______________________________________________________________________ - + ### method `forward` @@ -820,7 +820,7 @@ the output of the NN ______________________________________________________________________ - + ### method `toggle_pruning` @@ -836,13 +836,13 @@ Enable or remove pruning. ______________________________________________________________________ - + ## class `SimpleQAT` Torch model implements a step function that needs Greater, Cast and Where. - + ### method `__init__` @@ -852,7 +852,7 @@ __init__(input_output, activation_function, n_bits=2, disable_bit_check=False) ______________________________________________________________________ - + ### method `forward` @@ -871,13 +871,13 @@ the output of the NN ______________________________________________________________________ - + ## class `QATTestModule` Torch model that implements a simple non-uniform quantizer. - + ### method `__init__` @@ -887,7 +887,7 @@ __init__(activation_function) ______________________________________________________________________ - + ### method `forward` @@ -906,13 +906,13 @@ the output of the NN ______________________________________________________________________ - + ## class `SingleMixNet` Torch model that with a single conv layer that produces the output, e.g., a blur filter. - + ### method `__init__` @@ -922,7 +922,7 @@ __init__(use_conv, use_qat, inp_size, n_bits) ______________________________________________________________________ - + ### method `forward` @@ -941,7 +941,7 @@ the output of the NN ______________________________________________________________________ - + ## class `DoubleQuantQATMixNet` @@ -949,7 +949,7 @@ Torch model that with two different quantizers on the input. Used to test that it keeps the input TLU. - + ### method `__init__` @@ -959,7 +959,7 @@ __init__(use_conv, use_qat, inp_size, n_bits) ______________________________________________________________________ - + ### method `forward` @@ -978,13 +978,13 @@ the output of the NN ______________________________________________________________________ - + ## class `TorchSum` Torch model to test the ReduceSum ONNX operator in a leveled circuit. - + ### method `__init__` @@ -1001,7 +1001,7 @@ Initialize the module. ______________________________________________________________________ - + ### method `forward` @@ -1021,13 +1021,13 @@ Forward pass. ______________________________________________________________________ - + ## class `TorchSumMod` Torch model to test the ReduceSum ONNX operator in a circuit containing a PBS. - + ### method `__init__` @@ -1044,7 +1044,7 @@ Initialize the module. ______________________________________________________________________ - + ### method `forward` @@ -1064,13 +1064,13 @@ Forward pass. ______________________________________________________________________ - + ## class `NetWithConstantsFoldedBeforeOps` Torch QAT model that does not quantize the inputs. - + ### method `__init__` @@ -1085,7 +1085,7 @@ __init__( ______________________________________________________________________ - + ### method `forward` @@ -1105,13 +1105,13 @@ Forward pass. ______________________________________________________________________ - + ## class `ShapeOperationsNet` Torch QAT model that reshapes the input. - + ### method `__init__` @@ -1121,7 +1121,7 @@ __init__(is_qat) ______________________________________________________________________ - + ### method `forward` @@ -1141,13 +1141,13 @@ Forward pass. ______________________________________________________________________ - + ## class `PaddingNet` Torch QAT model that applies various padding patterns. - + ### method `__init__` @@ -1157,7 +1157,7 @@ __init__() ______________________________________________________________________ - + ### method `forward` @@ -1177,13 +1177,13 @@ Forward pass. ______________________________________________________________________ - + ## class `QuantCustomModel` A small quantized network with Brevitas, trained on make_classification. - + ### method `__init__` @@ -1213,7 +1213,7 @@ Quantized Torch Model with Brevitas. ______________________________________________________________________ - + ### method `forward` @@ -1233,13 +1233,13 @@ Forward pass. ______________________________________________________________________ - + ## class `TorchCustomModel` A small network with Brevitas, trained on make_classification. - + ### method `__init__` @@ -1257,7 +1257,7 @@ Torch Model. ______________________________________________________________________ - + ### method `forward` @@ -1277,13 +1277,13 @@ Forward pass. ______________________________________________________________________ - + ## class `ConcatFancyIndexing` Concat with fancy indexing. - + ### method `__init__` @@ -1309,7 +1309,7 @@ Torch Model. ______________________________________________________________________ - + ### method `forward` diff --git a/docs/developer-guide/api/concrete.ml.pytest.utils.md b/docs/developer-guide/api/concrete.ml.pytest.utils.md index 82f661ab54..eab94bada5 100644 --- a/docs/developer-guide/api/concrete.ml.pytest.utils.md +++ b/docs/developer-guide/api/concrete.ml.pytest.utils.md @@ -12,7 +12,7 @@ Common functions or lists for test files, which can't be put in fixtures. ______________________________________________________________________ - + ## function `get_random_extract_of_sklearn_models_and_datasets` @@ -29,7 +29,7 @@ the sublist ______________________________________________________________________ - + ## function `instantiate_model_generic` @@ -52,7 +52,7 @@ Instantiate any Concrete ML model type. ______________________________________________________________________ - + ## function `data_calibration_processing` @@ -78,7 +78,7 @@ Reduce size of the given data-set. ______________________________________________________________________ - + ## function `load_torch_model` @@ -106,7 +106,7 @@ Load an object saved with torch.save() from a file or dict. ______________________________________________________________________ - + ## function `values_are_equal` @@ -129,7 +129,7 @@ This method takes into account objects of type None, numpy.ndarray, numpy.floati ______________________________________________________________________ - + ## function `check_serialization` diff --git a/docs/developer-guide/api/concrete.ml.quantization.post_training.md b/docs/developer-guide/api/concrete.ml.quantization.post_training.md index 0ac4b03c90..8dbee4aae4 100644 --- a/docs/developer-guide/api/concrete.ml.quantization.post_training.md +++ b/docs/developer-guide/api/concrete.ml.quantization.post_training.md @@ -108,7 +108,7 @@ Get the number of bits to use for the quantization of any constants (usually wei ______________________________________________________________________ - + ### method `quantize_module` @@ -130,7 +130,7 @@ Following https://arxiv.org/abs/1712.05877 guidelines. ______________________________________________________________________ - + ## class `PostTrainingAffineQuantization` @@ -207,7 +207,7 @@ Get the number of bits to use for the quantization of any constants (usually wei ______________________________________________________________________ - + ### method `quantize_module` @@ -229,7 +229,7 @@ Following https://arxiv.org/abs/1712.05877 guidelines. ______________________________________________________________________ - + ## class `PostTrainingQATImporter` @@ -291,7 +291,7 @@ Get the number of bits to use for the quantization of any constants (usually wei ______________________________________________________________________ - + ### method `quantize_module` diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md b/docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md index 56c78602aa..205e213a68 100644 --- a/docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md +++ b/docs/developer-guide/api/concrete.ml.quantization.quantized_module_passes.md @@ -54,7 +54,7 @@ Stores, for each quantized op, a list of quantized ops that produce its inputs. ______________________________________________________________________ - + ### method `detect_patterns` @@ -122,7 +122,7 @@ Nothing will be done if rounding is already specified. ______________________________________________________________________ - + ### method `process_patterns` diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md b/docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md index e1b6d71662..5f9031e49b 100644 --- a/docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md +++ b/docs/developer-guide/api/concrete.ml.quantization.quantized_ops.md @@ -273,7 +273,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedMatMul` @@ -320,7 +320,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedAdd` @@ -340,7 +340,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -358,7 +358,7 @@ Add operation can be computed in float and fused if it operates over inputs prod ______________________________________________________________________ - + ### method `q_impl` @@ -371,7 +371,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedTanh` @@ -389,7 +389,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedSoftplus` @@ -407,7 +407,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedExp` @@ -425,7 +425,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedLog` @@ -443,7 +443,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedAbs` @@ -461,7 +461,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedIdentity` @@ -479,7 +479,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `q_impl` @@ -492,7 +492,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedReshape` @@ -510,7 +510,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -528,7 +528,7 @@ Max Pooling operation can not be fused since it must be performed over integer t ______________________________________________________________________ - + ### method `q_impl` @@ -552,13 +552,13 @@ Reshape the input integer encrypted tensor. ______________________________________________________________________ - + ## class `QuantizedConv` Quantized Conv op. - + ### method `__init__` @@ -601,7 +601,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `q_impl` @@ -632,13 +632,13 @@ Allows an optional quantized bias. ______________________________________________________________________ - + ## class `QuantizedAvgPool` Quantized Average Pooling op. - + ### method `__init__` @@ -665,7 +665,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `q_impl` @@ -679,13 +679,13 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedMaxPool` Quantized Max Pooling op. - + ### method `__init__` @@ -712,7 +712,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -730,7 +730,7 @@ Max Pooling operation can not be fused since it must be performed over integer t ______________________________________________________________________ - + ### method `q_impl` @@ -743,13 +743,13 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedPad` Quantized Padding op. - + ### method `__init__` @@ -776,7 +776,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -794,7 +794,7 @@ Pad operation cannot be fused since it must be performed over integer tensors. ______________________________________________________________________ - + ### method `q_impl` @@ -808,7 +808,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedWhere` @@ -816,7 +816,7 @@ Where operator on quantized arrays. Supports only constants for the results produced on the True/False branches. - + ### method `__init__` @@ -843,7 +843,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedCast` @@ -863,7 +863,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedGreater` @@ -871,7 +871,7 @@ Comparison operator >. Only supports comparison with a constant. - + ### method `__init__` @@ -898,7 +898,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedGreaterOrEqual` @@ -906,7 +906,7 @@ Comparison operator >=. Only supports comparison with a constant. - + ### method `__init__` @@ -933,7 +933,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedLess` @@ -941,7 +941,7 @@ Comparison operator \<. Only supports comparison with a constant. - + ### method `__init__` @@ -968,7 +968,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedLessOrEqual` @@ -976,7 +976,7 @@ Comparison operator \<=. Only supports comparison with a constant. - + ### method `__init__` @@ -1003,7 +1003,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedOr` @@ -1023,7 +1023,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedDiv` @@ -1043,7 +1043,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedMul` @@ -1063,7 +1063,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedSub` @@ -1083,7 +1083,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1101,7 +1101,7 @@ Add operation can be computed in float and fused if it operates over inputs prod ______________________________________________________________________ - + ### method `q_impl` @@ -1114,7 +1114,7 @@ q_impl( ______________________________________________________________________ - + ## class `QuantizedBatchNormalization` @@ -1132,7 +1132,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedFlatten` @@ -1150,7 +1150,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1168,7 +1168,7 @@ Flatten operation cannot be fused since it must be performed over integer tensor ______________________________________________________________________ - + ### method `q_impl` @@ -1192,13 +1192,13 @@ Flatten the input integer encrypted tensor. ______________________________________________________________________ - + ## class `QuantizedReduceSum` ReduceSum with encrypted input. - + ### method `__init__` @@ -1239,7 +1239,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `calibrate` @@ -1259,7 +1259,7 @@ Create corresponding QuantizedArray for the output of the activation function. ______________________________________________________________________ - + ### method `q_impl` @@ -1283,7 +1283,7 @@ Sum the encrypted tensor's values along the given axes. ______________________________________________________________________ - + ## class `QuantizedErf` @@ -1301,7 +1301,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedNot` @@ -1319,13 +1319,13 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedBrevitasQuant` Brevitas uniform quantization with encrypted input. - + ### method `__init__` @@ -1368,7 +1368,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `calibrate` @@ -1388,7 +1388,7 @@ Create corresponding QuantizedArray for the output of Quantization function. ______________________________________________________________________ - + ### method `q_impl` @@ -1412,7 +1412,7 @@ Quantize values. ______________________________________________________________________ - + ## class `QuantizedTranspose` @@ -1432,7 +1432,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1450,7 +1450,7 @@ Transpose can not be fused since it must be performed over integer tensors as it ______________________________________________________________________ - + ### method `q_impl` @@ -1474,7 +1474,7 @@ Transpose the input integer encrypted tensor. ______________________________________________________________________ - + ## class `QuantizedFloor` @@ -1492,7 +1492,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedMax` @@ -1510,7 +1510,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedMin` @@ -1528,7 +1528,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedNeg` @@ -1546,7 +1546,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedSign` @@ -1564,7 +1564,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ## class `QuantizedUnsqueeze` @@ -1582,7 +1582,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1600,7 +1600,7 @@ Unsqueeze can not be fused since it must be performed over integer tensors as it ______________________________________________________________________ - + ### method `q_impl` @@ -1624,7 +1624,7 @@ Unsqueeze the input tensors on a given axis. ______________________________________________________________________ - + ## class `QuantizedConcat` @@ -1642,7 +1642,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1660,7 +1660,7 @@ Concatenation can not be fused since it must be performed over integer tensors a ______________________________________________________________________ - + ### method `q_impl` @@ -1684,7 +1684,7 @@ Concatenate the input tensors on a given axis. ______________________________________________________________________ - + ## class `QuantizedSqueeze` @@ -1702,7 +1702,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1720,7 +1720,7 @@ Squeeze can not be fused since it must be performed over integer tensors as it r ______________________________________________________________________ - + ### method `q_impl` @@ -1744,7 +1744,7 @@ Squeeze the input tensors on a given axis. ______________________________________________________________________ - + ## class `ONNXShape` @@ -1762,7 +1762,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1780,7 +1780,7 @@ This operation returns the shape of the tensor and thus can not be fused into a ______________________________________________________________________ - + ### method `q_impl` @@ -1793,7 +1793,7 @@ q_impl( ______________________________________________________________________ - + ## class `ONNXConstantOfShape` @@ -1811,7 +1811,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1829,7 +1829,7 @@ This operation returns a new encrypted tensor and thus can not be fused. ______________________________________________________________________ - + ## class `ONNXGather` @@ -1849,7 +1849,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1867,7 +1867,7 @@ This operation returns values from a tensor and thus can not be fused into a uni ______________________________________________________________________ - + ### method `q_impl` @@ -1880,7 +1880,7 @@ q_impl( ______________________________________________________________________ - + ## class `ONNXSlice` @@ -1898,7 +1898,7 @@ Get the names of encrypted integer tensors that are used by this op. ______________________________________________________________________ - + ### method `can_fuse` @@ -1916,7 +1916,7 @@ This operation returns values from a tensor and thus can not be fused into a uni ______________________________________________________________________ - + ### method `q_impl` diff --git a/docs/developer-guide/api/concrete.ml.quantization.quantizers.md b/docs/developer-guide/api/concrete.ml.quantization.quantizers.md index faa278d51d..054d925de5 100644 --- a/docs/developer-guide/api/concrete.ml.quantization.quantizers.md +++ b/docs/developer-guide/api/concrete.ml.quantization.quantizers.md @@ -12,7 +12,7 @@ Quantization utilities for a numpy array/tensor. ______________________________________________________________________ - + ## function `fill_from_kwargs` @@ -39,7 +39,7 @@ Fill a parameter set structure from kwargs parameters. ______________________________________________________________________ - + ## class `QuantizationOptions` @@ -47,7 +47,7 @@ Options for quantization. Determines the number of bits for quantization and the method of quantization of the values. Signed quantization allows negative quantized values. Symmetric quantization assumes the float values are distributed symmetrically around x=0 and assigns signed values around 0 to the float values. QAT (quantization aware training) quantization assumes the values are already quantized, taking a discrete set of values, and assigns these values to integers, computing only the scale. - + ### method `__init__` @@ -72,7 +72,7 @@ Get a copy of the quantization parameters. ______________________________________________________________________ - + ### method `copy_opts` @@ -88,7 +88,7 @@ Copy the options from a different structure. ______________________________________________________________________ - + ### method `dump` @@ -104,7 +104,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -120,7 +120,7 @@ Dump itself to a dict. ______________________________________________________________________ - + ### method `dumps` @@ -136,7 +136,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `is_equal` @@ -157,7 +157,7 @@ Compare two quantization options sets. ______________________________________________________________________ - + ### method `load_dict` @@ -177,7 +177,7 @@ Load itself from a string. ______________________________________________________________________ - + ## class `MinMaxQuantizationStats` @@ -185,7 +185,7 @@ Calibration set statistics. This class stores the statistics for the calibration set or for a calibration data batch. Currently we only store min/max to determine the quantization range. The min/max are computed from the calibration set. - + ### method `__init__` @@ -209,7 +209,7 @@ Get a copy of the calibration set statistics. ______________________________________________________________________ - + ### method `check_is_uniform_quantized` @@ -231,7 +231,7 @@ Determines whether the values represented by this QuantizedArray show a quantize ______________________________________________________________________ - + ### method `compute_quantization_stats` @@ -247,7 +247,7 @@ Compute the calibration set quantization statistics. ______________________________________________________________________ - + ### method `copy_stats` @@ -263,7 +263,7 @@ Copy the statistics from a different structure. ______________________________________________________________________ - + ### method `dump` @@ -279,7 +279,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -295,7 +295,7 @@ Dump itself to a dict. ______________________________________________________________________ - + ### method `dumps` @@ -311,7 +311,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `load_dict` @@ -331,7 +331,7 @@ Load itself from a string. ______________________________________________________________________ - + ## class `UniformQuantizationParameters` @@ -339,7 +339,7 @@ Quantization parameters for uniform quantization. This class stores the parameters used for quantizing real values to discrete integer values. The parameters are computed from quantization options and quantization statistics. - + ### method `__init__` @@ -363,7 +363,7 @@ Get a copy of the quantization parameters. ______________________________________________________________________ - + ### method `compute_quantization_parameters` @@ -383,7 +383,7 @@ Compute the quantization parameters. ______________________________________________________________________ - + ### method `copy_params` @@ -399,7 +399,7 @@ Copy the parameters from a different structure. ______________________________________________________________________ - + ### method `dump` @@ -415,7 +415,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -431,7 +431,7 @@ Dump itself to a dict. ______________________________________________________________________ - + ### method `dumps` @@ -447,7 +447,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `load_dict` @@ -467,7 +467,7 @@ Load itself from a string. ______________________________________________________________________ - + ## class `UniformQuantizer` @@ -481,7 +481,7 @@ Contains all information necessary for uniform quantization and provides quantiz - `stats` (Optional\[MinMaxQuantizationStats\]): Quantization batch statistics set - `params` (Optional\[UniformQuantizationParameters\]): Quantization parameters set (scale, zero-point) - + ### method `__init__` @@ -526,7 +526,7 @@ Get a copy of the calibration set statistics. ______________________________________________________________________ - + ### method `check_is_uniform_quantized` @@ -548,7 +548,7 @@ Determines whether the values represented by this QuantizedArray show a quantize ______________________________________________________________________ - + ### method `compute_quantization_parameters` @@ -568,7 +568,7 @@ Compute the quantization parameters. ______________________________________________________________________ - + ### method `compute_quantization_stats` @@ -584,7 +584,7 @@ Compute the calibration set quantization statistics. ______________________________________________________________________ - + ### method `copy_opts` @@ -600,7 +600,7 @@ Copy the options from a different structure. ______________________________________________________________________ - + ### method `copy_params` @@ -616,7 +616,7 @@ Copy the parameters from a different structure. ______________________________________________________________________ - + ### method `copy_stats` @@ -632,7 +632,7 @@ Copy the statistics from a different structure. ______________________________________________________________________ - + ### method `dequant` @@ -652,7 +652,7 @@ De-quantize values. ______________________________________________________________________ - + ### method `dump` @@ -668,7 +668,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -684,7 +684,7 @@ Dump itself to a dict. ______________________________________________________________________ - + ### method `dumps` @@ -700,7 +700,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `is_equal` @@ -721,7 +721,7 @@ Compare two quantization options sets. ______________________________________________________________________ - + ### method `load_dict` @@ -741,7 +741,7 @@ Load itself from a string. ______________________________________________________________________ - + ### method `quant` @@ -761,7 +761,7 @@ Quantize values. ______________________________________________________________________ - + ## class `QuantizedArray` @@ -781,7 +781,7 @@ See https://arxiv.org/abs/1712.05877. - `params` (Optional\[UniformQuantizationParameters\]): Quantization parameters set (scale, zero-point) - `kwargs`: Any member of the options, stats, params sets as a key-value pair. The parameter sets need to be completely parametrized if their members appear in kwargs. - + ### method `__init__` @@ -799,7 +799,7 @@ __init__( ______________________________________________________________________ - + ### method `dequant` @@ -815,7 +815,7 @@ De-quantize self.qvalues. ______________________________________________________________________ - + ### method `dump` @@ -831,7 +831,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -847,7 +847,7 @@ Dump itself to a dict. ______________________________________________________________________ - + ### method `dumps` @@ -863,7 +863,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `load_dict` @@ -883,7 +883,7 @@ Load itself from a string. ______________________________________________________________________ - + ### method `quant` @@ -899,7 +899,7 @@ Quantize self.values. ______________________________________________________________________ - + ### method `update_quantized_values` @@ -919,7 +919,7 @@ Update qvalues to get their corresponding values using the related quantized par ______________________________________________________________________ - + ### method `update_values` diff --git a/docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md b/docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md index 7cc6cd405e..4031e284dc 100644 --- a/docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md +++ b/docs/developer-guide/api/concrete.ml.search_parameters.p_error_search.md @@ -43,7 +43,7 @@ If we don't reach the convergence, a user warning is raised. ______________________________________________________________________ - + ## function `compile_and_simulated_fhe_inference` @@ -91,13 +91,13 @@ Supported models are: ______________________________________________________________________ - + ## class `BinarySearch` Class for `p_error` hyper-parameter search for classification and regression tasks. - + ### method `__init__` @@ -147,7 +147,7 @@ __init__( ______________________________________________________________________ - + ### method `eval_match` @@ -174,7 +174,7 @@ Eval the matches. ______________________________________________________________________ - + ### method `reset_history` @@ -186,7 +186,7 @@ Clean history. ______________________________________________________________________ - + ### method `run` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.base.md b/docs/developer-guide/api/concrete.ml.sklearn.base.md index 48c1a78ac6..fcf8a8c805 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.base.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.base.md @@ -14,7 +14,7 @@ Base classes for all estimators. ______________________________________________________________________ - + ## class `BaseEstimator` @@ -26,7 +26,7 @@ This class does not inherit from sklearn.base.BaseEstimator as it creates some c - `_is_a_public_cml_model` (bool): Private attribute indicating if the class is a public model (as opposed to base or mixin classes). - + ### method `__init__` @@ -84,7 +84,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -100,7 +100,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -116,7 +116,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -150,7 +150,7 @@ Compile the model. ______________________________________________________________________ - + ### method `dequantize_output` @@ -172,7 +172,7 @@ This step ensures that the fit method has been called. ______________________________________________________________________ - + ### method `dump` @@ -188,7 +188,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -204,7 +204,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -220,7 +220,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -243,7 +243,7 @@ The fitted estimator. ______________________________________________________________________ - + ### method `fit_benchmark` @@ -270,7 +270,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -292,7 +292,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -312,7 +312,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -336,7 +336,7 @@ For some simple models such a linear regression, there is no post-processing ste ______________________________________________________________________ - + ### method `predict` @@ -360,7 +360,7 @@ Predict values for X, in FHE or in the clear. ______________________________________________________________________ - + ### method `quantize_input` @@ -382,7 +382,7 @@ This step ensures that the fit method has been called. ______________________________________________________________________ - + ## class `BaseClassifier` @@ -390,14 +390,18 @@ Base class for linear and tree-based classifiers in Concrete ML. This class inherits from BaseEstimator and modifies some of its methods in order to align them with classifier behaviors. This notably include applying a sigmoid/softmax post-processing to the predicted values as well as handling a mapping of classes in case they are not ordered. - + ### method `__init__` ```python -__init__(*args, **kwargs) +__init__() ``` +Initialize the base class with common attributes used in all estimators. + +An underscore "\_" is appended to attributes that were created while fitting the model. This is done in order to follow scikit-Learn's standard format. More information available in their documentation: https://scikit-learn.org/stable/developers/develop.html#:~:text=Estimated%20Attributes%C2%B6 + ______________________________________________________________________ #### property fhe_circuit @@ -432,6 +436,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -444,7 +460,19 @@ Is None if the model is not fitted. ______________________________________________________________________ - +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + + ### method `check_model_is_compiled` @@ -460,7 +488,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -476,7 +504,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -510,7 +538,7 @@ Compile the model. ______________________________________________________________________ - + ### method `dequantize_output` @@ -532,7 +560,7 @@ This step ensures that the fit method has been called. ______________________________________________________________________ - + ### method `dump` @@ -548,7 +576,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -564,7 +592,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -580,7 +608,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -590,7 +618,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -617,7 +645,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -639,7 +667,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -659,7 +687,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -669,7 +697,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -682,7 +710,7 @@ predict( ______________________________________________________________________ - + ### method `predict_proba` @@ -706,7 +734,7 @@ Predict class probabilities. ______________________________________________________________________ - + ### method `quantize_input` @@ -728,13 +756,13 @@ This step ensures that the fit method has been called. ______________________________________________________________________ - + ## class `QuantizedTorchEstimatorMixin` Mixin that provides quantization for a torch module and follows the Estimator API. - + ### method `__init__` @@ -810,7 +838,7 @@ Get the output quantizers. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -826,7 +854,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -842,7 +870,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -860,7 +888,7 @@ compile( ______________________________________________________________________ - + ### method `dequantize_output` @@ -870,7 +898,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -886,7 +914,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -902,7 +930,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -918,7 +946,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -943,7 +971,7 @@ The fitted estimator. ______________________________________________________________________ - + ### method `fit_benchmark` @@ -974,7 +1002,7 @@ The Concrete ML and equivalent skorch fitted estimators. ______________________________________________________________________ - + ### method `get_params` @@ -996,7 +1024,7 @@ This method is overloaded in order to make sure that auto-computed parameters ar ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -1006,7 +1034,7 @@ get_sklearn_params(deep: 'bool' = True) → Dict ______________________________________________________________________ - + ### classmethod `load_dict` @@ -1026,7 +1054,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -1036,7 +1064,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -1060,7 +1088,7 @@ Predict values for X, in FHE or in the clear. ______________________________________________________________________ - + ### method `prune` @@ -1088,7 +1116,7 @@ A new pruned copy of the Neural Network model. ______________________________________________________________________ - + ### method `quantize_input` @@ -1098,7 +1126,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `BaseTreeEstimatorMixin` @@ -1106,7 +1134,7 @@ Mixin class for tree-based estimators. This class inherits from sklearn.base.BaseEstimator in order to have access to scikit-learn's `get_params` and `set_params` methods. - + ### method `__init__` @@ -1166,7 +1194,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -1182,7 +1210,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -1198,7 +1226,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -1208,7 +1236,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `dequantize_output` @@ -1218,7 +1246,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -1234,7 +1262,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -1250,7 +1278,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -1266,7 +1294,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -1276,7 +1304,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -1303,7 +1331,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -1325,7 +1353,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -1345,7 +1373,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -1355,7 +1383,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -1368,7 +1396,7 @@ predict( ______________________________________________________________________ - + ### method `quantize_input` @@ -1378,7 +1406,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `BaseTreeRegressorMixin` @@ -1386,7 +1414,7 @@ Mixin class for tree-based regressors. This class is used to create a tree-based regressor class that inherits from sklearn.base.RegressorMixin, which essentially gives access to scikit-learn's `score` method for regressors. - + ### method `__init__` @@ -1446,7 +1474,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -1462,7 +1490,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -1478,7 +1506,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -1488,7 +1516,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `dequantize_output` @@ -1498,7 +1526,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -1514,7 +1542,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -1530,7 +1558,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -1546,7 +1574,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -1556,7 +1584,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -1583,7 +1611,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -1605,7 +1633,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -1625,7 +1653,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -1635,7 +1663,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -1648,7 +1676,7 @@ predict( ______________________________________________________________________ - + ### method `quantize_input` @@ -1658,7 +1686,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `BaseTreeClassifierMixin` @@ -1668,14 +1696,20 @@ This class is used to create a tree-based classifier class that inherits from sk Additionally, this class adjusts some of the tree-based base class's methods in order to make them compliant with classification workflows. - + ### method `__init__` ```python -__init__(*args, **kwargs) +__init__(n_bits: 'int') ``` +Initialize the TreeBasedEstimatorMixin. + +**Args:** + +- `n_bits` (int): The number of bits used for quantization. + ______________________________________________________________________ #### property fhe_circuit @@ -1710,6 +1744,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -1722,7 +1768,19 @@ Is None if the model is not fitted. ______________________________________________________________________ - +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + + ### method `check_model_is_compiled` @@ -1738,7 +1796,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -1754,7 +1812,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -1764,7 +1822,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `dequantize_output` @@ -1774,7 +1832,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -1790,7 +1848,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -1806,7 +1864,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -1822,7 +1880,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -1832,7 +1890,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -1859,7 +1917,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -1881,7 +1939,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -1901,7 +1959,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -1911,7 +1969,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -1924,7 +1982,7 @@ predict( ______________________________________________________________________ - + ### method `predict_proba` @@ -1948,7 +2006,7 @@ Predict class probabilities. ______________________________________________________________________ - + ### method `quantize_input` @@ -1958,7 +2016,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `SklearnLinearModelMixin` @@ -1966,7 +2024,7 @@ A Mixin class for sklearn linear models with FHE. This class inherits from sklearn.base.BaseEstimator in order to have access to scikit-learn's `get_params` and `set_params` methods. - + ### method `__init__` @@ -2028,7 +2086,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -2044,7 +2102,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -2060,7 +2118,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -2070,7 +2128,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `dequantize_output` @@ -2080,7 +2138,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -2096,7 +2154,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -2112,7 +2170,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -2128,7 +2186,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -2138,7 +2196,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -2165,7 +2223,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -2187,7 +2245,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -2207,7 +2265,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -2231,7 +2289,7 @@ For some simple models such a linear regression, there is no post-processing ste ______________________________________________________________________ - + ### method `predict` @@ -2255,7 +2313,7 @@ Predict values for X, in FHE or in the clear. ______________________________________________________________________ - + ### method `quantize_input` @@ -2265,7 +2323,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `SklearnLinearRegressorMixin` @@ -2273,7 +2331,7 @@ A Mixin class for sklearn linear regressors with FHE. This class is used to create a linear regressor class that inherits from sklearn.base.RegressorMixin, which essentially gives access to scikit-learn's `score` method for regressors. - + ### method `__init__` @@ -2335,7 +2393,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `check_model_is_compiled` @@ -2351,7 +2409,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -2367,7 +2425,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -2377,7 +2435,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `dequantize_output` @@ -2387,7 +2445,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -2403,7 +2461,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -2419,7 +2477,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -2435,7 +2493,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -2445,7 +2503,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -2472,7 +2530,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -2494,7 +2552,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -2514,7 +2572,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -2538,7 +2596,7 @@ For some simple models such a linear regression, there is no post-processing ste ______________________________________________________________________ - + ### method `predict` @@ -2562,7 +2620,7 @@ Predict values for X, in FHE or in the clear. ______________________________________________________________________ - + ### method `quantize_input` @@ -2572,7 +2630,7 @@ quantize_input(X: 'ndarray') → ndarray ______________________________________________________________________ - + ## class `SklearnLinearClassifierMixin` @@ -2582,14 +2640,22 @@ This class is used to create a linear classifier class that inherits from sklear Additionally, this class adjusts some of the tree-based base class's methods in order to make them compliant with classification workflows. - + ### method `__init__` ```python -__init__(*args, **kwargs) +__init__(n_bits: 'Union[int, Dict[str, int]]' = 8) ``` +Initialize the FHE linear model. + +**Args:** + +- `n_bits` (int, Dict\[str, int\]): Number of bits to quantize the model. If an int is passed for n_bits, the value will be used for quantizing inputs and weights. If a dict is passed, then it should contain "op_inputs" and "op_weights" as keys with corresponding number of quantization bits so that: + \- op_inputs : number of bits to quantize the input values + \- op_weights: number of bits to quantize the learned parameters Default to 8. + ______________________________________________________________________ #### property fhe_circuit @@ -2624,6 +2690,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -2636,7 +2714,19 @@ Is None if the model is not fitted. ______________________________________________________________________ - +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + + ### method `check_model_is_compiled` @@ -2652,7 +2742,7 @@ Check if the model is compiled. ______________________________________________________________________ - + ### method `check_model_is_fitted` @@ -2668,7 +2758,7 @@ Check if the model is fitted. ______________________________________________________________________ - + ### method `compile` @@ -2678,7 +2768,7 @@ compile(*args, **kwargs) → Circuit ______________________________________________________________________ - + ### method `decision_function` @@ -2702,7 +2792,7 @@ Predict confidence scores. ______________________________________________________________________ - + ### method `dequantize_output` @@ -2712,7 +2802,7 @@ dequantize_output(q_y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `dump` @@ -2728,7 +2818,7 @@ Dump itself to a file. ______________________________________________________________________ - + ### method `dump_dict` @@ -2744,7 +2834,7 @@ Dump the object as a dict. ______________________________________________________________________ - + ### method `dumps` @@ -2760,7 +2850,7 @@ Dump itself to a string. ______________________________________________________________________ - + ### method `fit` @@ -2770,7 +2860,7 @@ fit(X: 'Data', y: 'Target', **fit_parameters) ______________________________________________________________________ - + ### method `fit_benchmark` @@ -2797,7 +2887,7 @@ The Concrete ML and float equivalent fitted estimators. ______________________________________________________________________ - + ### method `get_sklearn_params` @@ -2819,7 +2909,7 @@ This method is used to instantiate a scikit-learn model using the Concrete ML mo ______________________________________________________________________ - + ### classmethod `load_dict` @@ -2839,7 +2929,7 @@ Load itself from a dict. ______________________________________________________________________ - + ### method `post_processing` @@ -2849,7 +2939,7 @@ post_processing(y_preds: 'ndarray') → ndarray ______________________________________________________________________ - + ### method `predict` @@ -2862,7 +2952,7 @@ predict( ______________________________________________________________________ - + ### method `predict_proba` @@ -2875,7 +2965,631 @@ predict_proba( ______________________________________________________________________ - + + +### method `quantize_input` + +```python +quantize_input(X: 'ndarray') → ndarray +``` + +______________________________________________________________________ + + + +## class `SklearnKNeighborsMixin` + +A Mixin class for sklearn KNeighbors models with FHE. + +This class inherits from sklearn.base.BaseEstimator in order to have access to scikit-learn's `get_params` and `set_params` methods. + + + +### method `__init__` + +```python +__init__(n_bits: 'int' = 3) +``` + +Initialize the FHE knn model. + +**Args:** + +- `n_bits` (int): Number of bits to quantize the model. IThe value will be used for quantizing inputs and X_fit. Default to 3. + +______________________________________________________________________ + +#### property fhe_circuit + +Get the FHE circuit. + +The FHE circuit combines computational graph, mlir, client and server into a single object. More information available in Concrete documentation (https://docs.zama.ai/concrete/getting-started/terminology_and_structure) Is None if the model is not fitted. + +**Returns:** + +- `Circuit`: The FHE circuit. + +______________________________________________________________________ + +#### property is_compiled + +Indicate if the model is compiled. + +**Returns:** + +- `bool`: If the model is compiled. + +______________________________________________________________________ + +#### property is_fitted + +Indicate if the model is fitted. + +**Returns:** + +- `bool`: If the model is fitted. + +______________________________________________________________________ + +#### property onnx_model + +Get the ONNX model. + +Is None if the model is not fitted. + +**Returns:** + +- `onnx.ModelProto`: The ONNX model. + +______________________________________________________________________ + + + +### method `check_model_is_compiled` + +```python +check_model_is_compiled() → None +``` + +Check if the model is compiled. + +**Raises:** + +- `AttributeError`: If the model is not compiled. + +______________________________________________________________________ + + + +### method `check_model_is_fitted` + +```python +check_model_is_fitted() → None +``` + +Check if the model is fitted. + +**Raises:** + +- `AttributeError`: If the model is not fitted. + +______________________________________________________________________ + + + +### method `compile` + +```python +compile(*args, **kwargs) → Circuit +``` + +______________________________________________________________________ + + + +### method `dequantize_output` + +```python +dequantize_output(q_y_preds: 'ndarray') → ndarray +``` + +______________________________________________________________________ + + + +### method `dump` + +```python +dump(file: 'TextIO') → None +``` + +Dump itself to a file. + +**Args:** + +- `file` (TextIO): The file to dump the serialized object into. + +______________________________________________________________________ + + + +### method `dump_dict` + +```python +dump_dict() → Dict[str, Any] +``` + +Dump the object as a dict. + +**Returns:** + +- `Dict[str, Any]`: Dict of serialized objects. + +______________________________________________________________________ + + + +### method `dumps` + +```python +dumps() → str +``` + +Dump itself to a string. + +**Returns:** + +- `metadata` (str): String of the serialized object. + +______________________________________________________________________ + + + +### method `fit` + +```python +fit(X: 'Data', y: 'Target', **fit_parameters) +``` + +______________________________________________________________________ + + + +### method `fit_benchmark` + +```python +fit_benchmark( + X: 'Data', + y: 'Target', + random_state: 'Optional[int]' = None, + **fit_parameters +) +``` + +Fit both the Concrete ML and its equivalent float estimators. + +**Args:** + +- `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List. +- `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List. +- `random_state` (Optional\[int\]): The random state to use when fitting. Defaults to None. +- `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method. + +**Returns:** +The Concrete ML and float equivalent fitted estimators. + +______________________________________________________________________ + + + +### method `get_sklearn_params` + +```python +get_sklearn_params(deep: 'bool' = True) → dict +``` + +Get parameters for this estimator. + +This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`. + +**Args:** + +- `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True. + +**Returns:** + +- `params` (dict): Parameter names mapped to their values. + +______________________________________________________________________ + + + +### classmethod `load_dict` + +```python +load_dict(metadata: 'Dict[str, Any]') → BaseEstimator +``` + +Load itself from a dict. + +**Args:** + +- `metadata` (Dict\[str, Any\]): Dict of serialized objects. + +**Returns:** + +- `BaseEstimator`: The loaded object. + +______________________________________________________________________ + + + +### method `majority_vote` + +```python +majority_vote(nearest_classes: 'ndarray') +``` + +Determine the most common class among nearest neighborsfor each query. + +**Args:** + +- `nearest_classes` (numpy.ndarray): The class labels of the nearest neighbors for a query + +**Returns:** + +- `numpy.ndarray`: The majority-voted class label for the corresponding query. + +______________________________________________________________________ + + + +### method `post_processing` + +```python +post_processing(y_preds: 'ndarray') → ndarray +``` + +Perform the majority. + +For KNN, the de-quantization step is not required. Because \_inference returns the label of the k-nearest neighbors. + +**Args:** + +- `y_preds` (numpy.ndarray): The topk nearest labels + +**Returns:** + +- `numpy.ndarray`: The majority vote. + +______________________________________________________________________ + + + +### method `predict` + +```python +predict( + X: 'Data', + fhe: 'Union[FheMode, str]' = +) → ndarray +``` + +______________________________________________________________________ + + + +### method `quantize_input` + +```python +quantize_input(X: 'ndarray') → ndarray +``` + +______________________________________________________________________ + + + +## class `SklearnKNeighborsClassifierMixin` + +A Mixin class for sklearn KNeighbors classifiers with FHE. + +This class is used to create a KNeighbors classifier class that inherits from SklearnKNeighborsMixin and sklearn.base.ClassifierMixin. By inheriting from sklearn.base.ClassifierMixin, it allows this class to be recognized as a classifier." + + + +### method `__init__` + +```python +__init__(n_bits: 'int' = 3) +``` + +Initialize the FHE knn model. + +**Args:** + +- `n_bits` (int): Number of bits to quantize the model. IThe value will be used for quantizing inputs and X_fit. Default to 3. + +______________________________________________________________________ + +#### property fhe_circuit + +Get the FHE circuit. + +The FHE circuit combines computational graph, mlir, client and server into a single object. More information available in Concrete documentation (https://docs.zama.ai/concrete/getting-started/terminology_and_structure) Is None if the model is not fitted. + +**Returns:** + +- `Circuit`: The FHE circuit. + +______________________________________________________________________ + +#### property is_compiled + +Indicate if the model is compiled. + +**Returns:** + +- `bool`: If the model is compiled. + +______________________________________________________________________ + +#### property is_fitted + +Indicate if the model is fitted. + +**Returns:** + +- `bool`: If the model is fitted. + +______________________________________________________________________ + +#### property onnx_model + +Get the ONNX model. + +Is None if the model is not fitted. + +**Returns:** + +- `onnx.ModelProto`: The ONNX model. + +______________________________________________________________________ + + + +### method `check_model_is_compiled` + +```python +check_model_is_compiled() → None +``` + +Check if the model is compiled. + +**Raises:** + +- `AttributeError`: If the model is not compiled. + +______________________________________________________________________ + + + +### method `check_model_is_fitted` + +```python +check_model_is_fitted() → None +``` + +Check if the model is fitted. + +**Raises:** + +- `AttributeError`: If the model is not fitted. + +______________________________________________________________________ + + + +### method `compile` + +```python +compile(*args, **kwargs) → Circuit +``` + +______________________________________________________________________ + + + +### method `dequantize_output` + +```python +dequantize_output(q_y_preds: 'ndarray') → ndarray +``` + +______________________________________________________________________ + + + +### method `dump` + +```python +dump(file: 'TextIO') → None +``` + +Dump itself to a file. + +**Args:** + +- `file` (TextIO): The file to dump the serialized object into. + +______________________________________________________________________ + + + +### method `dump_dict` + +```python +dump_dict() → Dict[str, Any] +``` + +Dump the object as a dict. + +**Returns:** + +- `Dict[str, Any]`: Dict of serialized objects. + +______________________________________________________________________ + + + +### method `dumps` + +```python +dumps() → str +``` + +Dump itself to a string. + +**Returns:** + +- `metadata` (str): String of the serialized object. + +______________________________________________________________________ + + + +### method `fit` + +```python +fit(X: 'Data', y: 'Target', **fit_parameters) +``` + +______________________________________________________________________ + + + +### method `fit_benchmark` + +```python +fit_benchmark( + X: 'Data', + y: 'Target', + random_state: 'Optional[int]' = None, + **fit_parameters +) +``` + +Fit both the Concrete ML and its equivalent float estimators. + +**Args:** + +- `X` (Data): The training data, as a Numpy array, Torch tensor, Pandas DataFrame or List. +- `y` (Target): The target data, as a Numpy array, Torch tensor, Pandas DataFrame, Pandas Series or List. +- `random_state` (Optional\[int\]): The random state to use when fitting. Defaults to None. +- `**fit_parameters`: Keyword arguments to pass to the float estimator's fit method. + +**Returns:** +The Concrete ML and float equivalent fitted estimators. + +______________________________________________________________________ + + + +### method `get_sklearn_params` + +```python +get_sklearn_params(deep: 'bool' = True) → dict +``` + +Get parameters for this estimator. + +This method is used to instantiate a scikit-learn model using the Concrete ML model's parameters. It does not override scikit-learn's existing `get_params` method in order to not break its implementation of `set_params`. + +**Args:** + +- `deep` (bool): If True, will return the parameters for this estimator and contained subobjects that are estimators. Default to True. + +**Returns:** + +- `params` (dict): Parameter names mapped to their values. + +______________________________________________________________________ + + + +### classmethod `load_dict` + +```python +load_dict(metadata: 'Dict[str, Any]') → BaseEstimator +``` + +Load itself from a dict. + +**Args:** + +- `metadata` (Dict\[str, Any\]): Dict of serialized objects. + +**Returns:** + +- `BaseEstimator`: The loaded object. + +______________________________________________________________________ + + + +### method `majority_vote` + +```python +majority_vote(nearest_classes: 'ndarray') +``` + +Determine the most common class among nearest neighborsfor each query. + +**Args:** + +- `nearest_classes` (numpy.ndarray): The class labels of the nearest neighbors for a query + +**Returns:** + +- `numpy.ndarray`: The majority-voted class label for the corresponding query. + +______________________________________________________________________ + + + +### method `post_processing` + +```python +post_processing(y_preds: 'ndarray') → ndarray +``` + +Perform the majority. + +For KNN, the de-quantization step is not required. Because \_inference returns the label of the k-nearest neighbors. + +**Args:** + +- `y_preds` (numpy.ndarray): The topk nearest labels + +**Returns:** + +- `numpy.ndarray`: The majority vote. + +______________________________________________________________________ + + + +### method `predict` + +```python +predict( + X: 'Data', + fhe: 'Union[FheMode, str]' = +) → ndarray +``` + +______________________________________________________________________ + + ### method `quantize_input` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.linear_model.md b/docs/developer-guide/api/concrete.ml.sklearn.linear_model.md index 94d39673d6..31c935dd01 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.linear_model.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.linear_model.md @@ -478,6 +478,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -490,6 +502,18 @@ Is None if the model is not fitted. ______________________________________________________________________ +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + ### method `dump_dict` @@ -500,7 +524,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.md b/docs/developer-guide/api/concrete.ml.sklearn.md index 01d38b582d..226ebfd165 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.md @@ -13,6 +13,7 @@ Import sklearn models. - **base** - **glm** - **linear_model** +- **neighbors** - **qnn** - **rf** - **svm** @@ -21,7 +22,7 @@ Import sklearn models. ______________________________________________________________________ - + ## function `get_sklearn_models` @@ -36,7 +37,7 @@ the lists of models in Concrete ML ______________________________________________________________________ - + ## function `get_sklearn_linear_models` @@ -61,7 +62,7 @@ the lists of linear models in Concrete ML ______________________________________________________________________ - + ## function `get_sklearn_tree_models` @@ -86,7 +87,7 @@ the lists of tree models in Concrete ML ______________________________________________________________________ - + ## function `get_sklearn_neural_net_models` @@ -108,3 +109,28 @@ Return the list of available neural net models in Concrete ML. **Returns:** the lists of neural net models in Concrete ML + +______________________________________________________________________ + + + +## function `get_sklearn_neighbors_models` + +```python +get_sklearn_neighbors_models( + classifier: bool = True, + regressor: bool = True, + str_in_class_name: List[str] = None +) +``` + +Return the list of available neighbor models in Concrete ML. + +**Args:** + +- `classifier` (bool): whether you want classifiers or not +- `regressor` (bool): whether you want regressors or not +- `str_in_class_name` (List\[str\]): if not None, only return models with the given string or list of strings as a substring in their class name + +**Returns:** +the lists of neighbor models in Concrete ML diff --git a/docs/developer-guide/api/concrete.ml.sklearn.neighbors.md b/docs/developer-guide/api/concrete.ml.sklearn.neighbors.md new file mode 100644 index 0000000000..980c3a56c6 --- /dev/null +++ b/docs/developer-guide/api/concrete.ml.sklearn.neighbors.md @@ -0,0 +1,103 @@ + + + + +# module `concrete.ml.sklearn.neighbors` + +Implement sklearn linear model. + +______________________________________________________________________ + + + +## class `KNeighborsClassifier` + +A k-nearest classifier model with FHE. + +**Parameters:** + +- `n_bits` (int): Number of bits to quantize the model. The value will be used for quantizing inputs and X_fit. Default to 3. + +For more details on KNeighborsClassifier please refer to the scikit-learn documentation: https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html + + + +### method `__init__` + +```python +__init__( + n_bits=2, + n_neighbors=3, + weights='uniform', + algorithm='auto', + leaf_size=30, + p=2, + metric='minkowski', + metric_params=None, + n_jobs=None +) +``` + +______________________________________________________________________ + +#### property fhe_circuit + +Get the FHE circuit. + +The FHE circuit combines computational graph, mlir, client and server into a single object. More information available in Concrete documentation (https://docs.zama.ai/concrete/getting-started/terminology_and_structure) Is None if the model is not fitted. + +**Returns:** + +- `Circuit`: The FHE circuit. + +______________________________________________________________________ + +#### property is_compiled + +Indicate if the model is compiled. + +**Returns:** + +- `bool`: If the model is compiled. + +______________________________________________________________________ + +#### property is_fitted + +Indicate if the model is fitted. + +**Returns:** + +- `bool`: If the model is fitted. + +______________________________________________________________________ + +#### property onnx_model + +Get the ONNX model. + +Is None if the model is not fitted. + +**Returns:** + +- `onnx.ModelProto`: The ONNX model. + +______________________________________________________________________ + + + +### method `dump_dict` + +```python +dump_dict() → Dict[str, Any] +``` + +______________________________________________________________________ + + + +### classmethod `load_dict` + +```python +load_dict(metadata: Dict) +``` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.qnn.md b/docs/developer-guide/api/concrete.ml.sklearn.qnn.md index 0a9dbd295e..3127905345 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.qnn.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.qnn.md @@ -14,7 +14,7 @@ Scikit-learn interface for fully-connected quantized neural networks. ______________________________________________________________________ - + ## class `NeuralNetRegressor` @@ -24,7 +24,7 @@ This class wraps a quantized neural network implemented using Torch tools as a s Inputs and targets that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. An error is raised if these values are not floating points. - + ### method `__init__` @@ -120,7 +120,7 @@ Get the output quantizers. ______________________________________________________________________ - + ### method `dump_dict` @@ -130,7 +130,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### method `fit` @@ -145,7 +145,7 @@ fit( ______________________________________________________________________ - + ### method `fit_benchmark` @@ -160,7 +160,7 @@ fit_benchmark( ______________________________________________________________________ - + ### classmethod `load_dict` @@ -170,7 +170,7 @@ load_dict(metadata: Dict) ______________________________________________________________________ - + ### method `predict` @@ -183,7 +183,7 @@ predict( ______________________________________________________________________ - + ### method `predict_proba` @@ -196,7 +196,7 @@ predict_proba( ______________________________________________________________________ - + ## class `NeuralNetClassifier` @@ -206,7 +206,7 @@ This class wraps a quantized neural network implemented using Torch tools as a s Inputs that are float64 will be casted to float32 before training as Torch does not handle float64 types properly. Thus should not have a significant impact on the model's performances. If the targets are integers of lower bit-width, they will be safely casted to int64. Else, an error is raised. - + ### method `__init__` @@ -285,6 +285,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -307,7 +319,19 @@ Get the output quantizers. ______________________________________________________________________ - +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + + ### method `dump_dict` @@ -317,7 +341,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### method `fit` @@ -332,7 +356,7 @@ fit( ______________________________________________________________________ - + ### method `fit_benchmark` @@ -347,7 +371,7 @@ fit_benchmark( ______________________________________________________________________ - + ### classmethod `load_dict` @@ -357,7 +381,7 @@ load_dict(metadata: Dict) ______________________________________________________________________ - + ### method `predict` @@ -370,7 +394,7 @@ predict( ______________________________________________________________________ - + ### method `predict_proba` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md b/docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md index efbe95b98c..47628298e6 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.qnn_module.md @@ -6,13 +6,9 @@ Sparse Quantized Neural Network torch module. -## **Global Variables** - -- **MAX_BITWIDTH_BACKWARD_COMPATIBLE** - ______________________________________________________________________ - + ## class `SparseQuantNeuralNetwork` @@ -20,7 +16,7 @@ Sparse Quantized Neural Network. This class implements an MLP that is compatible with FHE constraints. The weights and activations are quantized to low bit-width and pruning is used to ensure accumulators do not surpass an user-provided accumulator bit-width. The number of classes and number of layers are specified by the user, as well as the breadth of the network - + ### method `__init__` @@ -30,9 +26,9 @@ __init__( n_layers: int, n_outputs: int, n_hidden_neurons_multiplier: int = 4, - n_w_bits: int = 3, - n_a_bits: int = 3, - n_accum_bits: int = 8, + n_w_bits: int = 4, + n_a_bits: int = 4, + n_accum_bits: int = 32, n_prune_neurons_percentage: float = 0.0, activation_function: Type = , quant_narrow: bool = False, @@ -64,7 +60,7 @@ Sparse Quantized Neural Network constructor. ______________________________________________________________________ - + ### method `enable_pruning` @@ -80,7 +76,7 @@ Enable pruning in the network. Pruning must be made permanent to recover pruned ______________________________________________________________________ - + ### method `forward` @@ -100,7 +96,7 @@ Forward pass. ______________________________________________________________________ - + ### method `make_pruning_permanent` @@ -112,7 +108,7 @@ Make the learned pruning permanent in the network. ______________________________________________________________________ - + ### method `max_active_neurons` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.rf.md b/docs/developer-guide/api/concrete.ml.sklearn.rf.md index 1b86163913..47eeaeb9bc 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.rf.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.rf.md @@ -80,6 +80,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -92,6 +104,18 @@ Is None if the model is not fitted. ______________________________________________________________________ +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + ### method `dump_dict` @@ -102,7 +126,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` @@ -122,13 +146,13 @@ post_processing(y_preds: ndarray) → ndarray ______________________________________________________________________ - + ## class `RandomForestRegressor` Implements the RandomForest regressor. - + ### method `__init__` @@ -205,7 +229,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `dump_dict` @@ -215,7 +239,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.svm.md b/docs/developer-guide/api/concrete.ml.sklearn.svm.md index 7ba090351a..6022345236 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.svm.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.svm.md @@ -178,6 +178,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -190,6 +202,18 @@ Is None if the model is not fitted. ______________________________________________________________________ +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + ### method `dump_dict` @@ -200,7 +224,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.tree.md b/docs/developer-guide/api/concrete.ml.sklearn.tree.md index 29242567f6..160f6e1277 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.tree.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.tree.md @@ -74,6 +74,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -86,6 +98,18 @@ Is None if the model is not fitted. ______________________________________________________________________ +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + ### method `dump_dict` @@ -96,7 +120,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` @@ -116,13 +140,13 @@ post_processing(y_preds: ndarray) → ndarray ______________________________________________________________________ - + ## class `DecisionTreeRegressor` Implements the sklearn DecisionTreeClassifier. - + ### method `__init__` @@ -193,7 +217,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `dump_dict` @@ -203,7 +227,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` diff --git a/docs/developer-guide/api/concrete.ml.sklearn.xgb.md b/docs/developer-guide/api/concrete.ml.sklearn.xgb.md index 52d571fdf3..1da667615b 100644 --- a/docs/developer-guide/api/concrete.ml.sklearn.xgb.md +++ b/docs/developer-guide/api/concrete.ml.sklearn.xgb.md @@ -90,6 +90,18 @@ Indicate if the model is fitted. ______________________________________________________________________ +#### property n_classes\_ + +Get the model's number of classes. + +Using this attribute is deprecated. + +**Returns:** + +- `int`: The model's number of classes. + +______________________________________________________________________ + #### property onnx_model Get the ONNX model. @@ -102,6 +114,18 @@ Is None if the model is not fitted. ______________________________________________________________________ +#### property target_classes\_ + +Get the model's classes. + +Using this attribute is deprecated. + +**Returns:** + +- `Optional[numpy.ndarray]`: The model's classes. + +______________________________________________________________________ + ### method `dump_dict` @@ -112,7 +136,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### classmethod `load_dict` @@ -122,7 +146,7 @@ load_dict(metadata: Dict) ______________________________________________________________________ - + ## class `XGBRegressor` @@ -130,7 +154,7 @@ Implements the XGBoost regressor. See https://xgboost.readthedocs.io/en/stable/python/python_api.html#module-xgboost.sklearn for more information about the parameters used. - + ### method `__init__` @@ -216,7 +240,7 @@ Is None if the model is not fitted. ______________________________________________________________________ - + ### method `dump_dict` @@ -226,7 +250,7 @@ dump_dict() → Dict[str, Any] ______________________________________________________________________ - + ### method `fit` @@ -236,7 +260,7 @@ fit(X, y, *args, **kwargs) → Any ______________________________________________________________________ - + ### classmethod `load_dict` diff --git a/docs/developer-guide/api/concrete.ml.torch.compile.md b/docs/developer-guide/api/concrete.ml.torch.compile.md index fa92008f03..1a1750a2fb 100644 --- a/docs/developer-guide/api/concrete.ml.torch.compile.md +++ b/docs/developer-guide/api/concrete.ml.torch.compile.md @@ -44,7 +44,7 @@ build_quantized_module( model: Union[Module, ModelProto], torch_inputset: Union[Tensor, ndarray, Tuple[Union[Tensor, ndarray], ]], import_qat: bool = False, - n_bits=8, + n_bits: Union[int, Dict[str, int]] = 8, rounding_threshold_bits: Optional[int] = None ) → QuantizedModule ``` @@ -123,7 +123,7 @@ compile_onnx_model( configuration: Optional[Configuration] = None, artifacts: Optional[DebugArtifacts] = None, show_mlir: bool = False, - n_bits=8, + n_bits: Union[int, Dict] = 8, rounding_threshold_bits: Optional[int] = None, p_error: Optional[float] = None, global_p_error: Optional[float] = None, @@ -170,7 +170,7 @@ compile_brevitas_qat_model( rounding_threshold_bits: Optional[int] = None, p_error: Optional[float] = None, global_p_error: Optional[float] = None, - output_onnx_file: Union[Path, str] = None, + output_onnx_file: Union[NoneType, Path, str] = None, verbose: bool = False ) → QuantizedModule ``` diff --git a/docs/developer-guide/api/concrete.ml.torch.hybrid_model.md b/docs/developer-guide/api/concrete.ml.torch.hybrid_model.md index 429b801809..323256541b 100644 --- a/docs/developer-guide/api/concrete.ml.torch.hybrid_model.md +++ b/docs/developer-guide/api/concrete.ml.torch.hybrid_model.md @@ -6,9 +6,33 @@ Implement the conversion of a torch model to a hybrid fhe/torch inference. +## **Global Variables** + +- **MAX_BITWIDTH_BACKWARD_COMPATIBLE** + +______________________________________________________________________ + + + +## function `tuple_to_underscore_str` + +```python +tuple_to_underscore_str(tup: Tuple) → str +``` + +Convert a tuple to a string representation. + +**Args:** + +- `tup` (Tuple): a tuple to change into string representation + +**Returns:** + +- `str`: a string representing the tuple + ______________________________________________________________________ - + ## function `convert_conv1d_to_linear` @@ -28,23 +52,37 @@ Convert all Conv1D layers in a module or a Conv1D layer itself to nn.Linear. ______________________________________________________________________ - + + +## class `HybridFHEMode` + +Simple enum for different modes of execution of HybridModel. + +______________________________________________________________________ + + ## class `RemoteModule` A wrapper class for the modules to be done remotely with FHE. - + ### method `__init__` ```python -__init__(module=None, server_remote_address=None) +__init__( + module: Optional[Module] = None, + server_remote_address: Optional[str] = None, + module_name: Optional[str] = None, + model_name: Optional[str] = None, + verbose: int = 0 +) ``` ______________________________________________________________________ - + ### method `forward` @@ -54,6 +92,13 @@ forward(x: Tensor) → Tensor Forward pass of the remote module. +To change the behavior of this forward function one must change the fhe_local_mode attribute. Choices are: + +- disable: forward using torch module +- remote: forward with fhe client-server +- simulate: forward with local fhe simulation +- calibrate: forward for calibration + **Args:** - `x` (torch.Tensor): The input tensor. @@ -62,14 +107,21 @@ Forward pass of the remote module. - `(torch.Tensor)`: The output tensor. +**Raises:** + +- `ValueError`: if local_fhe_mode is not supported + ______________________________________________________________________ - + ### method `init_fhe_client` ```python -init_fhe_client(path_to_client: str, path_to_keys: str) +init_fhe_client( + path_to_client: Optional[Path] = None, + path_to_keys: Optional[Path] = None +) ``` Set the clients keys. @@ -79,14 +131,18 @@ Set the clients keys. - `path_to_client` (str): Path where the client.zip is located. - `path_to_keys` (str): Path where keys are located. +**Raises:** + +- `ValueError`: if anything goes wrong with the server. + ______________________________________________________________________ - + ### method `remote_call` ```python -remote_call(x: Tensor) +remote_call(x: Tensor) → Tensor ``` Call the remote server to get the private module inference. @@ -95,15 +151,29 @@ Call the remote server to get the private module inference. - `x` (torch.Tensor): The input tensor. +**Returns:** + +- `torch.Tensor`: The result of the FHE computation + ______________________________________________________________________ - + ## class `HybridFHEModel` Convert a model to a hybrid model. - +This is done by converting targeted modules by RemoteModules. This will modify the model in place. + +**Args:** + +- `model` (nn.Module): The model to modify (in-place modification) +- `module_names` (Union\[str, List\[str\]\]): The module name(s) to replace with FHE server. +- `server_remote_address)`: The remote address of the FHE server +- `model_name` (str): Model name identifier +- `verbose` (int): If logs should be printed when interacting with FHE server + + ### method `__init__` @@ -111,13 +181,15 @@ Convert a model to a hybrid model. __init__( model: Module, module_names: Union[str, List[str]], - server_remote_address=None + server_remote_address=None, + model_name: str = 'model', + verbose: int = 0 ) ``` ______________________________________________________________________ - + ### method `compile_model` @@ -125,9 +197,9 @@ ______________________________________________________________________ compile_model( x: Tensor, n_bits: int = 8, - rounding_threshold_bits: int = 8, - p_error=0.01, - configuration: Configuration = None + rounding_threshold_bits: Optional[int] = None, + p_error: Optional[float] = None, + configuration: Optional[Configuration] = None ) ``` @@ -143,24 +215,27 @@ Compiles the specific layers to FHE. ______________________________________________________________________ - + ### method `init_client` ```python -init_client(path_to_client: str, path_to_keys: str) +init_client( + path_to_clients: Optional[Path] = None, + path_to_keys: Optional[Path] = None +) ``` Initialize client for all remote modules. **Args:** -- `path_to_client` (str): Path to the client.zip files. -- `path_to_keys` (str): Path to the keys folder. +- `path_to_clients` (Optional\[Path\]): Path to the client.zip files. +- `path_to_keys` (Optional\[Path\]): Path to the keys folder. ______________________________________________________________________ - + ### method `publish_to_hub` @@ -172,12 +247,12 @@ Allow the user to push the model and FHE required files to HF Hub. ______________________________________________________________________ - + ### method `save_and_clear_private_info` ```python -save_and_clear_private_info(path: Path) +save_and_clear_private_info(path: Path, via_mlir=False) ``` Save the PyTorch model to the provided path and also saves the corresponding FHE circuit. @@ -185,3 +260,4 @@ Save the PyTorch model to the provided path and also saves the corresponding FHE **Args:** - `path` (Path): The directory where the model and the FHE circuit will be saved. +- `via_mlir` (bool): if fhe circuits should be serialized using via_mlir option useful for cross-platform (compile on one architecture and run on another) diff --git a/docs/developer-guide/api/concrete.ml.torch.numpy_module.md b/docs/developer-guide/api/concrete.ml.torch.numpy_module.md index 56672b0e9c..5c5e546e3e 100644 --- a/docs/developer-guide/api/concrete.ml.torch.numpy_module.md +++ b/docs/developer-guide/api/concrete.ml.torch.numpy_module.md @@ -32,7 +32,7 @@ General interface to transform a torch.nn.Module to numpy module. __init__( model: Union[Module, ModelProto], dummy_input: Optional[Tensor, Tuple[Tensor, ]] = None, - debug_onnx_output_file_path: Optional[Path, str] = None + debug_onnx_output_file_path: Optional[str, Path] = None ) ``` @@ -50,7 +50,7 @@ Get the ONNX model. ______________________________________________________________________ - + ### method `forward` diff --git a/docs/getting-started/showcase.md b/docs/getting-started/showcase.md index 91402a547d..05aa7a16b7 100644 --- a/docs/getting-started/showcase.md +++ b/docs/getting-started/showcase.md @@ -49,7 +49,7 @@ Simpler tutorials that discuss only model usage and compilation are also availab nn.png - use_case_examples/cifar_brevitas_finetuning + use_case_examples/cifar_brevitas_finetuning @@ -61,7 +61,7 @@ Simpler tutorials that discuss only model usage and compilation are also availab client-server-1.png - use_case_examples/cifar_brevitas_with_model_splitting + use_case_examples/cifar_brevitas_with_model_splitting diff --git a/docs/index.toc.txt b/docs/index.toc.txt index 180c93a82c..f9362e2e57 100644 --- a/docs/index.toc.txt +++ b/docs/index.toc.txt @@ -22,6 +22,7 @@ built-in-models/linear.md built-in-models/tree.md built-in-models/neural-networks.md + built-in-models/nearest-neighbors.md built-in-models/pandas.md built-in-models/ml_examples.md @@ -49,6 +50,7 @@ advanced-topics/client_server.md advanced-topics/advanced_features.md advanced-topics/serialization.md + advanced-topics/hybrid-models.md .. toctree:: :maxdepth: 0 diff --git a/use_case_examples/cifar/README.md b/use_case_examples/cifar/README.md index 6ef892b970..5b1cc70643 100644 --- a/use_case_examples/cifar/README.md +++ b/use_case_examples/cifar/README.md @@ -5,15 +5,15 @@ This repository provides resources and documentation on different use-cases for ## Table of Contents 1. [Use-Cases](#use-cases) - - [Fine-Tuning VGG11 CIFAR-10/100](#fine-tuning-cifar-10100) + - [Fine-Tuning VGG11 CIFAR-10/100](#fine-tuning-cifar) - [Training Ternary VGG9 on CIFAR10](#training-ternary-vgg-on-cifar10) - - [CIFAR-10 VGG9 with one client-side layer](#cifar-10-with-a-split-clearfhe-model) + - [CIFAR-10 VGG9 with one client-side layer](#cifar-10-with-a-split-model) 1. [Installation](#installation) -1. [Further Reading & Resources](#further-reading--resources) +2. [Further Reading & Resources](#further-reading) ## Use cases -### Fine-Tuning CIFAR-10/100 +### Fine-Tuning CIFAR - **Description**: This use-case explores how to convert a pre-trained CNN (on imagenet) to its FHE equivalent using Quantization Aware Training (QAT) and Concrete ML. The conversion process involves adapting a VGG11 network and quantizing the network for FHE. @@ -31,9 +31,9 @@ Notebooks: - **Description**: Train a VGG-like neural network from scratch using Brevitas on CIFAR-10 and run it in FHE. This use-case modifies the original VGG model for compatibility with Concrete ML, and explores the performance gains of rounding operations in FHE. - **Training & Inference**: Scripts provided to train the network and evaluate its performance. It also includes simulations in Concrete ML and insights into the performance enhancement using rounding. -[Results & Metrics](cifar_brevitas_training/README.md#Accuracy_/and_/performance) +[Results & Metrics](cifar_brevitas_training/README.md#accuracy-and-performance) -### CIFAR-10 with a Split Clear/FHE Model +### CIFAR-10 with a Split Model - **Description**: This method divides the model into two segments: one that operates in plaintext (clear) and the other in Fully Homomorphic Encryption (FHE). This division allows for greater precision in the input layer while taking advantage of FHE's privacy-preserving capabilities in the subsequent layers. - **Model Design**: Aims at using 8-bit accumulators to speed up FHE inference. The design incorporates pruning techniques and employs 2-bit weights to meet this aim. @@ -51,7 +51,7 @@ All use-cases can be quickly set up with: pip install -r requirements.txt ``` -## Further Reading & Resources +## Further Reading - [Concrete ML Documentation](https://docs.zama.ai/concrete-ml/) - [Brevitas Github Repository](https://github.com/Xilinx/brevitas) 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 c02b1bb323..f6a670154c 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/advanced-topics/advanced_features.md#approximate-computations). ## Results diff --git a/use_case_examples/deployment/cifar_8_bit/README.md b/use_case_examples/deployment/cifar_8_bit/README.md index 5de0328a81..f7395efaeb 100644 --- a/use_case_examples/deployment/cifar_8_bit/README.md +++ b/use_case_examples/deployment/cifar_8_bit/README.md @@ -1,7 +1,7 @@ # Deployment In this folder we show how to deploy a Concrete ML model that classifies images from CIFAR-10, either through Docker or Amazon Web Services. -We use the model showcased in [cifar split model](../../cifar_brevitas_with_model_splitting/README.md). +We use the model showcased in [cifar split model](../../cifar/cifar_brevitas_with_model_splitting/README.md). ## Get started