Weirdly high accuracy compared to seal

Hello all,

I am using the CKKS implementation of OpenFHE to do PPML, and I have a working implementation of Tenseal, agains which I am comparing OpenFHE. Now when I am running an inference session over a Pneumonia MNIST model, which does not use Polynomial approximation due to only having Square activation functions, I get an insanely high accuracy from OpenFHE compared to Tenseal, although it should be using the same parameters.

For Tenseal (Seal) I am entering the params:
poly_modulus_degree = 8192
coeff_mod_bit_sizes = [34, 25, 25, 25, 25, 25, 25, 34]

As far as I understood this translates to: (parameter object implicit)

Activated FHE features are:

Now for the inference results. For just one example I get the outputs:
Tenseal: [-7.008189 5.3304128]
OpenFHE: [-9.62276159 7.14398429]
Plain: [-9.666669 7.1789775]

Linear layers are carried out on flattened inputs using matrix multiplication. Am I getting something wrong with translating the parameters here, or what seems to be the issue?

Cheers and thanks in advance

FLEXIBLEAUTO (with a different scaling factor for each level) has a higher precision than the mode where the same scale is used for all levels (called FIXEDAUTO in OpenFHE). My guess is that you are using SEAL in the mode comparable to FIXEDMANUAL (in SEAL, the developer has to compute scaling factors on their own - not done by the library).

A simple test you can try: change the scaling techniques from FLEXIBLEAUTO to FIXEDAUTO and see how much worse the accuracy will become.

Thank you! So the accuracy is not weirdly high after all!

I still have one question however: Why does it not create the crypto context if I set the security standard to 128, although I get \log(mod) = 184.031?

Cheers and thanks in advance

For RLWE, the ring dimension for CKKS with hybrid key switching is determined by \log Q + \log P, where Q corresponds to the ciphertext modulus and P is the auxiliary modulus used for hybrid key switching (by default, \log P \approx \frac{1}{3} \log Q. In your case, you need to bump up the ring dimension to 16K or use a larger number of digits for hybrid key switching to make \log P smaller.

A suggestion related to the use of the DIscourse forum: please use different topics for different questions.

1 Like

Suggestion noted, I think now it is too late to start a new thread about this. So it should work if I set the KeySwitchTechnique to BV? What other implication does this have?

It’s slower than the hybrid key-switching technique. Check Table 4 here.