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

Testing/rounding feature on cml trees 4104 #392

Merged
merged 33 commits into from
Dec 13, 2023

Conversation

kcelia
Copy link
Collaborator

@kcelia kcelia commented Nov 13, 2023

  • MSB = 1:

The MSB is set to a value of 1 by default in all our tree-based models. This setting should give the fastest results without decreasing the model's performance. You can review the results of the experiments here.

  • Possible approaches to introduce this new feature in our API:

1. Using rounding_bit_padding and auto-rounding:

  • To use rounding as truncate, we subtract a term referred to as 'half,' which is calculated as '1 << (lsb - 1).'
  • When overflow is detected, an automatic update of the LSB occurs (decremented by 1), which affects the computation of the 'half' value and at the end leading to incorrect results.
  • Disabling the overflow check is not recommended

2. Using truncate and auto-truncate:

  • The API looks like rounding_bit_padding and auto-rounding
  • Not available yet

3. Computing the required bitwidth and LSB via the ONNX Graph: (WORKAROUNG)

  • check the overflow
  • This method involves checking for overflow and introducing new nodes in the ONNX graph.
  • 3.1: We can create new nodes in the ONNX graph. But some tests in 'tests/sklearn/test_sklearn_models.py::test_serialization' may fail due to manual build of 'tree_inference' using fake and non-representative inputs, without considering whether rounding is enabled or not. Because lambda functions can't be properly serialized, we want to limite the use of pickle see this conversation.
  • 3.2: We can add a flag lsbs_to_remove(Optional[int]) to existing ONNX nodes

In the current implementation, we have opted for approach 3 + adding a flag to existing nodes in the ONNX graph.
From time to time, we might get an overflow, but the issue problem is not reproducible.
eg: pytest tests/sklearn/test_sklearn_models.py::test_rounding_consistency[6-RandomForestClassifier1] --forcing_random_seed 8576543745180669800 --randomly-dont-reset-seed

The issue with the parallelization shared resources in concrete.fhe.extensions.round_bit_pattern.py is fixed.

closes https://github.com/zama-ai/concrete-ml-internal/issues/4157
ref Add new test for level 2
ref Add a test to check if graphs are identical after and before serialization
ref Control the maximum bitwidth of a circuit with rounding

@cla-bot cla-bot bot added the cla-signed label Nov 13, 2023
src/concrete/ml/onnx/convert.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/onnx_utils.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/onnx_utils.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/ops_impl.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/ops_impl.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/ops_impl.py Outdated Show resolved Hide resolved
src/concrete/ml/sklearn/base.py Outdated Show resolved Hide resolved
src/concrete/ml/sklearn/base.py Outdated Show resolved Hide resolved
tests/sklearn/test_sklearn_models.py Show resolved Hide resolved
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch from 5e89ffd to 692c4ae Compare November 15, 2023 10:45
src/concrete/ml/common/utils.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/ops_impl.py Outdated Show resolved Hide resolved
src/concrete/ml/sklearn/base.py Outdated Show resolved Hide resolved
src/concrete/ml/sklearn/base.py Outdated Show resolved Hide resolved
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch 5 times, most recently from 99cd997 to 66f6c41 Compare November 17, 2023 15:41
@kcelia kcelia changed the title Testing/rounding feature on cml trees 4104 Testing/rounding feature on cml trees 4104 [ON HOLD] Nov 20, 2023
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch 4 times, most recently from b933eeb to 74d8b97 Compare November 23, 2023 17:47
Copy link
Collaborator

@jfrery jfrery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a quick look. Great job! I have a few comments.

src/concrete/ml/onnx/onnx_utils.py Outdated Show resolved Hide resolved
src/concrete/ml/sklearn/base.py Show resolved Hide resolved
src/concrete/ml/onnx/convert.py Outdated Show resolved Hide resolved
src/concrete/ml/onnx/convert.py Show resolved Hide resolved
src/concrete/ml/onnx/onnx_utils.py Outdated Show resolved Hide resolved
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch 2 times, most recently from 17ef517 to f2a080e Compare November 27, 2023 16:55
src/concrete/ml/onnx/ops_impl.py Outdated Show resolved Hide resolved
@kcelia
Copy link
Collaborator Author

kcelia commented Dec 12, 2023

@RomanBredehoft is it ok for you ?

@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch 4 times, most recently from bca5660 to 4c3cdb1 Compare December 12, 2023 15:06
jfrery
jfrery previously approved these changes Dec 12, 2023
Copy link
Collaborator

@jfrery jfrery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this PR. Thanks Celia for taking all the comments into account. Let's continue this with truncate now!

Copy link
Collaborator

@andrei-stoian-zama andrei-stoian-zama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! thanks

src/concrete/ml/sklearn/base.py Outdated Show resolved Hide resolved
tests/sklearn/test_sklearn_models.py Outdated Show resolved Hide resolved
@kcelia kcelia dismissed stale reviews from andrei-stoian-zama and jfrery via 0272194 December 13, 2023 12:31
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch from 0272194 to ce2bc47 Compare December 13, 2023 14:56
the maximum_bit (of the circuit without rounding) = maximum_bitwidth (of
the circuit with rounding)
Remove the test with rounding for n_bits=11
@kcelia kcelia force-pushed the testing/rounding_feature_on_cml_trees_4104 branch from ce2bc47 to 586d7db Compare December 13, 2023 14:58
Copy link
Collaborator

@RomanBredehoft RomanBredehoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me , thanks a lot !

Copy link

Coverage passed ✅

Coverage details

---------- coverage: platform linux, python 3.8.18-final-0 -----------
Name    Stmts   Miss  Cover   Missing
-------------------------------------
TOTAL    6539      0   100%

51 files skipped due to complete coverage.

@kcelia kcelia merged commit 064eb82 into main Dec 13, 2023
9 checks passed
@kcelia kcelia deleted the testing/rounding_feature_on_cml_trees_4104 branch December 13, 2023 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants