LLM inference speedup starts with identifying the bottleneck: input processing, generation, memory, queueing, or inter-GPU communication. The engine manages model execution, memory allocation, and request scheduling. The same method can raise overall throughput while also worsening the latency for an individual user, so settings should be chosen against a measurable target.
Prepared by Vladimir Lomtev’s AI Studio on November 14, 2026 for developers, platform engineers, and technical team leads. This is a technical overview of the mechanisms and optimization sequence for text LLMs based on project documentation. No original benchmark comparisons of engines were performed; there is no universal speed ranking or guaranteed acceleration factor here. Check the exact launch parameters against the pinned version of your server.
Contents
- What an inference engine does
- Two phases: prefill and decode
- Which metrics to optimize
- How to choose between engines
- KV cache: don’t recompute the past
- PagedAttention: managing cache placement
- Continuous batching: fill each compute step with work
- Prefix caching: reuse shared input
- FlashAttention and compute kernels
- Quantization: less data, but a different computation path
- Speculative decoding: proposals with verification
- Multiple GPUs: model partitioning or extra replicas
- Separating prefill and decode
- The optimization sequence for a production service
- Common mistakes when speeding up inference
- Frequently asked questions
What an inference engine does
The engine loads weights, executes model operations, maintains generation state, and uses the compute libraries of the selected hardware. The server layer accepts network requests, batches them into scheduler work, and returns the result to the application. In one project, both layers may be delivered together.
It helps to distinguish four objects: the model, the format of its artifacts, the runtime environment, and the user interface. GGUF is a file format, not a standalone server. Open WebUI is an interface, not a replacement for GPU compute. Ollama provides a convenient way to manage models and an API, while llama.cpp, vLLM, SGLang, and TensorRT-LLM solve execution problems with different priorities.
The choice is not just about the number of project stars. First, check support for the model architecture, the hardware, and the required features. Then evaluate answer quality and behavior under production load. An overview of the purpose of the main options is already available in the comparison of vLLM, Ollama, llama.cpp, and SGLang; below, the focus is on acceleration mechanisms.
Two phases: prefill and decode
During prefill, the model processes the input context and prepares the states needed to continue. A long document can take significant time before the first token of the response appears. During decode, the model sequentially selects the next tokens using the already processed context.
The split explains why a service cannot be judged by a single “tokens per second” number. A short question with a long answer and a long document with a short label create different workload profiles. A method that reduces repeated input reads may barely change the speed of producing a long answer. NVIDIA describes the phase architecture and its connection to memory in its guide to optimizing LLM inference.
For diagnosis, add a third component: queue wait time. The user sees the time from request submission, not from the actual start of computation. Fast decode does not help if the request waits too long before execution.
Which metrics to optimize
| Metric | What it shows | When it is especially useful |
|---|---|---|
| TTFT | Time to first token | Chats, long input, overloaded queue |
| TPOT or ITL | Time for subsequent tokens or output intervals | Streaming response readability |
| End-to-end latency | Time to request completion | Field extraction and automated workflows |
| Throughput | The amount of work successfully processed over time | Batch jobs and shared server capacity |
| Goodput | Work completed while meeting the chosen SLOs | Production capacity planning |
| Error rate | Failures, timeouts, and incorrect outputs | Any optimization acceptance test |
In a report, clarify the metric definition and the measurement boundary. For example, client-side TTFT includes network and server latency; the value inside the engine may start later. Add quantiles to the average so slow requests are not hidden. Quantiles of different components cannot simply be added together to get the quantile of total time.
How to choose between engines
| Option | What to examine first | Primary check before use |
|---|---|---|
| llama.cpp | GGUF, CPU/GPU placement, local server | Model support and backend, memory-speed balance |
| Ollama | Fast startup, model loading and retention, API | Actual model placement and behavior under concurrent load |
| vLLM | Scheduler, KV cache memory, multi-user serving | Model support, weight format, SLOs for your workload |
| SGLang | Repeated contexts, caching, and server settings | The effect of the chosen configuration on latency and memory |
| TensorRT-LLM | Optimization for the supported NVIDIA stack | Hardware, model, and deployment-path compatibility |
This is a map of experiments, not a ranking. The engine name does not determine the winner without the version, model, hardware, and request profile. The llama.cpp server documentation describes its own server path; SGLang has a guide to memory and performance tuning.
For a fair comparison, keep the input texts, output constraints, and evaluation rules the same. Check the tokenizer and chat template. If one option uses quantization, another uses higher-precision weights, and a third uses an additional draft model, you are comparing system configurations. That is valid, but it must be stated clearly.
KV-cache: don’t recompute the past
The KV-cache stores the keys and values from the attention mechanism for tokens that have already been processed. It makes it possible to continue generation without fully recomputing the corresponding states from prior context. The tradeoff is memory, which depends on the model architecture and the length of the active sequences.
The size of the weight file does not describe the server’s full VRAM requirements. Dialogs handled at the same time each require their own states. Increasing context length and concurrency can cause an out-of-memory condition even if the model itself does not change. That is why throughput gains from handling more requests must be matched against the KV-cache budget.
Some architectures use compressed or hybrid states, so a simple formula for standard attention does not apply to every model. First read the architecture configuration, then use engine estimates and actual measurements. If needed, start with a separate model memory calculation.
PagedAttention: managing cache placement
PagedAttention organizes KV-cache handling through blocks, allowing a logical sequence to use physically noncontiguous memory. The idea is related to memory management: you do not need to reserve one continuous region for the maximum length of every request. This helps use available resources more efficiently when sequence lengths vary.
Do not describe PagedAttention as weight compression or a universal reduction in model computation. Its role is different from quantization. Better cache placement may allow the server to handle more work, but by itself it does not promise the same speedup for every individual request. The mechanism is explained in the PagedAttention authors’ paper.
When evaluating the effect, look at production-like load: different conversation lengths, requests finishing at different times, repeated and unique inputs. A set of identical short prompts may not reveal the problems that show up in a real chat.
Continuous batching: keep the compute step busy
In standard sequential processing, a new request waits for the previous one to finish. Batching combines the work of multiple requests. Continuous batching lets the scheduler change the active group as sequences complete and new ones arrive, so resources do not sit idle because responses have different lengths.
User concurrency and batch size are related, but not identical. You can accept many network connections and keep them queued. You can raise the execution limit and get higher throughput, but at the same time increase competition for memory and individual request latency.
For overnight archiving, a longer delay may be acceptable in exchange for higher total throughput. For a voice interface, the pause before a response can be critical. That is why scheduler tuning should be based on the target SLO, not on the maximum number of simultaneous requests in the config.
Prefix caching: reuse a shared input
If requests start with the same token sequence, the server can reuse the computed states for the shared prefix. This is useful for a long system instruction, repeated questions about the same document, and some multi-step workflows. The vLLM Automatic Prefix Caching documentation separately describes the use cases and limitations.
The practical takeaway for an application is that stable parts of the request should be placed thoughtfully. If you insert a unique time stamp or identifier before the shared document every time, the matching region may shrink. At the same time, you should not rearrange data just to benefit the cache if that changes the instructions, conversation order, or task meaning.
Distinguish prefix cache from response caching. The first reuses input computation and continues generation; the second returns a stored result. Stored responses separately require freshness rules, access control, and reuse permissions.
FlashAttention and compute kernels
FlashAttention changes how attention computation and memory traffic are organized by breaking the work into blocks. Its goal is to reduce expensive data movement under supported conditions. It is an execution-time attention optimization, not a new trained language model. The mechanism is explained in the original FlashAttention paper.
Seeing the word FlashAttention in a server description does not prove that a specific request uses the intended backend. The choice depends on hardware, precision, architecture, and library version. Startup logs and profiling are more useful than assuming the feature is enabled by default.
Beyond attention, speed is affected by matrix operations, kernel fusion, compilation, and launch overhead. For a small workload, preparation cost may matter more than the gain from optimization. For a continuously running service, it is useful to measure cold start and steady state separately.
Quantization: less data, but a different computation path
Quantization reduces the precision used to represent certain numbers. It can apply to weights, activations, or the KV-cache; these are different objects with different consequences. Smaller weights can let a model fit into less memory, but actual speed depends on support for the corresponding compute kernels.
If the format has to be converted during runtime, a smaller footprint does not necessarily turn into lower latency. Compare “format plus backend” pairs on the same task and track quality separately. Pay especially close attention to numeric extraction, Russian language output, JSON formatting, and tool calls.
There is a separate guide to quantization and GGUF for preparing artifacts. As part of an optimization plan, it is reasonable to first determine whether memory is the limiting factor. If the server already fits in memory and latency is caused by an external tool queue, changing weight precision will not solve the root cause.
Speculative decoding: proposals with verification
Speculative decoding uses a mechanism that proposes several future tokens and has the main model verify them. The proposals can be generated by a separate model or by an architecturally linked method. The benefit depends on proposal cost, the share of accepted tokens, and the load pattern. The term does not mean the server returns an answer from a weaker model without verification.
In the vLLM speculative decoding documentation supported options and limitations are described. The exact feature set changes between releases, so you should not transfer a configuration from a random example without checking the version.
Treat the method as a separate experiment. Record memory, TTFT, generation time, and quality before making changes. Add the proposal mechanism, repeat the same flow, and compare. If the extra model takes memory away from active sequences, a gain in single-response performance may come with a loss in overall capacity.
Multiple GPUs: model sharding or extra replicas
Tensor parallelism distributes parts of the model’s operations across accelerators. Pipeline parallelism splits execution into stages. Replicas make it possible to serve independent requests with separate copies of the model. For MoE, there is also expert parallelism, which relates to expert placement.
A single large model that does not fit on a device and many short independent requests call for different solutions. In the first case, sharding helps place the computation. In the second, several separate copies may sometimes be a better fit for the task, but that should be tested. The number of GPUs by itself does not determine the result.
Take the interconnect into account: communication between devices and nodes is part of the step cost. An additional GPU does not automatically translate into the same amount of extra speed. The approaches and constraints are described in the vLLM parallelism and scaling guide.
Prefill and decode separation
With separate serving, the input-processing and generation phases are placed on different resources. This makes it possible to manage their queues and power profiles separately. At the same time, it creates a need to transfer state, coordinate scheduling, and observe more components.
This approach is worth considering after measurement, when a mixed workload is truly getting in the way of meeting the SLO. For a small service, the complexity may outweigh the practical benefit. In the TensorRT-LLM Disaggregated Serving documentation the architecture for transferring KV-cache between phases is shown.
Do not start optimizing with a distributed system if input length, single-server settings, and the actual queue have not yet been checked. Phase separation does not fix a poor model, unnecessary documents in the prompt, or endless application-level retries.
Optimization order for a live service
- Record the model artifacts, engine, hardware, and current settings.
- Choose a metric and a threshold: for example, time to first token under a consistent load.
- Break total time into data preparation, queueing, prefill, decode, and external operations.
- Check context length, unnecessary output, and application retry requests.
- Change one significant factor per experiment.
- Repeat the test in both warm and cold states with the same caching rules.
- Check answer correctness, failures, and memory alongside speed.
- Save the winning configuration and the rollback conditions.
To document an experiment, use this template: “hypothesis → change → control flow → metrics → quality → decision.” Fill in the blank fields with actual data; there should be no prewritten acceleration percentage in the protocol. For the server side, vLLM Benchmark CLI is a good fit; for the user journey, you need an additional application-level measurement.
Common mistakes when speeding up inference
Comparing different models while presenting it as a comparison of engines hides the real cause of the result. A repeat test with an already warmed cache can look like a post-tuning speedup. Measuring only successful requests hides losses due to timeouts. The same output limit does not guarantee the same actual response length.
Another mistake is treating streamed output as a computation speedup. Streaming helps show the already completed portion earlier, but it does not necessarily reduce total generation time. This is a useful interface change that should be measured separately from model performance.
Finally, do not transfer a vendor benchmark’s top-line result to your own system. Keep the model, sequence lengths, batch size, precision, hardware, and cache mode the same. Without these conditions, the number does not help you choose an architecture.
FAQ
Which inference engine is the fastest?
The answer depends on the model, hardware, and workload. Compare compatible configurations on the same request stream, recording quality, TTFT, total latency, and throughput.
Can you speed up an LLM without changing the GPU?
Sometimes yes: reduce unnecessary context, limit the output, fix the queue, use repeated prefixes, and choose a supported weight format. First, you need to identify the cause of the latency.
Does quantization always reduce quality?
It changes the numeric representation and can affect the result; the degree of impact depends on the method, model, and task. Acceptance testing on real examples matters more than a general statement about bit count.
Does more concurrent traffic mean faster performance?
Not necessarily. Overall throughput may increase, while the latency of a single request may go up. Acceptance is based on the chosen SLOs and includes failures.
Should you turn on all optimizations at once?
No: then it is hard to identify the source of the change and the compatibility of the features. A stable baseline configuration is needed first, followed by sequential experiments.
How Vladimir Lomtev’s AI studio helps with a local LLM
Vladimir Lomtev’s AI studio can connect model deployment with process auditing, control data preparation, and integration into a production system. For a speed-up project, that means defining a user-facing criterion, checking the appropriate execution option, and organizing testing before launch. These steps do not imply a prepromised acceleration factor.
The first step is to describe one process, the current latency, the data composition, and the acceptance criterion for the response. Discuss the project.
Where to start with acceleration
Start with a time-and-memory map of a single real request. For a long repeated input, examine prefill and cache; for a large queue, examine admission and batching; for memory pressure, examine context, states, and supported quantization methods; for distributed execution, examine communication between devices.
Choose the engine based on compatibility and the results of your own test. A successful optimization preserves the required quality and improves the selected metric under the agreed-upon load. It should leave you with a reproducible configuration and a clear rollback path.


