IDEAS home Printed from https://ideas.repec.org/a/alk/fcsai0/v5y2026i9id13294.html

Optimizing Fully Homomorphic Encryption for Real-Time Transformer Inference

Author

Listed:
  • Kameran Ali Ameen

    (College of Computer Science and Information Technology, University of Kirkuk, Kirkuk, Iraq)

Abstract

Fully Homomorphic Encryption (FHE) allows Transformer inference to run end to end over encrypted inputs, but where its cost originates has remained unsettled: the encryption scheme, the Transformer's structure, or the library implementing it. This paper answers that question with an operation-level, measurement-first characterisation of a Transformer encoder layer under RNS-CKKS, implemented in TenSEAL over Microsoft SEAL at N = 16384 and Δ = 2⁴⁰. Three results are established by execution. First, the usable multiplicative depth of a chain of L primes is L − 2, not L − 1: a nine-prime chain of 400 bits admits exactly seven sequential ciphertext–ciphertext multiplications, and SEAL accepts that chain while rejecting a ten-prime chain of 440 bits against a 438-bit ceiling. Second, a level-by-level trace shows that a complete softmax requires eleven multiplicative levels and a complete encoder layer thirty-three, against the seven available; the softmax attempt aborts with a scale-overflow exception at the operation the trace identifies, so the depth wall is observed rather than asserted. Third, fully encrypted single-head attention (n = 8, dₖ = 16) reproduces the plaintext reference to a maximum absolute error of 3.19×10⁻⁶ and a cosine similarity of 0.9999999993, executing 384 ciphertext–plaintext multiplications, 2048 ciphertext–ciphertext multiplications and 1536 rotations counted by instrumentation. A cost model built on these counts places the compute-only latency of one encoder layer at 268.7 s under the layout implemented and 7.0 s under diagonal packing — a 38-fold span identifying ciphertext packing, not parameter choice, as the dominant lever. We further report three effects belonging to the library rather than the mathematics: an algebraically identical rewriting accelerates the Goldschmidt reciprocal by 29 to 31×; the vector-packing helper silently consumes one multiplicative level; and the ciphertext copy costs several times the reduction beside it. Because execution was on a shared virtual machine, host interference was measured rather than assumed and the full measurement set was run twice. Both sessions exceeded the discard threshold (coefficients of variation 38.7 % and 24.4 %), and the pair separates the results by class: all seven deterministic quantities are identical, the interleaved paired ratios agree to within 4.6 %, and absolute latencies differ by up to 27 %. Absolute latencies are therefore quoted as intervals and marked provisional; the depth accounting, level traces, operation counts, fidelity and parameter validation are final. Encrypted Transformer inference remains three to four orders of magnitude from the sub-100 ms real-time target; the contribution is an itemised, reproducible budget with an explicit account of which entries are measurements and which are projections.

Suggested Citation

  • Kameran Ali Ameen, 2026. "Optimizing Fully Homomorphic Encryption for Real-Time Transformer Inference," Frontiers in Computer Science and Artificial Intelligence, Al-Kindi Center for Research and Development, vol. 5(9), pages 299-319, June.
  • Handle: RePEc:alk:fcsai0:v:5:y:2026:i:9:id:13294
    DOI: 10.32996/fcsai.2026.5.9.20
    as

    Download full text from publisher

    File URL: https://al-kindipublisher.com/index.php/fcsai/article/view/13294
    File Function: Abstract page
    Download Restriction: no

    File URL: https://al-kindipublisher.com/index.php/fcsai/article/download/13294/12154
    File Function: Full text
    Download Restriction: no

    File URL: https://libkey.io/10.32996/fcsai.2026.5.9.20?utm_source=ideas
    LibKey link: if access is restricted and if your library uses this service, LibKey will redirect you to where you can use your library subscription to access this item
    ---><---

    More about this item

    Keywords

    ;
    ;
    ;
    ;
    ;
    ;
    ;

    Statistics

    Access and download statistics

    Corrections

    All material on this site has been provided by the respective publishers and authors. You can help correct errors and omissions. When requesting a correction, please mention this item's handle: RePEc:alk:fcsai0:v:5:y:2026:i:9:id:13294. See general information about how to correct material in RePEc.

    If you have authored this item and are not yet registered with RePEc, we encourage you to do it here. This allows to link your profile to this item. It also allows you to accept potential citations to this item that we are uncertain about.

    We have no bibliographic references for this item. You can help adding them by using this form .

    If you know of missing items citing this one, you can help us creating those links by adding the relevant references in the same way as above, for each refering item. If you are a registered author of this item, you may also want to check the "citations" tab in your RePEc Author Service profile, as there may be some citations waiting for confirmation.

    For technical questions regarding this item, or to correct its authors, title, abstract, bibliographic or download information, contact: Al-Kindi Center for Research and Development (email available below). General contact details of provider: https://al-kindipublisher.com/index.php/fcsai .

    Please note that corrections may take a couple of weeks to filter through the various RePEc services.

    IDEAS is a RePEc service. RePEc uses bibliographic data supplied by the respective publishers.