Inference is the process of running a trained or adapted AI model on new input data to produce an output such as a prediction, classification, recommendation, embedding, generated response, or decision. In AI engineering, inference is the computational stage where a model is used after its parameters have been trained or adapted.
What Is Inference?
Training teaches a model how to perform a task by adjusting its parameters using data. Inference uses what the model has learned to process new inputs and produce results.
For example, a fraud-detection model might be trained using millions of historical transactions. When a new transaction arrives, the trained model can evaluate it and return a fraud probability. That evaluation is inference.
Inference is not limited to large language models. It occurs whenever a trained AI model is applied to new data. An image classifier performs inference when it receives a new photograph. A recommendation model performs inference when it scores products for a customer. A demand-forecasting model performs inference when it predicts next month's sales.
A useful distinction is:
Training → learns model parameters
Fine-tuning → adapts an existing model
Inference → uses the resulting model
Serving → makes inference available to applications
Inference can happen locally on a device, on a company's own infrastructure, or through a cloud service. It can process one request at a time, handle many requests concurrently, or process large batches of data.
For modern language models, inference can also involve generating output token by token. This makes inference an important engineering concern because model size, context length, output length, hardware, memory, concurrency, latency, and throughput all affect the cost and responsiveness of an application.
How It Works
The exact inference process depends on the model and task, but a typical system follows these stages:
- Receive an input. The application provides data such as an image, transaction, sentence, sensor reading, or user prompt.
- Validate and preprocess the input. The system checks the data and converts it into the representation expected by the model. For a language model, text is converted into tokens.
- Load or access the model. The model's learned parameters must be available to the inference hardware or service.
- Run the model. The model performs its forward computation using the input and its learned parameters.
- Produce a raw output. Depending on the model, this might be a probability distribution, numerical prediction, class score, embedding, ranking score, or generated token.
- Post-process the output. The raw result may be converted into a label, recommendation, formatted response, probability, or other application-level result.
- Return or act on the result. The application can display the output, store it, pass it to another system, or use it to trigger an action.
- Measure performance. Production systems can monitor accuracy, latency, throughput, resource consumption, failures, and other task-specific metrics.
For a conventional neural-network model, inference generally consists of a forward pass through the network. Unlike ordinary training, inference does not normally calculate gradients or update the model's parameters.
LLM Inference
Large language model inference has an additional characteristic because generated text is produced as a sequence of tokens.
A typical request can be understood through two major phases:
Prefill → Decode
During prefill, the model processes the input prompt and builds the internal representations needed for generation.
During decode, the model generates output tokens sequentially. The newly generated token becomes part of the sequence used to generate the next token.
This creates two important performance measures:
Time to First Token (TTFT) measures how long the system takes to begin producing a response.
Time Per Output Token (TPOT) measures the time required to generate subsequent tokens.
For an interactive language application, both can affect how responsive the system feels.
Batch and Real-Time Inference
Inference can be performed in different operating modes.
Batch inference processes many inputs together, often on a schedule. A retailer might generate embeddings for 2 million catalog products overnight, or a bank might score yesterday's transactions in a scheduled job.
Real-time or online inference processes requests as they arrive. A fraud model might evaluate a payment during checkout, or a language model might respond to a user within a few seconds.
Batch workloads generally provide more flexibility to optimize for throughput. Real-time workloads place greater emphasis on predictable latency.
Latency and Throughput
Two of the most important engineering properties of an inference system are latency and throughput.
Latency is the time required to process an inference request or reach a specified response point.
Throughput is the amount of inference work the system can complete over a period, such as requests per second or tokens per second.
A system optimized for one user may prioritize low latency. A system processing millions of records may prioritize high throughput.
Engineers often have to balance these objectives. Increasing batching can improve hardware utilization and throughput, but excessive batching can increase the time an individual request waits before processing.
Memory and the KV Cache
Inference requires memory for model parameters, intermediate computations, input and output data, runtime structures, and other state.
For autoregressive language models, a KV cache stores key and value representations from previously processed tokens. Reusing these representations avoids repeating some computations for every newly generated token.
The KV cache can become a significant memory requirement when context lengths or the number of simultaneous requests increase. This creates a practical relationship between model size, context length, concurrency, available memory, and inference capacity.
Hardware
Inference can run on CPUs, GPUs, TPUs, specialized AI accelerators, and edge devices.
The appropriate hardware depends on the model and workload. A small classification model may run efficiently on a CPU, while a large language model serving many simultaneous users may require multiple accelerators.
Engineers consider factors such as compute capacity, memory capacity, memory bandwidth, latency, throughput, power consumption, and infrastructure cost when selecting inference hardware.
Serving
Inference and serving are related but different.
Inference is the actual computation performed by the model.
Serving is the infrastructure that makes the model available to applications and manages inference requests.
A model-serving system may handle API requests, model loading, batching, concurrency, routing, scaling, authentication, version management, monitoring, and hardware allocation.
A model can therefore exist without being actively served. Conversely, a production inference service normally combines the model with software and infrastructure required to accept and process requests reliably.
Inference Optimization
AI engineers can optimize inference in several ways:
- Quantization reduces numerical precision to lower memory requirements and potentially improve efficiency.
- Batching combines multiple compatible requests to improve hardware utilization.
- Caching avoids repeating computational work where results or intermediate state can be reused.
- Model selection uses a model appropriate to the required quality, latency, and cost rather than automatically choosing the largest model.
- Hardware acceleration uses processors optimized for neural-network computation.
- Parallelism distributes computation across multiple processing units when appropriate.
- Context reduction can reduce unnecessary input processing for language models.
- Model compilation and optimized kernels can reduce the computational overhead of model execution.
- Request scheduling can organize concurrent workloads to improve resource utilization and response times.
Large models may also require distributed inference, where computation or model components are spread across multiple devices.
Formula & Calculation Method
There is no single universal formula for inference because different models and workloads perform different computations. Several operational calculations are useful when engineering an inference system.
Inference Latency
A simplified end-to-end latency model can be expressed as:
Total Latency = Input Processing + Model Computation + Output Processing + Network/Queueing Overhead
For an interactive LLM, a simplified decomposition can include:
Time to Complete ≈ TTFT + (Number of Output Tokens × TPOT)
This is an approximation because actual systems can have additional scheduling, networking, batching, and processing effects.
Throughput
A basic request-throughput calculation is:
Throughput = Completed Requests ÷ Time
For token-based workloads:
Token Throughput = Processed Tokens ÷ Time
Batch Processing Time
For a workload containing N inputs processed at an average rate of R inputs per second:
Processing Time ≈ N ÷ R
These equations describe operational performance rather than the mathematical computation performed inside the AI model itself.
Worked Example
Consider a customer-service application using a language model.
A user submits a prompt containing 800 input tokens. The model generates 200 output tokens.
The inference service records:
- Time to First Token = 1.2 seconds
- Average Time Per Output Token = 40 milliseconds
- Output tokens = 200
Step 1
Convert the token generation time into seconds:
200 × 0.040 = 8 seconds
Step 2
Add the initial time to first token:
Total Generation Time ≈ 1.2 + 8.0 = 9.2 seconds
The approximate time from request initiation to the completed generated response is therefore 9.2 seconds, assuming other overhead is negligible.
Step 3
Calculate output-token throughput:
Output Token Throughput = 200 ÷ 8.0
Output Token Throughput = 25 tokens per second
The application therefore generates output at approximately 25 tokens per second after the initial 1.2-second wait.
Step 4
Consider concurrency
If the same system must handle 100 simultaneous requests, the single-request result cannot simply be multiplied by 100 to predict production capacity. Memory consumption, accelerator capacity, batching, scheduling, queueing, and contention can materially change performance.
This is why inference engineering evaluates latency and throughput under realistic workload conditions rather than measuring one isolated request.
How to Interpret Results
Inference is best understood as the operational use of a model, not as a separate kind of intelligence. A model can be highly capable while still being expensive or slow to run, and a fast inference system can still produce poor results if the underlying model is unsuitable for the task.
Several practical interpretations matter:
- Low latency does not automatically mean high throughput. A system can respond quickly to individual requests while processing relatively little total work.
- High throughput does not automatically mean good user experience. A heavily batched system may process many requests efficiently while individual users experience additional waiting.
- Larger models are not automatically better for every inference workload. A smaller model may provide sufficient quality at substantially lower latency and cost.
- Inference cost depends on workload. Model size, input size, output size, hardware, concurrency, and utilization can all affect cost.
- Longer context can increase resource requirements. Large language models may require additional computation and memory as the amount of context grows.
- Benchmark results are workload-dependent. Performance measured with one batch size, sequence length, model, and hardware configuration may not predict performance under another workload.
- Model quality and inference efficiency are separate dimensions. A model should be evaluated both for how well it performs the intended task and how practical it is to operate.
- Inference is not equivalent to human reasoning. The technical term describes model execution and output generation; it does not establish consciousness or human-like thought.
- Production inference includes more than the model. Networking, preprocessing, queues, serving software, hardware, monitoring, and post-processing can all contribute to end-to-end performance.
- Cold starts can change observed latency. A service that must load a model before processing a request can behave differently from a continuously warm service.
- Batch and online inference solve different operational problems. A nightly forecasting pipeline can tolerate conditions that would be unacceptable in an interactive application.
The most useful engineering question is therefore not simply "How fast is the model?" It is whether the complete inference system provides the required quality, latency, throughput, reliability, and cost for its intended workload.
Real-World Applications
- LLM applications: Inference generates responses, summaries, classifications, code, and other outputs from language models.
- Fraud detection: A trained model can score transactions as they arrive and flag suspicious activity.
- E-commerce recommendations: Recommendation models can score products and rank candidates for individual customers.
- Demand forecasting: A trained forecasting model can generate demand estimates for thousands of products in scheduled batch jobs.
- Computer vision: Image models can classify products, detect defects, identify objects, or analyze visual scenes.
- Speech recognition: Audio models can convert spoken language into text during calls, meetings, or voice interactions.
- Embeddings: Embedding models can transform text, images, or other data into numerical vectors for search, retrieval, clustering, or recommendation systems.
- Manufacturing: Edge inference can detect production defects directly on cameras or industrial equipment.
- Cybersecurity: Models can evaluate network or user behavior and identify patterns associated with potential threats.
- Healthcare: AI models can assist with image analysis, prediction, classification, and other tasks where the system has been appropriately validated for the intended use.
- Mobile applications: Smaller models can perform inference directly on phones or other devices when local processing is practical.
- Autonomous and robotic systems: Inference can transform sensor information into predictions, classifications, or decisions used by physical systems.
Common Mistakes & Misconceptions
- Inference means training the model. Training changes model parameters; inference uses the resulting model to produce outputs.
- Inference and serving are the same thing. Inference is the model computation, while serving provides the infrastructure through which applications access that computation.
- Inference only applies to LLMs. Any trained AI model can perform inference, including vision, forecasting, recommendation, fraud-detection, and speech models.
- Every inference request takes the same amount of time. Input size, output size, model architecture, hardware, batching, concurrency, and system load can all change latency.
- More GPUs always make inference proportionally faster. Scaling efficiency depends on the model, workload, communication overhead, parallelization strategy, and hardware.
- The largest model is automatically the best production choice. A smaller model can provide adequate quality at lower cost and latency for a particular task.
- High tokens-per-second means the whole request is fast. Initial processing, queueing, network time, and time to first token can make end-to-end latency much higher.
- Batching always improves the user experience. Batching can improve throughput and hardware utilization while increasing waiting time for individual requests.
- Inference automatically updates the model. Ordinary inference does not normally modify the model's learned parameters.
- A benchmark from one model or GPU applies to all inference systems. Inference performance depends heavily on the model, hardware, workload, sequence length, batch size, and implementation.
- Inference is simply the model's "thinking." Inference is a technical term for running a trained model to produce an output and does not establish human-like reasoning or consciousness.
- Inference happens only in the cloud. Models can perform inference in cloud infrastructure, on-premises servers, personal computers, mobile devices, and edge hardware.
Frequently Asked Questions
What is inference in AI?
Inference is the process of running a trained or adapted AI model on new input data to produce an output such as a prediction, classification, recommendation, embedding, or generated response.
What is the difference between training and inference?
Training uses data to learn or update model parameters. Inference uses the resulting model to process new inputs and generate outputs without normally updating those parameters.
What is the difference between inference and serving?
Inference is the model computation itself. Serving is the infrastructure and software used to make that computation available to applications, including request handling, scaling, batching, routing, and monitoring.
What is LLM inference?
LLM inference is the process of using a trained language model to process an input context and generate output tokens. Generation commonly involves an initial prefill phase followed by sequential token decoding.
What is time to first token?
Time to First Token (TTFT) is the time between initiating a language-model request and receiving the first generated output token. It is an important latency measure for interactive AI applications.
What is inference latency?
Inference latency is the time required for an inference request to reach a specified result. Depending on the application, it can include input processing, model computation, output processing, network delay, and queueing.
What is inference throughput?
Inference throughput measures how much inference work a system completes over a period. It can be expressed as requests per second, images per second, or tokens per second depending on the workload.
What is batch inference?
Batch inference processes multiple inputs together, often on a schedule. It is useful for workloads such as generating predictions for a large customer database or producing embeddings for an entire product catalog.
What is real-time inference?
Real-time or online inference processes requests as they arrive and returns results quickly enough for the application's requirements. Fraud checks during checkout and interactive AI assistants are common examples.
Why is inference expensive?
Inference can require substantial compute and memory, particularly for large models and high request volumes. Cost depends on factors such as model size, hardware, input and output volume, concurrency, and infrastructure utilization.
What is a KV cache?
A KV cache stores key and value representations from previously processed tokens during autoregressive language-model generation. Reusing this information can reduce repeated computation, although the cache consumes additional memory.
Can AI inference happen on a device?
Yes. Inference can run on CPUs, GPUs, mobile devices, embedded systems, and other edge hardware as well as cloud or on-premises infrastructure. The appropriate location depends on the model, hardware, latency, privacy, cost, and reliability requirements. ---