Skip to content

Commit

Permalink
chore: integrate input compression
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBredehoft committed Apr 16, 2024
1 parent c76cae8 commit 8eaccb6
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ use_case_examples/llm/gpt2*
use_case_examples/cifar_brevitas_training/.datasets/

# Key cache
ConcreteNumpyKeyCache
ConcretePythonKeyCache

# This index file is autogenerated
docs/index.rst
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,14 @@


# This is only for benchmarks to speed up compilation times
# Jit compiler is now deprecated and will soon be removed, it is thus forced to False by default
# Parameter `enable_unsafe_features` and `use_insecure_key_cache` are needed in order to be able to
# cache generated keys through `insecure_key_cache_location`. As the name suggests, these
# parameters are unsafe and should only be used for debugging in development
BENCHMARK_CONFIGURATION = fhe.Configuration(
dump_artifacts_on_unexpected_failures=True,
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location="ConcreteNumpyKeyCache",
insecure_key_cache_location="ConcretePythonKeyCache",
)


Expand Down
15 changes: 9 additions & 6 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def monkeypatched_compilation_configuration_init_for_codeblocks(
self.enable_unsafe_features = True
self.treat_warnings_as_errors = True
self.use_insecure_key_cache = True
self.insecure_key_cache_location = "ConcreteNumpyKeyCache"
self.insecure_key_cache_location = "ConcretePythonKeyCache"


def pytest_sessionstart(session: pytest.Session):
Expand Down Expand Up @@ -138,25 +138,27 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus): # pylint: disabl

@pytest.fixture
def default_configuration():
"""Return the default test compilation configuration."""
"""Return the compilation configuration for tests that can execute in FHE."""

# Parameter `enable_unsafe_features` and `use_insecure_key_cache` are needed in order to be
# able to cache generated keys through `insecure_key_cache_location`. As the name suggests,
# these parameters are unsafe and should only be used for debugging in development
# Simulation compilation is done lazily when calling circuit.simulate, so we do not need to
# set it by default
return Configuration(
dump_artifacts_on_unexpected_failures=False,
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location="ConcreteNumpyKeyCache",
# Simulation compilation is done lazily on circuit.simulate
insecure_key_cache_location="ConcretePythonKeyCache",
fhe_simulation=False,
fhe_execution=True,
compress_input_ciphertexts=True,
)


@pytest.fixture
def simulation_configuration():
"""Return the simulation test compilation configuration for simulation."""
"""Return the compilation configuration for tests that only simulate."""

# Parameter `enable_unsafe_features` and `use_insecure_key_cache` are needed in order to be
# able to cache generated keys through `insecure_key_cache_location`. As the name suggests,
Expand All @@ -165,9 +167,10 @@ def simulation_configuration():
dump_artifacts_on_unexpected_failures=False,
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location="ConcreteNumpyKeyCache",
insecure_key_cache_location="ConcretePythonKeyCache",
fhe_simulation=True,
fhe_execution=False,
compress_input_ciphertexts=True,
)


Expand Down
4 changes: 2 additions & 2 deletions docker/release_resources/sanity_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def main(args):

keyring_dir_as_str = None
if is_fast:
keyring_dir = Path.home().resolve() / "ConcreteNumpyKeyCache"
keyring_dir = Path.home().resolve() / "ConcretePythonKeyCache"
keyring_dir.mkdir(parents=True, exist_ok=True)
keyring_dir_as_str = str(keyring_dir)
print(f"Using {keyring_dir_as_str} as key cache dir")
Expand All @@ -162,7 +162,7 @@ def main(args):
cn_check(args, keyring_dir_as_str)

if is_fast:
keyring_dir = Path.home().resolve() / "ConcreteNumpyKeyCache"
keyring_dir = Path.home().resolve() / "ConcretePythonKeyCache"
if keyring_dir is not None:
# Remove incomplete keys
for incomplete_keys in keyring_dir.glob("**/*incomplete*"):
Expand Down
3 changes: 1 addition & 2 deletions src/concrete/ml/quantization/quantized_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,6 @@ def compile(
# Find the right way to set parameters for compiler, depending on the way we want to default
p_error, global_p_error = manage_parameters_for_pbs_errors(p_error, global_p_error)

# Jit compiler is now deprecated and will soon be removed, it is thus forced to False
# by default
self.fhe_circuit = compiler.compile(
inputset,
configuration=configuration,
Expand All @@ -745,6 +743,7 @@ def compile(
single_precision=False,
fhe_simulation=False,
fhe_execution=True,
compress_input_ciphertexts=True,
)

self._is_compiled = True
Expand Down
3 changes: 1 addition & 2 deletions src/concrete/ml/sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ def compile(
f"{type(module_to_compile)}."
)

# Jit compiler is now deprecated and will soon be removed, it is thus forced to False
# by default
self.fhe_circuit_ = module_to_compile.compile(
inputset,
configuration=configuration,
Expand All @@ -572,6 +570,7 @@ def compile(
single_precision=False,
fhe_simulation=False,
fhe_execution=True,
compress_input_ciphertexts=True,
)

self._is_compiled = True
Expand Down
4 changes: 2 additions & 2 deletions use_case_examples/cifar/cifar_brevitas_finetuning/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ profile_default/
ipython_config.py

# Key cache
ConcreteNumpyKeyCache
ConcretePythonKeyCache

# Data
/data/
/data/

0 comments on commit 8eaccb6

Please sign in to comment.