Hi, I’m tryng to make a comparison between plaintext and ciphertext MB sizes.
I believe that the encrypted ciphertext should be heavier, but this doesn’t seem to reflect on the results from the code. I don’t know if I’m simply wrong or if I’m computing the MB wrong.
To simplify, suppose server_input
is the input tensor to my custom Brevitas model (n_bits=6
) with 25088000 float32
elements, here is my code:
from concrete.ml.torch.compile import compile_brevitas_qat_model
from concrete.fhe.compilation import Configuration
import numpy as np
configuration = Configuration(
enable_unsafe_features=True,
use_insecure_key_cache=True,
insecure_key_cache_location=".keys",
)
n_bits=6
round_bits=5
p_error=1.e-7
clear_dim = server_input.nbytes/(1024**2)
print(f"MB in clear: {clear_dim} MB")
qmodel = compile_brevitas_qat_model(
torch_model=model.to('cpu'),
torch_inputset=server_input,
n_bits=n_bits,
rounding_threshold_bits=round_bits,
p_error=p_error,
device=compilation_device,
)
print("Quantized module compiled.")
server_input = server_input.numpy()
fhe_circuit = qmodel.compile(
inputs=server_input,
configuration=configuration,
)
print("FHE circuit compiled.")
print(f"Encryption keys: {fhe_circuit.size_of_secret_keys/(1024**2):.4f} MB")
print(f"Evaluation keys: {(fhe_circuit.size_of_bootstrap_keys+fhe_circuit.size_of_keyswitch_keys)/(1024**2):.4f} MB")
print(f"MB encrypted input: {fhe_circuit.size_of_inputs/(1024**2):.4f} MB")
When I run the code, I get:
MB in clear: 95.703125 MB
Quantized module compiled.
FHE circuit compiled.
Encryption keys: 0.1269 MB
Evaluation keys: 4178.2812 MB
MB encrypted input: 0.5742 MB
Why is it that before encrypting the tensor is so much bigger than the encrypted input? Shouldn’t it be the opposite?
EDIT:
I made some computations.
Plain:
25,088,000 elements * 32 bits = 802,816,000 bits = 100,816,000 bytes = 95.70 MB
6 bits quantization:
25,088,000 elements * 6 bits = 150,528,000 bits = 18,816,000 bytes = 17.94 MB
Encryption: since 6 bits are encrypted in a single 8 bits ciphertext, we still need 25,088,000 ciphertexts
y = # bits of a ciphertext
25,088,000*y/8/1024/1024 = … = maybe 574.2 MB ??? (just an hypothesis)
Since I considered 1000 samples in my batch, maybe 0.5742 MB was the size of just one of the 1000 samples? If I were right, y would be around 24 bytes.