microsoft / EVA

Compiler for the SEAL homomorphic encryption library
MIT License
218 stars 57 forks source link

How to control the maximum vector size in EVA?? #12

Open 2w21234 opened 3 years ago

2w21234 commented 3 years ago

Hi, I'm running EVA with 16384-length per a individual(sample) data for a simple model. In the end of the execution, I had the following warning message,

'WARNING: Program uses vector size 16384 while only 4096 slots are required for security. This does not affect correctness, but higher performance may be available with a smaller vector size.'

So, I tried changing some parameters such as 'model.set_input_scales' and 'model.set_output_ranges', and the required slots (4096 above) has changed to 16384 (maximum case in my case).

If I want use more samples (a vector with length 16384*2 ), then 16384 slots are still less to avoid that warning message.

I have two quenstions.

  1. Is there any way to control the maximum slots (acceptable length of input vector)?
  2. Does the warning message mean that the the security is loosened mathematically?

Thank you in advance for your reply :)

olsaarik commented 3 years ago

The warning is more of a performance hint than a problem to be fixed. What it is saying is that using smaller vectors (down to that 4096) would allow each individual operation in the program to be faster. So if it would be possible in your program to split your 16384 sized vectors into four smaller ones, then you might get better end-to-end performance. Whether this is possible depends on your program, for example if you need to do many rotations by numbers that are not a multiple of 4096, then it is not easy to do such a transformation. It is fully fine to just ignore this warning.

You can turn the warning off by passing "warn_vec_size":"false" to the config of the compiler as is done for example here: https://github.com/microsoft/EVA/blob/main/tests/large_programs.py#L137

To answer your questions:

  1. The 4096 number of slots is actually the minimum required for security. Larger ones are acceptable. This minimum is essentially determined by the multiplicative depth of the program and is affected by the scales you set (as you found). Both reducing the depth of the program in multiplications and reducing the scales will lower this (and generally result in better performance).
  2. The security is always guaranteed. In fact if you use a vec_size lower than that minimum, EVA will emulate that smaller vec_size with a larger one to meet the security guarantees. It will also give you a similar warning indicating that you could use a larger vec_size for no additional cost.

Also thank you for filing an issue. This warning is clearly something we could improve the wording in.

2w21234 commented 3 years ago

I really want to thank you for your help. 👍🏼