Batch Input Examples

This section provides practical demonstrations of FHEON for batch processing: every ciphertext holds one channel of a whole batch of images, so one encrypted evaluation classifies the batch. The examples are built with -DMODE=BATCH_INPUTS (HEStandardBatchModels/), for ResNet-20 and ResNet-34 with batch sizes from 16 to 512 (-DBATCH_SIZE) and for LeNet-5. The batch models run multithreaded, on FHEONANNStandardBatchThreadedController (the multithreaded FHEONANNStandardBatchController, see FHEON’s Controllers); --threads N caps the worker threads.

Every batch model evaluates any number of images: --test-size images from --index-value on (or a file of selected images), in runs of its batch size; the last run is completed with blank images, which are evaluated but not reported.

The pipelines with accumulators BResNet20Pipeline, BResNet34Pipeline, BVGG11Pipeline and BVGG16Pipeline keep every ciphertext full: groups of 16 images enter the network, and after every stride-2 block (or average pooling) an accumulator merges 4 groups into the freed slots, so one pipeline holds 256 (ResNet-20), 1024 (ResNet-34) or 4096 (VGG) images. Fewer images run the same circuit with partly filled accumulators. The global average pooling and the linear layers are packed linear layers (he_batch_linear_packed), which scale to the 1024-wide layers of VGG and the 100 classes of ResNet-34.

Security Levels and Packing

With the performance-efficient parameters every batch program uses the ring dimension and slot count of its HEConfig: 2^15 and 2^14 slots for most of them, so a ciphertext holds one channel of 16 CIFAR images of 32 x 32. At a standard security level (-DSECURITY_LEVEL=128, 192 or 256) OpenFHE takes the smallest ring dimension the HE standard allows for the modulus chain, which is larger: 2^16 at 128 bits for the ResNet chains, and a 2^16 ring holds 2^15 slots. The batch programs set HEConfig.fillSlots: the context then packs every slot of that ring (FHEONHEController::num_slots is half the ring dimension) instead of leaving half of them as copies, and each program multiplies its packing by FHEONHEController::slot_scale(numSlots): the images per ciphertext of every stage, the bootstrapped slot counts and the rotation splits (scale_rotation_split). A run takes slot_scale times more images for about the same cost per ciphertext:

Programs

Performance efficient

128-bit

192 / 256-bit

BLeNet5N16, BResNet20N16, BResNet34N16 (2^14 slots)

16 images

32 (ring 2^16)

64 (ring 2^17)

BResNet20N64, BResNet34N64

64

128

256

BResNet20N32, BResNet34N32 (2^15 slots, ring 2^16 already)

32

32

64

Pipelines (BResNet20Pipeline, …)

groups of 16

groups of 32

groups of 64

The program prints the packing it uses (Security level packing: 2x the images per ciphertext), and the keys it generates record the slot count (num_slots.txt), so --load-context runs with the packing of the saved keys.