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

Parameters validation for the FV scheme #3870

Merged
merged 4 commits into from
Jul 27, 2020

Conversation

rav1kantsingh
Copy link
Member

Description

closes #3792
Checks basic properties that the parameters should have while setting up, and tests the generated prime nos if those are correct.

Affected Dependencies

None

How has this been tested?

This code does not need to have dedicated tests and it is verified by already present tests.

Checklist

@rav1kantsingh rav1kantsingh added the Type: New Feature ➕ Introduction of a completely new addition to the codebase label Jul 17, 2020
@rav1kantsingh rav1kantsingh added this to the BFV Tensor in Python milestone Jul 17, 2020
len(params.coeff_modulus) > COEFF_MOD_COUNT_MAX
or len(params.coeff_modulus) < COEFF_MOD_COUNT_MIN
):
raise RuntimeError("Invalid coefficient modulus counts")
Copy link
Member

Choose a reason for hiding this comment

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

Can you specify in the error message the range of the coeffecients allowed and how many was passed?

if params.coeff_modulus[i] >> COEFF_MOD_BIT_COUNT_MAX or not (
params.coeff_modulus[i] >> (COEFF_MOD_BIT_COUNT_MIN - 1)
):
raise RuntimeError("Invalid coefficient modulus values")
Copy link
Member

Choose a reason for hiding this comment

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

same here

Comment on lines 53 to 55
# Compute the product of all coeff moduli
total_coeff_modulus = reduce(lambda x, y: x * y, params.coeff_modulus)
# total_coeff_modulus_bit_count = get_significant_count(total_coeff_modulus)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also verify that the total_coeff_modulus is good for our n-bit security level?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the code required for the security level checking. but It is currently commented with TODO because I would need to work on how to ask for the security level and if passed then it can be checked otherwise scheme will work without standard security.


# Check for the range of coefficient modulus primes.
for i in range(len(params.coeff_modulus)):
if params.coeff_modulus[i] >> COEFF_MOD_BIT_COUNT_MAX or not (
Copy link
Member

Choose a reason for hiding this comment

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

Maybe

params.coeff_modulus[i] > 2**COEFF_MOD_BIT_COUNT_MAX

Is clearer? I am always nervous about operator precedence. :D

Copy link
Member Author

Choose a reason for hiding this comment

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

But, bitwise operators will be much better for performance than exponentiation.

# Check all coeff moduli are relatively prime to plain_modulus
for i in range(len(params.coeff_modulus)):
for j in range(i):
if math.gcd(params.coeff_modulus[i], params.plain_modulus) > 1:
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the j loop here?

Copy link
Member Author

Choose a reason for hiding this comment

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

By mistake, I copied the above loop and forget to remove the j loop😅

@codecov
Copy link

codecov bot commented Jul 26, 2020

Codecov Report

Merging #3870 into master will decrease coverage by 0.17%.
The diff coverage is 67.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3870      +/-   ##
==========================================
- Coverage   95.07%   94.90%   -0.18%     
==========================================
  Files         186      199      +13     
  Lines       18868    20158    +1290     
==========================================
+ Hits        17939    19131    +1192     
- Misses        929     1027      +98     
Impacted Files Coverage Δ
syft/frameworks/torch/he/fv/util/fv_std_param.py 33.33% <33.33%> (ø)
syft/frameworks/torch/he/fv/modulus.py 80.95% <36.36%> (-15.83%) ⬇️
syft/frameworks/torch/he/fv/context.py 80.55% <79.41%> (-19.45%) ⬇️
...yft/frameworks/torch/he/fv/util/global_variable.py 100.00% <100.00%> (ø)
test/torch/tensors/test_fv.py 100.00% <100.00%> (ø)
syft/frameworks/torch/nn/conv.py 28.57% <0.00%> (-71.43%) ⬇️
syft/frameworks/torch/nn/functional.py 89.83% <0.00%> (-7.17%) ⬇️
syft/generic/pointers/object_pointer.py 78.35% <0.00%> (-3.87%) ⬇️
...orks/torch/tensors/interpreters/additive_shared.py 92.35% <0.00%> (-1.08%) ⬇️
...frameworks/torch/tensors/interpreters/precision.py 97.06% <0.00%> (-0.20%) ⬇️
... and 36 more

Copy link
Member

@bcebere bcebere left a comment

Choose a reason for hiding this comment

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

LGTM!

@rav1kantsingh rav1kantsingh changed the title [WIP] Parameters validation for the FV scheme Parameters validation for the FV scheme Jul 27, 2020
):
raise RuntimeError(
f"Invalid coefficient modulus count {len(params.coeff_modulus)}, "
+ "should be in range [1, 62]"
Copy link
Member

Choose a reason for hiding this comment

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

Better to use the variables directly here

Copy link
Member

Choose a reason for hiding this comment

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

[1, 62], in case those values change

):
raise RuntimeError(
f"Invalid coefficient modulus values {params.coeff_modulus[i]}, "
+ "should be in smaller than 60 bit number."
Copy link
Member

Choose a reason for hiding this comment

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

same here

@youben11 youben11 merged commit 786bb4a into OpenMined:master Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature ➕ Introduction of a completely new addition to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement parameter validation for FV scheme.
3 participants