LLM Inference Performance and Cryptographic Security: An Engineering Validation Framework
This article presents an engineering framework for evaluating LLM inference performance, cryptographic protocol assurance, and FHE-based encrypted inference. It explains why inference speed depends on activated parameters, memory traffic, prefill and decoding bottlenecks, batching, and multi-accelerator communication; how to design reproducible benchmarks; why model-generated cryptographic proofs require explicit threat models and formal review; and how FHE systems must address operator approximation, ciphertext packing, noise budgets, and layered deployment. It concludes with a staged validation path that replaces single-number claims with an evidence chain.
1. Building a Unified Analysis Framework from Scattered Technical Observations
LLM deployment and privacy-preserving computation may appear to belong to different fields, but they share the same engineering problem: how to turn technical phenomena that “look effective” into system capabilities that are reproducible, explainable, and verifiable.
For example, on the same hardware, two models with similar parameter counts may show markedly different generation speeds. A model may be able to write a structurally complete proof of a cryptographic protocol without actually satisfying the required security definition. A set of encrypted inference methods may run smoothly on simple operators, but that does not mean it can directly support online serving for a complete model.
These observations suggest that we should distinguish three levels:
- Observed result: a speed, score, or runtime result obtained from one test.
- Explanatory hypothesis: what model structure, memory access, proof gap, or encrypted computation overhead may have caused the effect.
- Validated conclusion: which judgments can be confirmed through controlled experiments, a clear security model, and inspectable evidence.
The value of technical analysis is not to package a single result as a universal law, but to identify the key variables that affect the result and to state the conditions under which a conclusion holds.
2. Why Inference Speed Can Differ on the Same Hardware
2.1 Total Parameter Count Is Not the Only Measure of Inference Cost
When evaluating a language model, parameter count is intuitive, but it cannot by itself represent the computation required to generate each token.
In a dense structure, most parameters in the relevant layers participate in one forward computation. In a sparse expert structure, each token is usually routed to only a subset of experts, so the following factors must be examined separately:
- the total number of model parameters;
- the number of parameters actually activated per token;
- routing and expert scheduling overhead;
- where expert weights are stored;
- data transfer and synchronization costs.
A model with more total parameters may have lower computational cost because fewer parameters are activated. However, this does not mean a sparse structure is necessarily faster. If expert weights must be moved frequently, or if expert tasks are too fragmented, scheduling and memory-access overhead may offset the computational savings.
In addition, experts not activated by the current token still occupy storage. Lower computation and lower model storage requirements are two different matters.
2.2 Prefill and Token-by-Token Generation Have Different Bottlenecks
LLM inference can usually be divided into two stages.
The prefill stage processes the input context and generates the intermediate states needed for subsequent decoding. Multiple positions in the input can be computed in parallel to some extent, so it is relatively easy to use large-scale matrix computation capabilities.
The decoding stage generates new tokens step by step. A single request usually has sequential dependencies, and the computational tasks are relatively fine-grained. In small-batch scenarios, weight reads, cache access, and operator launch overhead may become the main bottlenecks.
Therefore, “inference speed” should be broken down into at least the following metrics:
| Metric | Primary Meaning | Key Influencing Factors |
|---|---|---|
| Time to first token | Time from submitting a request to receiving the first output | Queuing, prefill, scheduling |
| Inter-token latency | Time interval between consecutive outputs | Decoding computation, memory access, synchronization |
| Per-request generation speed | Speed at which one request generates output | Model structure, context length, execution method |
| System throughput | Total output completed by all requests per unit time | Concurrency, batching, cache capacity |
| End-to-end request latency | Total time from request entry to output completion | Input and output length, load, queuing |
If a scheme uses a larger batch, it may achieve higher total throughput while making individual requests wait longer. Different metrics answer different business questions and cannot be used interchangeably.
2.3 The Memory System May Matter More Than Peak Compute
The nominal compute capability of hardware cannot be used directly to infer actual generation speed. For memory-bound workloads, a simplified lower bound can help explain execution time:
The lower bound on execution time is approximately the larger of compute time and data-access time.
Compute time depends on the effective amount of computation and actual computational efficiency; data-access time depends on the amount of data that must be moved and the effective bandwidth. Real execution also adds scheduling, synchronization, and other overheads that cannot be fully overlapped.
As context length increases, the key-value cache associated with attention usually becomes larger. As concurrency increases, cache capacity pressure may limit batch size or even trigger data movement. Therefore, performance rankings obtained with short contexts cannot necessarily be generalized to long-context scenarios.
2.4 Multiple Accelerators Do Not Guarantee Proportional Speedup
Distributing a model across multiple accelerators can usually alleviate capacity shortages, but it also introduces communication costs.
Factors affecting the result include:
- how the model is partitioned;
- the volume of data exchanged between accelerators;
- interconnect bandwidth and communication latency;
- whether the task on each device is large enough;
- whether synchronization points are too frequent;
- whether input/output and host-side processing become bottlenecks.
If the computation for each decoding step is small but repeated cross-device synchronization is required, multi-device deployment may mainly solve the problem of “fitting the model” rather than “running it faster.”
3. How to Design Trustworthy Inference Benchmarks
3.1 Define Business Goals Before Choosing Metrics
Interactive applications usually focus on time to first token, output smoothness, and high-percentile request latency. Offline processing focuses more on throughput and resource utilization. Long-document analysis requires particular attention to cache occupancy and performance degradation under long contexts.
Before testing, clarify:
- Is this single-user interaction or multi-user concurrency?
- What is the distribution of input lengths and output lengths?
- Is a fixed generation length required?
- Is cache reuse allowed?
- Must a quality threshold be met?
- Are there strict resource capacity limits?
Without these constraints, a single “speed multiplier” is difficult to convert into a deployment decision.
3.2 Standardize Key Experimental Conditions
Cross-model comparisons cannot make all internal implementations identical, but external conditions should be standardized as much as possible, and differences that cannot be standardized should be recorded.
Recommended records include:
- model structure, total parameter count, and activated parameter count;
- weight precision and quantization method;
- cache precision;
- input and output lengths;
- batch size and concurrency;
- hardware capacity, bandwidth, and interconnect conditions;
- execution environment version;
- whether prefix reuse or other acceleration mechanisms are enabled;
- whether the model fully resides in accelerator memory.
Quantization especially needs to be described separately. Reducing weight precision can usually reduce storage and read pressure, but the benefit depends on the execution implementation and may change output quality. Results under different precision conditions cannot be simply interpreted as evidence of model architecture superiority or inferiority.
3.3 Separate Cold Start from Steady-State Operation
The first request may include weight loading, memory allocation, execution-path initialization, and other overheads. Tests should separately measure:
- cold-start time;
- steady-state inference after warm-up;
- throughput and latency under sustained load;
- resource changes after long-running operation.
Each condition should be measured repeatedly, and at minimum the sample count, median, and high-percentile results should be reported. Do not select only the fastest run as representative.
3.4 Use Experiments to Validate Performance Explanations Step by Step
After observing a speed difference, it is not appropriate to immediately attribute it to one architecture. Experiments can be conducted in sequence:
- change input length and observe how prefill time changes;
- fix the input, increase output length, and observe whether decoding remains stable;
- change concurrency to distinguish throughput gains from queuing costs;
- inspect memory occupancy and data movement;
- analyze compute utilization, communication time, and synchronization waits;
- where feasible, change weight precision to assess the effect of memory access.
Changing only a small number of variables at a time helps establish a more credible causal explanation. At the same time, task-quality tests should be included to avoid mistaking speed gains caused by quality degradation for system optimization.
4. Why Model-Generated Cryptographic Protocol Proofs Cannot Be Accepted Directly
4.1 Security Conclusions Must Be Bound to an Explicit Threat Model
“The protocol is secure” is not a complete proposition. A security conclusion that can be reviewed must state at least:
- what the attacker can observe and control;
- whether adaptive queries can be made;
- whether parties are allowed to be compromised;
- which computational hardness assumptions are used;
- whether the goal is confidentiality, integrity, authentication, or another property;
- whether the protocol considers concurrent execution, replay, and state leakage.
Under different threat models, the same protocol may lead to different conclusions. If a model ignores these conditions, even coherent textual reasoning may not prove the properties actually required.
4.2 Proof Text and a Valid Proof Are Different Levels
Automatically generated proofs may contain security games, reductions, and probability bounds, but they may still contain subtle errors, such as:
- the reduction does not have the ability to simulate a required interface;
- information is used that the attacker should not obtain in the game;
- computational indistinguishability is treated as exact equality;
- failure events and their probabilities are ignored;
- necessary freshness constraints are omitted;
- the conclusion depends on undeclared additional assumptions.
Therefore, a benchmark score can only describe performance on a specific test set and scoring rule. It cannot be directly equated with real system security, and it cannot replace a complete proof review.
4.3 A More Reasonable Role Is to Help Identify Problems
Models are suitable for assisting with the following work:
- organizing informal descriptions into protocol steps;
- extracting party states and message flows;
- listing missing conditions in security definitions;
- proposing potential attack paths;
- generating lemmas to be verified;
- helping explain why a check failed.
A more reliable process is:
Protocol description → explicit security goals → formal model → attempted attacks and proofs → review of key derivations → review of implementation deviations.
Formal proofs also have boundaries. They prove properties under a specified model and assumptions, and may not cover side channels, random-number implementation flaws, error-handling leakage, and other practical issues. Mathematical conclusions still need to be combined with implementation audits.
5. How Fully Homomorphic Encryption Supports Encrypted Inference
5.1 What Problem Encrypted Inference Solves
Fully homomorphic encryption (FHE) allows a compute party to perform specific operations on ciphertexts without decrypting the input, and the party holding decryption capability ultimately recovers the result.
A typical flow is:
Data owner encrypts input → compute party performs ciphertext computation → returns ciphertext result → data owner decrypts.
Its main goal is to reduce the chance that plaintext input is exposed to the compute party during computation. However, it does not automatically solve all privacy and security problems.
For example:
- query frequency and message length may still reveal information;
- the output itself may leak input or model information;
- correctness of ciphertext computation is not necessarily guaranteed;
- whether model parameters are protected must be defined separately.
Input confidentiality, computation integrity, and model confidentiality should be designed separately rather than grouped vaguely under “encrypted security.”
5.2 Encrypted Operations Are Not Equivalent to Ordinary Floating-Point Computation
Homomorphic schemes for approximate numerical computation usually represent real or complex numbers through encoding and scale management. Ciphertext multiplication increases noise and consumes computation levels, and may require relinearization and rescaling afterward.
When available levels are insufficient, bootstrapping can refresh the computational capacity of a ciphertext, but this usually introduces significant overhead. Therefore, system design must manage:
- operation depth;
- numerical precision;
- noise budget;
- ciphertext size;
- number of rotations;
- bootstrapping location and frequency.
Parameter choices must satisfy the target security strength while accommodating computational requirements. Security margins must not be arbitrarily reduced merely for speed.
5.3 Nonlinear Operators Are Key Adaptation Points
Comparisons, branches, normalization, and some activation functions in ordinary models cannot always be converted efficiently and directly into homomorphic operations.
Common approaches include polynomial approximation or adjusting the network structure, but trade-offs are required:
- whether the approximation interval covers actual inputs;
- whether the polynomial degree makes depth too high;
- whether error outside the interval becomes uncontrolled;
- whether errors accumulate across multiple layers;
- whether retraining is needed to adapt to operator changes.
Therefore, “an operator can be approximated” does not mean “the complete model remains usable.” Precision and stability must be evaluated on end-to-end tasks.
5.4 Ciphertext Packing Determines Practical Computational Efficiency
A ciphertext can often carry multiple numerical slots and perform parallel computation through packing. However, data layout affects matrix computation, slot rotation, and result aggregation.
When designing the layout, consider:
- parallelism within a single sample or batch parallelism across multiple samples;
- whether intermediate results need to be rearranged;
- the number of rotation operations;
- the size of auxiliary keys;
- transmission pressure between the client and the compute party;
- how the final result is decoded.
Efficient data layouts in ordinary inference are not necessarily suitable for encrypted computation. Encrypted systems should treat layout, operators, and parameter selection as a joint optimization problem.
6. Layered Design from Cryptographic Foundations to Application Deployment
An encrypted inference system can be abstracted into three layers.
The cryptographic computation foundation layer handles encoding, encryption, decryption, ciphertext operations, and key management. Evaluation focuses on security parameters, correctness, numerical error, and computational overhead.
The compilation and mapping layer converts the model computation graph into executable ciphertext operations, including operator replacement, data layout, depth estimation, and operation scheduling. Its value is to reduce manual conversion errors and expose unsupported computation paths.
The application integration layer handles input/output, request scheduling, key delivery boundaries, exception handling, and deployment management. It directly determines whether a scheme can be reliably incorporated into business systems.
The maturity of these three layers must be validated separately. Support for ciphertext multiplication at the lower layer does not mean efficient execution of a complete model; the ability to compile a computation graph does not mean stable production operation.
7. Recommended Engineering Validation Path
Step 1: Establish a plaintext baseline. Fix the task, data distribution, and quality metrics, and record the original model’s accuracy, latency, and resource consumption.
Step 2: Establish an operator-adapted plaintext baseline. Test the replaced model without encryption to distinguish operator approximation error from encrypted computation error.
Step 3: Validate encrypted execution of key operators. Measure matrix operations, slot rotation, multiplication, rescaling, and necessary bootstrapping separately, and confirm whether numerical error is controllable.
Step 4: Conduct small-scale end-to-end testing. Record the time of encryption, transmission, ciphertext computation, result return, and decryption rather than only the compute party’s execution time.
Step 5: Check security and operational boundaries. Clarify who generates keys, who holds decryption capability, what is logged, and how sensitive information leakage is avoided in failure cases.
Step 6: Conduct sustained load testing. Validate concurrent requests, memory peaks, task timeouts, and failure recovery to avoid mistaking a single successful run for an available service.
8. Conclusion: Replace Single Numbers with an Evidence Chain
Inference performance, protocol security, and encrypted computation cannot be judged completely by a single number.
Performance must be explained together with model structure, memory access, concurrency conditions, and task quality. Security depends on explicit threat models, inspectable derivations, and implementation review. Encrypted inference must simultaneously satisfy cryptographic security, numerical precision, computational cost, and operational requirements.
For developers, the most reliable path is to first define goals and boundaries, then establish baselines, identify bottlenecks through layered experiments, and finally support deployment decisions with a complete evidence chain.
