From 2b84def2c3b29d3dc8a14e3c617bbcc581a26d75 Mon Sep 17 00:00:00 2001 From: Umut Date: Tue, 8 Nov 2022 13:30:32 +0100 Subject: [PATCH] feat: create auto adjust rounders configuration option --- concrete/numpy/compilation/compiler.py | 5 ++++- concrete/numpy/compilation/configuration.py | 3 +++ docs/howto/configure.md | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/concrete/numpy/compilation/compiler.py b/concrete/numpy/compilation/compiler.py index e73132c77..4181fc61a 100644 --- a/concrete/numpy/compilation/compiler.py +++ b/concrete/numpy/compilation/compiler.py @@ -11,6 +11,7 @@ from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union import numpy as np +from ..extensions import AutoRounder from ..mlir import GraphConverter from ..representation import Graph from ..tracing import Tracer @@ -261,6 +262,9 @@ class Compiler: f"(expected {expected} got {actual})" ) + if self.configuration.auto_adjust_rounders: + AutoRounder.adjust(self.function, self.inputset) + if self.graph is None: try: first_sample = next(iter(self.inputset)) @@ -431,7 +435,6 @@ class Compiler: ) try: - self._evaluate("Compiling", inputset) assert self.graph is not None diff --git a/concrete/numpy/compilation/configuration.py b/concrete/numpy/compilation/configuration.py index d498cd20b..b947f5de1 100644 --- a/concrete/numpy/compilation/configuration.py +++ b/concrete/numpy/compilation/configuration.py @@ -29,6 +29,7 @@ class Configuration: p_error: Optional[float] global_p_error: float insecure_key_cache_location: Optional[str] + auto_adjust_rounders: bool # pylint: enable=too-many-instance-attributes @@ -73,6 +74,7 @@ class Configuration: jit: bool = False, p_error: Optional[float] = None, global_p_error: float = (1 / 100_000), + auto_adjust_rounders: bool = False, ): self.verbose = verbose self.show_graph = show_graph @@ -91,6 +93,7 @@ class Configuration: self.jit = jit self.p_error = p_error self.global_p_error = global_p_error + self.auto_adjust_rounders = auto_adjust_rounders self._validate() diff --git a/docs/howto/configure.md b/docs/howto/configure.md index 23d256618..ca2f86baf 100644 --- a/docs/howto/configure.md +++ b/docs/howto/configure.md @@ -60,9 +60,13 @@ Additional kwarg to `compile` function have higher precedence. So if you set an * **verbose**: bool = False * Whether to print computation graph and MLIR during compilation. + * **dump\_artifacts\_on\_unexpected\_failures**: bool = True * Whether to export debugging artifacts automatically on compilation failures. +* **auto_adjust_rounders**: bool = False + * Whether to adjust rounders automatically. + * **p_error**: Optional[float] = None * Error probability for individual table lookups. Overwrites **global_p_error** if set.