mirror of
https://github.com/zama-ai/concrete.git
synced 2026-01-09 21:07:56 -05:00
docs(frontend): document parameter restrictions
This commit is contained in:
@@ -61,15 +61,8 @@ Collaborate with us to advance the FHE spaces and drive innovation together.
|
|||||||
***
|
***
|
||||||
|
|
||||||
{% hint style="success" %}
|
{% hint style="success" %}
|
||||||
<<<<<<< HEAD
|
|
||||||
**Zama 5-Question Developer Survey**
|
|
||||||
|
|
||||||
We want to hear from you! Take 1 minute to share your thoughts and helping us enhance our documentation and libraries. **👉** [**Click here**](https://zvajd6l0ngk.typeform.com/to/I7mXXanI) to participate.
|
|
||||||
{% endhint %}
|
|
||||||
=======
|
|
||||||
**Zama 5-Question Developer Survey**
|
**Zama 5-Question Developer Survey**
|
||||||
|
|
||||||
We want to hear from you! Take 1 minute to share your thoughts and helping us enhance our documentation and libraries. **👉** [**Click here**](https://www.zama.ai/developer-survey) to participate.
|
We want to hear from you! Take 1 minute to share your thoughts and helping us enhance our documentation and libraries. **👉** [**Click here**](https://www.zama.ai/developer-survey) to participate.
|
||||||
{% endhint %}
|
{% endhint %}
|
||||||
|
|
||||||
>>>>>>> origin/main
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
* [Multi parameters](compilation/multi_parameters.md)
|
* [Multi parameters](compilation/multi_parameters.md)
|
||||||
* [Compression](compilation/compression.md)
|
* [Compression](compilation/compression.md)
|
||||||
* [Reusing arguments](compilation/reuse_arguments.md)
|
* [Reusing arguments](compilation/reuse_arguments.md)
|
||||||
|
* [Parameter compatibility with restrictions](compilation/parameter_compatibility_with_restrictions.md)
|
||||||
* [Common errors](compilation/common_errors.md)
|
* [Common errors](compilation/common_errors.md)
|
||||||
|
|
||||||
## Execution / Analysis
|
## Execution / Analysis
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
# Parameters compatibility with restrictions
|
||||||
|
|
||||||
|
This document explains how to use restrictions to limit the possible crypto-parameters used for the keys.
|
||||||
|
|
||||||
|
When compiling a module, the optimizer analyzes the circuits and the expected probability of error, to identify the fastest crypto-parameters that meet the specific constraints. The chosen crypto-parameters determine the size of the keys and the ciphertexts. This means that if an existing module is used in production with a specific set of crypto-parameters, there is no guarantee that a compilation of a second, different module will yield compatible crypto-parameters.
|
||||||
|
|
||||||
|
With _restrictions_, Concrete provides a way to ensure that a compilation generates compatible crypto-parameters. Restrictions will limit the search-space walked by the optimizer to ensure that only compatible parameters can be returned. As of now, we support two major restrictions:
|
||||||
|
|
||||||
|
+ [__Keyset restriction__](#keyset-restriction) : Restricts the crypto-parameters to an existing keyset.
|
||||||
|
+ [__Ranges restriction__](#ranges-restriction) : Restricts the crypto-parameters ranges allowed in the optimizer.
|
||||||
|
|
||||||
|
## Keyset restriction
|
||||||
|
|
||||||
|
You can generate keyset restriction directly form an existing keyset:
|
||||||
|
|
||||||
|
```python
|
||||||
|
@fhe.module()
|
||||||
|
class Big:
|
||||||
|
@fhe.function({"x": "encrypted"})
|
||||||
|
def inc(x):
|
||||||
|
return (x + 1) % 200
|
||||||
|
|
||||||
|
big_inputset = [np.random.randint(1, 200, size=()) for _ in range(100)]
|
||||||
|
big_module = Big.compile(
|
||||||
|
{"inc": big_inputset},
|
||||||
|
)
|
||||||
|
big_keyset_info = big_module.keys.specs.program_info.get_keyset_info()
|
||||||
|
big_module.keygen()
|
||||||
|
|
||||||
|
# We get the restriction from the existing keyset
|
||||||
|
restriction = big_keyset_info.get_restriction()
|
||||||
|
|
||||||
|
@fhe.module()
|
||||||
|
class Small:
|
||||||
|
@fhe.function({"x": "encrypted"})
|
||||||
|
def inc(x):
|
||||||
|
return (x + 1) % 20
|
||||||
|
|
||||||
|
small_inputset = [np.random.randint(1, 20, size=()) for _ in range(100)]
|
||||||
|
small_module = Small.compile(
|
||||||
|
{"inc": small_inputset},
|
||||||
|
# We pass the keyset restriction as an extra compilation option
|
||||||
|
keyset_restriction=restriction
|
||||||
|
)
|
||||||
|
restricted_keyset_info = restricted_module.keys.specs.program_info.get_keyset_info()
|
||||||
|
assert big_keyset_info == restricted_keyset_info
|
||||||
|
|
||||||
|
small_module.keys = big_module.keys
|
||||||
|
|
||||||
|
x = 5
|
||||||
|
x_enc = small_module.inc.encrypt(x)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Ranges restriction
|
||||||
|
|
||||||
|
You can build a ranges restriction by adding available values:
|
||||||
|
```python
|
||||||
|
@fhe.module()
|
||||||
|
class Module:
|
||||||
|
@fhe.function({"x": "encrypted"})
|
||||||
|
def inc(x):
|
||||||
|
return (x + 1) % 20
|
||||||
|
|
||||||
|
inputset = [np.random.randint(1, 20, size=()) for _ in range(100)]
|
||||||
|
|
||||||
|
## We generate a range restriction
|
||||||
|
range_restriction = RangeRestriction()
|
||||||
|
|
||||||
|
## Make 999 and 200 available as internal lwe dimensions
|
||||||
|
range_restriction.add_available_internal_lwe_dimension(999)
|
||||||
|
range_restriction.add_available_internal_lwe_dimension(200)
|
||||||
|
|
||||||
|
## Setting other restrictions
|
||||||
|
range_restriction.add_available_glwe_log_polynomial_size(12)
|
||||||
|
range_restriction.add_available_glwe_dimension(2)
|
||||||
|
range_restriction.add_available_pbs_level_count(3)
|
||||||
|
range_restriction.add_available_pbs_base_log(11)
|
||||||
|
range_restriction.add_available_ks_level_count(3)
|
||||||
|
range_restriction.add_available_ks_base_log(6)
|
||||||
|
|
||||||
|
module = Module.compile(
|
||||||
|
{"inc": inputset},
|
||||||
|
# We pass the range restriction as an extra compilation option.
|
||||||
|
range_restriction=range_restriction
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that if no available parameters are set for one of the parameter ranges (say `ks_base_log`), it is assumed that the default range is available.
|
||||||
@@ -201,6 +201,12 @@ When options are specified both in the `configuration` and as kwargs in the `com
|
|||||||
#### single_precision: bool = False
|
#### single_precision: bool = False
|
||||||
- Use single precision for the whole circuit.
|
- Use single precision for the whole circuit.
|
||||||
|
|
||||||
|
#### range_restriction: Optional[RangeRestriction] = None
|
||||||
|
- A range restriction to pass to the optimizer to restrict the available crypto-parameters.
|
||||||
|
|
||||||
|
#### keyset_restriction: Optional[KeysetRestriction] = None
|
||||||
|
- A keyset restriction to pass to the optimizer to restrict the available crypto-parameters.
|
||||||
|
|
||||||
#### use_gpu: bool = False
|
#### use_gpu: bool = False
|
||||||
- Enable generating code for GPU in the compiler.
|
- Enable generating code for GPU in the compiler.
|
||||||
|
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ def test_range_restriction():
|
|||||||
range_restriction.add_available_ks_level_count(ks_level_count)
|
range_restriction.add_available_ks_level_count(ks_level_count)
|
||||||
ks_base_log = 6
|
ks_base_log = 6
|
||||||
range_restriction.add_available_ks_base_log(ks_base_log)
|
range_restriction.add_available_ks_base_log(ks_base_log)
|
||||||
module = Module.compile(
|
module = Module.compile({"inc": inputset}, range_restriction=range_restriction)
|
||||||
{"inc": inputset}, enable_unsafe_features=True, range_restriction=range_restriction
|
|
||||||
)
|
|
||||||
keyset_info = module.keys.specs.program_info.get_keyset_info()
|
keyset_info = module.keys.specs.program_info.get_keyset_info()
|
||||||
assert keyset_info.bootstrap_keys()[0].polynomial_size() == 2**glwe_log_polynomial_size
|
assert keyset_info.bootstrap_keys()[0].polynomial_size() == 2**glwe_log_polynomial_size
|
||||||
assert keyset_info.bootstrap_keys()[0].input_lwe_dimension() == internal_lwe_dimension
|
assert keyset_info.bootstrap_keys()[0].input_lwe_dimension() == internal_lwe_dimension
|
||||||
@@ -83,21 +81,17 @@ def test_keyset_restriction():
|
|||||||
|
|
||||||
big_module = Big.compile(
|
big_module = Big.compile(
|
||||||
{"inc": big_inputset},
|
{"inc": big_inputset},
|
||||||
enable_unsafe_features=True,
|
|
||||||
)
|
)
|
||||||
big_keyset_info = big_module.keys.specs.program_info.get_keyset_info()
|
big_keyset_info = big_module.keys.specs.program_info.get_keyset_info()
|
||||||
|
|
||||||
small_module = Small.compile(
|
small_module = Small.compile(
|
||||||
{"inc": small_inputset},
|
{"inc": small_inputset},
|
||||||
enable_unsafe_features=True,
|
|
||||||
)
|
)
|
||||||
small_keyset_info = small_module.keys.specs.program_info.get_keyset_info()
|
small_keyset_info = small_module.keys.specs.program_info.get_keyset_info()
|
||||||
assert big_keyset_info != small_keyset_info
|
assert big_keyset_info != small_keyset_info
|
||||||
|
|
||||||
restriction = big_keyset_info.get_restriction()
|
restriction = big_keyset_info.get_restriction()
|
||||||
restricted_module = Small.compile(
|
restricted_module = Small.compile({"inc": small_inputset}, keyset_restriction=restriction)
|
||||||
{"inc": small_inputset}, enable_unsafe_features=True, keyset_restriction=restriction
|
|
||||||
)
|
|
||||||
restricted_keyset_info = restricted_module.keys.specs.program_info.get_keyset_info()
|
restricted_keyset_info = restricted_module.keys.specs.program_info.get_keyset_info()
|
||||||
assert big_keyset_info == restricted_keyset_info
|
assert big_keyset_info == restricted_keyset_info
|
||||||
assert small_keyset_info != restricted_keyset_info
|
assert small_keyset_info != restricted_keyset_info
|
||||||
@@ -121,7 +115,6 @@ def test_generic_restriction():
|
|||||||
inputset = [np.random.randint(1, 200, size=()) for _ in range(100)]
|
inputset = [np.random.randint(1, 200, size=()) for _ in range(100)]
|
||||||
restricted_module = Module.compile(
|
restricted_module = Module.compile(
|
||||||
{"inc": inputset},
|
{"inc": inputset},
|
||||||
enable_unsafe_features=True,
|
|
||||||
keyset_restriction=generic_keyset_info.get_restriction(),
|
keyset_restriction=generic_keyset_info.get_restriction(),
|
||||||
)
|
)
|
||||||
compiled_keyset_info = restricted_module.keys.specs.program_info.get_keyset_info()
|
compiled_keyset_info = restricted_module.keys.specs.program_info.get_keyset_info()
|
||||||
|
|||||||
Reference in New Issue
Block a user