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: knn tuto #333

Merged
merged 8 commits into from
Oct 17, 2023
Merged

chore: knn tuto #333

merged 8 commits into from
Oct 17, 2023

Conversation

kcelia
Copy link
Collaborator

@kcelia kcelia commented Oct 3, 2023

In this PR, I added a new tutorial for KNN.

As you know, this model is really restrictive, as we are not able to exceed 9bits in the circuit, without having to wait > 1h for geyken + facing unstable execution with the compiler.

To apply the rounded features, we need to :

  • provide the "rounding_threshold_bits (int)" parameter
  • once rounding_threshold_bits parameter is provided, it will allow the instantiation of an auto-rounder object that will be used after the distance computation in 'inference'
  • force the compiler to use auto_adjust_rounders to True.

I want your advice to know where rounding_threshold_bits should be set for the user:

  • init:
    - naturel place for arguments
    - easy to add
    - but knn won't follow other CML patterns
  • in the compiler:
    - which seems more appropriate.
    - The way I see it, the auto-rounder object will be instantiated in this function. But it won't work if we use 'predict=disable', unless if I put a condition to skip the auto-rounder. But the big problem is that we won't have same results with and without auto-rounder.
  • fit, the paramater

(for Q4, we will try to add this feature it to our built-in models, so it's like an advanced conversion)

CC @zama-ai/machine-learning


We agreed to hide the parameter rounding_threshold_bits to the user and add a default value in base.py.
I suggest the value 5, you can see the plots in this branch 'testing/impact_of_rouning_on_knn' in use_case_example folder.

Update:
<!> The tests when we do not compile before the prediction, typically for fhe=disable are crushing, because we use the autorounder and we havent compiled the model !

New update:
I used the adjust method instead of the compilation to use the autorounder feature.
The concrete python autorounder must become a serialized object !

@cla-bot cla-bot bot added the cla-signed label Oct 3, 2023
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from b87a733 to 75f6277 Compare October 3, 2023 19:49
@kcelia kcelia marked this pull request as ready for review October 4, 2023 07:50
@kcelia kcelia requested a review from a team as a code owner October 4, 2023 07:50
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from 087b198 to 7ce1dda Compare October 13, 2023 12:24
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from 7ce1dda to 776e704 Compare October 13, 2023 12:27
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.

Looks pretty good! But I'd still like to see some graphs for rounding bits vs accuracy first.

  1. "b. Simulation: inference on non-encrypted quantized data, while simulating all FHE operations, failure probabilities and crypto-parameters. This mode of inference is recommended in the deployment phase. For further information, please consult this link"

I think you mean "development" not "deployment"

  1. you mention "accuracy loss" in the last line in the notebook but there is actually a 5% gain. You could say "accuracy difference"

@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from e29a76d to 7a38f81 Compare October 16, 2023 08:22
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from 7a38f81 to f5bb445 Compare October 16, 2023 08:24
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch 4 times, most recently from f20e5b6 to 2bb1fd0 Compare October 16, 2023 12:45
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch 2 times, most recently from 04ac5df to 26bb7b3 Compare October 16, 2023 13:25
@kcelia kcelia force-pushed the add_tuto_knn_4038 branch from 26bb7b3 to 1203403 Compare October 16, 2023 14:48
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 !

@github-actions
Copy link

Coverage passed ✅

Coverage details

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

51 files skipped due to complete coverage.

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.

Good job on this !

@kcelia kcelia merged commit 50bfc8d into main Oct 17, 2023
8 checks passed
@kcelia kcelia deleted the add_tuto_knn_4038 branch October 17, 2023 08:11
@kcelia kcelia mentioned this pull request Oct 18, 2023
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.

5 participants