Encouter Exception "what(): DropLastElement: Removing last element of DCRTPoly renders it invalid." during runtime.
Closed this issue · 4 comments
I encoutered an error during runtime.
The version of OpenFHE I am using is v1.1.3,
the command I execute is:
./LowMemoryFHEResNet20 generate_keys 1
./LowMemoryFHEResNet20 load_keys 1 input "inputs/vale.jpg"
The first command runs successfully while the second one will encouter an exception:
Encrypted ResNet20 classification started.
I am going to encrypt and classify ../inputs/vale.jpg.
terminate called after throwing an instance of 'lbcrypto::OpenFHEException'
what(): DropLastElement: Removing last element of DCRTPoly renders it invalid.
Aborted (core dumped)
That's weird, I replicated the commands and I obtained:
narger@MacBook-Pro-di-Lorenzo build % ./LowMemoryFHEResNet20 generate_keys 1
Ciphertexts depth: 23, available multiplications: 7
You are using log(Q+P) = 1756
Context built, generating keys...
Generated.
Now serializing keys ...
EvalMult keys have been serialized
Crypto Context have been serialized
Public Key has been serialized
Secret Key has been serialized
Rotation keys "rotations-layer1.bin" have been serialized
Rotation keys "rotations-layer2-downsample.bin" have been serialized
Rotation keys "rotations-layer2.bin" have been serialized
Rotation keys "rotations-layer3-downsample.bin" have been serialized
Rotation keys "rotations-layer3.bin" have been serialized
Rotation keys "rotations-finallayer.bin" have been serialized
Context created correctly.
narger@MacBook-Pro-di-Lorenzo build % ./LowMemoryFHEResNet20 load_keys 1 input "inputs/vale.jpg"
Encrypted ResNet20 classification started.
I am going to encrypt and classify ../inputs/vale.jpg.
Decrypting the output...
Output: [ -0.384, -2.183, -2.889, 2.112, -1.509, 9.036, -1.412, -1.074, -0.251, -1.438 ]
The input image is classified as Dog
The index of max element is 5
Your error says that it is trying to reseale a ciphertext at the last level, I guess it is happening before the bootstrapping. I wonder if OpenFHE's last version has something different in that procedure.
Could you please:
- Clear the generated keys in the
keys_exp1
folder - Change line 123 of
FHEController.cpp
touint32_t levelsUsedBeforeBootstrap = get_relu_depth(relu_deg) + 4;
- Re-execute the code
?
Thank you
Sorry for late response, it could now successfully run after changing the levels and ring size. Thanks!
The problem is that using by uint32_tlevelsUsedBeforeBootstrap = get_relu_depth(relu_deg) + 4
, the modulus becomes too large and the security goes below
I don't know why with newer versions the errorDropLastElement: Removing last element of DCRTPoly renders it invalid.
pops up, so I suggest you different alternatives:
- Use OpenFHE v1.0.4, OR
- Remove the 128 bits of security constraint (by using this line:
parameters.SetSecurityLevel(SecurityLevel::HEStd_NotSet);
), OR - Increase the ring size to
$2^{17}$ by changing the first argument ofgenerate_context
from 16 to 17 (notice that the performance will degrade, and the required memory doubled).