Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
kcelia committed Jan 29, 2024
1 parent ee696ec commit 1c4ebc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/concrete/ml/quantization/post_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def _inspect_tree_n_bits(n_bits):
)


# Find a better naming to describe leaf quantization in tree-based models
# FIXME: https://github.com/zama-ai/concrete-ml-internal/issues/4258
def _get_n_bits_dict_trees(n_bits: Union[int, Dict[str, int]]) -> Dict[str, int]:
"""Convert the n_bits parameter into a proper dictionary for tree based-models.
Expand Down
16 changes: 8 additions & 8 deletions tests/sklearn/test_sklearn_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,39 +1210,39 @@ def check_fhe_sum_for_tree_based_models(

# Run the test with more samples during weekly CIs
if is_weekly_option:
fhe_test = get_random_samples(x, n_sample=5)
fhe_samples = 5
else:
fhe_samples = 1

fhe_test = get_random_samples(x, n_sample=fhe_samples)

# pylint: disable=protected-access
assert not model._fhe_ensembling, "`_fhe_ensembling` is disabled by default."
fit_and_compile(model, x, y)

non_fhe_sum_predict_quantized = predict_method(x, fhe="disable")
non_fhe_sum_predict_simulate = predict_method(x, fhe="simulate")
non_fhe_sum_predict_fhe = predict_method(fhe_test, fhe="execute")

# Sanity check
array_allclose_and_same_shape(non_fhe_sum_predict_quantized, non_fhe_sum_predict_simulate)

# Compute the FHE predictions only during weekly CIs
if is_weekly_option:
non_fhe_sum_predict_fhe = predict_method(fhe_test, fhe="execute")

# pylint: disable=protected-access
model._fhe_ensembling = True

fit_and_compile(model, x, y)

fhe_sum_predict_quantized = predict_method(x, fhe="disable")
fhe_sum_predict_simulate = predict_method(x, fhe="simulate")
fhe_sum_predict_fhe = predict_method(fhe_test, fhe="execute")

# Sanity check
array_allclose_and_same_shape(fhe_sum_predict_quantized, fhe_sum_predict_simulate)

# Check that we have the exact same predictions
array_allclose_and_same_shape(fhe_sum_predict_quantized, non_fhe_sum_predict_quantized)
array_allclose_and_same_shape(fhe_sum_predict_simulate, non_fhe_sum_predict_simulate)
if is_weekly_option:
fhe_sum_predict_fhe = predict_method(fhe_test, fhe="execute")
array_allclose_and_same_shape(fhe_sum_predict_fhe, non_fhe_sum_predict_fhe)
array_allclose_and_same_shape(fhe_sum_predict_fhe, non_fhe_sum_predict_fhe)


# Neural network models are skipped for this test
Expand Down

0 comments on commit 1c4ebc0

Please sign in to comment.