concrete icon indicating copy to clipboard operation
concrete copied to clipboard

Bootstraping result have low padding bits and/or precision bits

Open yxtj opened this issue 2 years ago • 4 comments

Describe the bug I am trying to use bootstraping to perform some neural-network-like computation. I need about 30 padding bits for the computation of a layer (like a weighted summation). But I cannot make it work. The result is either low in precision bits or low in padding bits. I don't know it is a bug or my configuration problem.

To Reproduce Since it is just a proof-of-concept, I just use low-security settings.

let encoder = Encoder::new(-10., 10., 10, 30)?; // 10 precision bits, 30 padding bits
let sk_rlwe = RLWESecretKey::new(RLWEParams::new(512, -43));
let sk_in = LWESecretKey::new(LWEParams::new(1024, 1, -43));
// 13 higher than padding bits of the encoder. so there is no warning
let bsk = LWEBSK::new(&sk_in, &sk_rlwe, 5, 3);

let m = 5.0;
let c1 = LWE::encode_encrypt(&sk_in, message, &encoder)?;
let c2 = c1.bootstrap(&bsk)?;

I got the following message after calling bootstrap:

Loss of precision during bootstrap: 34 bit(s) of precision lost over 10 bit(s) of message originally. Consider increasing the number of level and/or decreasing the log base.

And the result has 0 precision bit. The encoder of c2 is:

Encoder { -> [-10,10.019550342130987[ -> center = 0.009775171065493637 -> radius = 10.009775171065494 -> nb bit precision = 0 -> granularity = 20.019550342130987 -> nb bit padding = 30 -> round = false }

(So this is also a bug report for the display. The ending bracket should be "]". The same problem seems to happen on some other classes.)

I tried to tune the level and base-log of bootstraping, and the dimension and noise-log of key parameter, but I still the same problem.

Configuration(please complete the following information):

  • OS: [e.g. Ubuntu 20.04]

Other Questions: For bootstrapping, what is the relationship among input/output key dimension (key parameter), noise level (key parameter), input/output precision bits (encoder), input/output padding bits (encoder), level and base-log (bootstrapping). Is there a function/approximate function? Is there a way to estimate the parameter so as to satisfy my computing requirement?

yxtj avatar May 19 '22 20:05 yxtj

Base on the warning message, it seems that 34 bits is taken away. That is larger than the number of padding bits (30). I tried to reduce the padding bits in encoder. As my guess, It still does not work.

yxtj avatar May 20 '22 19:05 yxtj

The bootstrapping procedure is fairly constrained in the number of precision bits for the output. According to this answer the current supported maximum that is guaranteed to be noise-free is 9 bit. You can find the function estimating the output noise variance for the current release of Concrete here. The calculated variance is used here to determine the new precision, any bit of the ciphertext that is overlapped by this noise estimate is considered lost. As you can see from the function calculating the variance, the relationship between the noise estimation and the parameters is fairly complicated.

From experience experimenting with neural networks in Concrete, roughly 6 bits of precision and padding each are sufficient to run inference with smaller network architectures and are workable with the right choice of parameter, like the ones given in the Zama whitepaper. There will be noise contamination, but certain architectures and tasks show some resilience and still perform reasonable on encrypted data.

SpiralEndlessly avatar May 23 '22 11:05 SpiralEndlessly

Thanks @SpiralEndlessly . I will study more on it. BTY, what parameter configuration do you use in concrete-numpy and concrete-ml? I wonder is that possible for me to use that setting to quickly start my program?

yxtj avatar May 23 '22 19:05 yxtj

Hello @yxtj,

Regarding your example, we can not provide you with 10 precision bits and 30 padding bits. In concrete-numpy and concrete-ml we are using hardcoded sets of parameters based on the precision needed and the number of leveled operations between bootstraps.

If you try with an encoding of: -10, 10, 3, 0 you could use this parameters:

  size_t glweDimension = 1
  size_t logPolynomialSize = 10
  size_t nSmall = 599
  size_t brLevel = 3
  size_t brLogBase = 6
  size_t ksLevel = 6
  size_t ksLogBase = 2

But I dont know if it will be enough for you usecase.

aquint-zama avatar May 28 '22 10:05 aquint-zama