Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: integrate Concrete Python 2.5.0rc1 #367

Merged
merged 7 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ OPEN_PR="true"
# Force the installation of a Concrete Python version, which is very useful with nightly versions
# /!\ WARNING /!\: This version should NEVER be a wildcard as it might create some
# issues when trying to run it in the future.
CONCRETE_PYTHON_VERSION="concrete-python==2.4.0"
CONCRETE_PYTHON_VERSION="concrete-python==2.5.0rc1"

# Force the installation of Concrete Python's latest version, release-candidates included
# CONCRETE_PYTHON_VERSION="$$(poetry run python \
Expand Down
2 changes: 1 addition & 1 deletion deps_licenses/licenses_linux_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.4.0, BSD-3-Clause
concrete-python, 2.5.0rc1, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down
2 changes: 1 addition & 1 deletion deps_licenses/licenses_linux_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5ea389d8b97dc534603abf9b77ff8a40
6e23de913fba55c72e9420fdef5e78de
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_intel_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.4.0, BSD-3-Clause
concrete-python, 2.5.0rc1, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_intel_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5ea389d8b97dc534603abf9b77ff8a40
6e23de913fba55c72e9420fdef5e78de
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_silicon_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ certifi, 2023.7.22, Mozilla Public License 2.0 (MPL 2.0)
charset-normalizer, 3.2.0, MIT License
click, 8.1.7, BSD License
coloredlogs, 15.0.1, MIT License
concrete-python, 2.4.0, BSD-3-Clause
concrete-python, 2.5.0rc1, BSD-3-Clause
dependencies, 2.0.1, BSD License
dill, 0.3.7, BSD License
exceptiongroup, 1.1.3, MIT License
Expand Down
2 changes: 1 addition & 1 deletion deps_licenses/licenses_mac_silicon_user.txt.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5ea389d8b97dc534603abf9b77ff8a40
6e23de913fba55c72e9420fdef5e78de
31 changes: 16 additions & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ readme = "README.md"
# Investigate if it is better to fix specific versions or use lower and upper bounds
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/2665
python = ">=3.8.1,<3.11"
concrete-python = "2.4.0"
concrete-python = "2.5.0-rc1 "
setuptools = "65.6.3"
skops = {version = "0.5.0"}
xgboost = "1.6.2"
Expand Down
7 changes: 3 additions & 4 deletions src/concrete/ml/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@

MAX_BITWIDTH_BACKWARD_COMPATIBLE = 8

# Use new VL with .simulate() by default once CP's multi-parameter/precision bug is fixed
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3856
# Indicate if the old simulation method should be used when simulating FHE executions
USE_OLD_VL = True
# Indicate if the old virtual library method should be used instead of the compiler simulation
# when simulating FHE executions
USE_OLD_VL = False

# Debug option for testing round PBS optimization
# Setting this option to true will make quantizers "round half up"
Expand Down
9 changes: 2 additions & 7 deletions src/concrete/ml/quantization/quantized_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ def _fhe_forward(self, *q_x: numpy.ndarray, simulate: bool = True) -> numpy.ndar

