Why different image get different complexity in same model

I use use_case_examples to inference CIFAR-10. I use the same VGG9 model to inference different images, but the complexity is different. As I understand, the number of parameters does not change, so I am curious why the complexity is different.

Thank you.

Could you please explain what “complexity” you measure and how you measure it ?

1 Like

Thanks for your reply. I use built-in API to measure “complexity” in concrete-ml .

print(f"Complexity is {quantized_numpy_module.fhe_circuit.complexity}\n")

You can see this code in (zama-ai/concrete-ml/tree/main/use_case_examples/cifar/cifar_brevitas_training/evaluate_one_example_fhe.py)

You can see I executed this file with different images using the same model. Their accumulators bit-width and the number of parameters are equal, but the complexity is different.

First attempt:
Files already downloaded and verified
Compiling the model.
Compilation time took 14.135635375976562 seconds
Max bit-width used in the circuit: 13 bits
Saving graph and mlir to disk.
Creation of the private and evaluation keys.
KeySetCache: miss, regenerating /home/decloak/cifar_brevitas_training/.keycache/4155552678911712866
Keygen took 1.2315690517425537 seconds
Quantization of a single input (image) took 0.00011324882507324219 seconds
Size of CLEAR input is 24576 bytes

Encryption of a single input (image) took 0.13261818885803223 seconds

Size of ENCRYPTED input is 37773312 bytes
Size of ENCRYPTED output is 163920 bytes
Size of keyswitch key is 0 bytes
Size of bootstrap key is 0 bytes
Size of secret key is 57520 bytes
Complexity is 52472421890320.0

Second attempt:

Compiling the model.
Compilation time took 14.469098567962646 seconds
Max bit-width used in the circuit: 13 bits
Saving graph and mlir to disk.
Creation of the private and evaluation keys.
KeySetCache: miss, regenerating /home/decloak/cifar_brevitas_training/.keycache/11780755650751906266
Keygen took 2.332667589187622 seconds
Quantization of a single input (image) took 0.00011467933654785156 seconds
Size of CLEAR input is 24576 bytes

Encryption of a single input (image) took 0.1078648567199707 seconds

Size of ENCRYPTED input is 37773312 bytes
Size of ENCRYPTED output is 163920 bytes
Size of keyswitch key is 0 bytes
Size of bootstrap key is 0 bytes
Size of secret key is 97008 bytes
Complexity is 53007351353024.0

Thank you.

I think there might be a slight difference in the “input-sets” used between the two runs. This may produce slightly different bounds for the intermediate values, resulting in different crypto-parameters being generated. Thus the complexity can vary, but the difference is very slight and does not change the FHE execution time.

Thank you very much for your detailed reply. Your explanation has been helpful to me.