# If the old simulation method should be used
if USE_OLD_VL:
predict_method = partial(
predict_method = partial( # pragma: no cover
self.fhe_circuit.graph, p_error=self.fhe_circuit.p_error
)

# Else, use the official simulation method
else:
predict_method = self.fhe_circuit.simulate # pragma: no cover
predict_method = self.fhe_circuit.simulate

# Else, use the FHE execution method
else:
Expand Down Expand Up @@ -691,11 +691,6 @@ def compile(
jit=False,
)

# CRT simulation is not supported yet
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3841
if not USE_OLD_VL:
self.fhe_circuit.enable_fhe_simulation() # pragma: no cover

self._is_compiled = True

return self.fhe_circuit
Expand Down
13 changes: 4 additions & 9 deletions src/concrete/ml/sklearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,11 @@ def compile(
jit=False,
)

self._is_compiled = True

# For mypy
assert isinstance(self.fhe_circuit, Circuit)

# CRT simulation is not supported yet
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3841
if not USE_OLD_VL:
self.fhe_circuit.enable_fhe_simulation() # pragma: no cover

self._is_compiled = True

return self.fhe_circuit

@abstractmethod
Expand Down Expand Up @@ -639,13 +634,13 @@ def predict(self, X: Data, fhe: Union[FheMode, str] = FheMode.DISABLE) -> numpy.

# If the old simulation method should be used
if USE_OLD_VL:
predict_method = partial(
predict_method = partial( # pragma: no cover
self.fhe_circuit.graph, p_error=self.fhe_circuit.p_error
)

# Else, use the official simulation method
else:
predict_method = self.fhe_circuit.simulate # pragma: no cover
predict_method = self.fhe_circuit.simulate

# Else, use the FHE execution method
else:
Expand Down
16 changes: 10 additions & 6 deletions tests/torch/test_compile_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,16 @@ def accuracy_test_rounding(

# Check modules predictions FHE simulation vs Concrete ML.
check_is_good_execution_for_cml_vs_circuit(x_test, quantized_numpy_module, simulate=simulate)
check_is_good_execution_for_cml_vs_circuit(
x_test, quantized_numpy_module_round_high_precision, simulate=simulate
)
check_is_good_execution_for_cml_vs_circuit(
x_test, quantized_numpy_module_round_low_precision, simulate=simulate
)

# Enable back the rounding tests (simulate and FHE) once Concrete Python fixes the simulation
# issue with rounding
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/4048
# check_is_good_execution_for_cml_vs_circuit(
# x_test, quantized_numpy_module_round_high_precision, simulate=simulate
# )
# check_is_good_execution_for_cml_vs_circuit(
# x_test, quantized_numpy_module_round_low_precision, simulate=simulate
# )

# Check that high precision gives a better match than low precision
# MSE is preferred over MAE here to spot a lack of diversity in the 2 bits rounded model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import time
from functools import partial
from pathlib import Path

import torch
Expand Down Expand Up @@ -134,17 +133,16 @@ def wrapper(*args, **kwargs):
print(f"Quantization of a single input (image) took {quantization_execution_time} seconds")
print(f"Size of CLEAR input is {q_x_numpy.nbytes} bytes\n")

# Use new VL with .simulate() once CP's multi-parameter/precision bug is fixed
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3856
p_error = quantized_numpy_module.fhe_circuit.p_error
expected_quantized_prediction, clear_inference_time = measure_execution_time(
partial(quantized_numpy_module.fhe_circuit.graph, p_error=p_error)
quantized_numpy_module.fhe_circuit.simulate
)(q_x_numpy)

# Encrypt the input
encrypted_q_x_numpy, encryption_execution_time = measure_execution_time(
quantized_numpy_module.fhe_circuit.encrypt
)(q_x_numpy)

print(f"Encryption of a single input (image) took {encryption_execution_time} seconds\n")

print(f"Size of ENCRYPTED input is {quantized_numpy_module.fhe_circuit.size_of_inputs} bytes")
Expand Down
4 changes: 1 addition & 3 deletions use_case_examples/llm/QuantFrameworkExample.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,7 @@
"clear_evaluation = f(input_0)\n",
"\n",
"# Compute the result in the clear using FHE simulation\n",
"# Use new VL with .simulate() once CP's multi-parameter/precision bug is fixed\n",
"# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3856\n",
"simulated_evaluation = circuit.graph(input_0, p_error=circuit.p_error)\n",
"simulated_evaluation = circuit.simulate(input_0)\n",
"\n",
"# Compute the result in FHE\n",
"fhe_evaluation = circuit.encrypt_run_decrypt(input_0)\n",
Expand Down
4 changes: 1 addition & 3 deletions use_case_examples/llm/qgpt2_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ def run_torch(self, inputs: torch.Tensor, fhe: str = "disable", true_float: bool
q_x = np.expand_dims(q_x, axis=0)

if fhe == "simulate":
# Use new VL with .simulate() once CP's multi-parameter/precision bug is fixed
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/3856
q_y = self.circuit.graph(q_x, p_error=self.circuit.p_error)
q_y = self.circuit.simulate(q_x)

elif fhe == "execute":
q_y = self.circuit.encrypt_run_decrypt(q_x)
Expand Down