1.2 Training vs inference
What training and inference each do, and why they need different resources.
Key points
Training is how a model learns. Data passes through the network, the error is propagated back through its layers, and the model adjusts its weights and tries again. A weight is one of the numbers inside the model that training tunes. Inference is when a trained model makes predictions on new data. NVIDIA notes inference cannot happen without training.
What NVIDIA says (3)
“Instead, the error is propagated back through the network’s layers, and the model must adjust its weights and try again.”
“Inference is the process where a trained AI model generates new outputs by reasoning and making predictions on new data — classifying inputs and applying learned knowledge in real time.”
“Inference can’t happen without training.”
Precision is how many bits a number uses. FP16 (half precision) uses 16 bits; FP32 (single precision) uses 32. Mixed precision does most operations in half precision while keeping critical information in single precision. NVIDIA lists three benefits: less memory, less memory bandwidth, and much faster math, especially on GPUs with Tensor Cores.
What NVIDIA says (3)
“First, they require less memory, enabling the training and deployment of larger neural networks.”
“Second, they require less memory bandwidth which speeds up data transfer operations.”
“Third, math operations run much faster in reduced precision, especially on GPUs with Tensor Core support for that precision.”
NVIDIA explains that training repeats a loop: the error is propagated back through the layers, the model adjusts its weights and tries again. Over many iterations it converges on the correct weights. NVIDIA calls training 'a monster when it comes to consuming compute.'
What NVIDIA says (2)
“Over many iterations, it converges on the correct weights, enabling it to reliably suggest accurate, useful code completions or translations.”
“The challenge is, it’s also a monster when it comes to consuming compute.”
Latency is the time from a request to its response. Throughput is how much work is completed per unit of time. NVIDIA says inference applies learned knowledge in real time. Low-latency, high-performance inference makes real-time interaction possible. NVIDIA adds that inference optimization lets enterprises tune throughput and latency to meet their service-level agreements (SLAs).
What NVIDIA says (2)
“This is only possible with low-latency, high-performance inference.”
“That’s why inference optimization techniques are so critical: they allow enterprises to optimize throughput and latency so they can meet their service level agreements across a variety of use cases.”
A large language model (LLM) generates text one token at a time. To avoid recomputing earlier tokens, it stores their attention keys and values in a KV (key-value) cache. NVIDIA says the two main contributors to GPU memory for LLM inference are the model weights and the KV cache. With batching, each request's KV cache is allocated separately, which can use a lot of memory.
What NVIDIA says (2)
“In effect, the two main contributors to the GPU LLM memory requirement are model weights and the KV cache.”
“With batching, the KV cache of each of the requests in the batch must still be allocated separately, and can have a large memory footprint.”
LLM inference has two main GPU phases. NVIDIA explains that in prefill, all input tokens are processed at once through every layer, which is computationally heavy. In decode, the model generates outputs one token at a time, and each new token depends on all the previous ones.
What NVIDIA says (4)
“Prefill Phase: All input tokens are processed at once, flowing through every layer of the neural network.”
“This is computationally heavy since the entire set of input tokens is processed all together.”
“Decode Phase (Token by Token): The model begins generating outputs one token at a time.”
“Each new token depends on the history of all the previous ones.”
Prefill is compute-heavy while decode is sensitive to latency, so mixing them on the same GPUs can make them interfere. NVIDIA describes disaggregated serving: a separate set of GPUs handles prefill, and another handles decode, to speed up prefill.
What NVIDIA says (1)
“To accelerate the prefill phase, enterprises can use a technique called disaggregated serving, in which a separate set of GPUs are used for the prefill phase than the next decode phase.”
Training from scratch is expensive. NVIDIA describes fine-tuning as the bridge between a foundation model trained on broad data and a model specialized for a domain, such as legal documents. Developers reuse the core model and train only a few layers or adapters on domain examples, which allows faster iteration.
What NVIDIA says (2)
“Fine-Tuning Makes Models More Adaptable Fine-tuning is the bridge between a foundation model trained on broad data and a model specialized for a specific domain — like legal documents, medical images or enterprise analytics.”
“Instead of starting from scratch, developers reuse the core model and train just a few layers or adapters on domain-specific examples.”
FP16 has a smaller range than FP32, so very small gradient values can become zero. NVIDIA's guide says mixed precision training needs two steps: port the model to use FP16 where appropriate, and add loss scaling to preserve small gradients. Without loss scaling, training can diverge, while with it the model matches single precision.
What NVIDIA says (3)
“Using mixed precision training requires two steps: Porting the model to use the FP16 data type where appropriate.”
“Adding loss scaling to preserve small gradient values.”
“Mixed precision without loss scaling (grey) diverges after a while, whereas mixed precision with loss scaling (green) matches the single precision model (black).”
Smaller number formats store each value in fewer bytes. NVIDIA's guide says FP16 uses 16 bits compared with 32 for FP32. That reduces the network's memory use, allowing larger networks or larger mini-batches, and FP16 transfers take less time than FP32 or FP64.
What NVIDIA says (3)
“Half-precision floating point format (FP16) uses 16 bits, compared to 32 bits for single precision (FP32).”
“Lowering the required memory enables training of larger models or training with larger mini-batches.”
“Half precision (also known as FP16) data compared to higher precision FP32 vs FP64 reduces memory usage of the neural network, allowing training and deployment of larger networks, and FP16 data transfers take less time than FP32 or FP64 transfers.”
Inference is optimized differently from training. NVIDIA's AI inference glossary says the inference phase is optimized for speed and efficiency, often using speculative decoding, quantization, pruning and layer fusion, while maintaining accuracy.
What NVIDIA says (1)
“This phase is optimized for speed and efficiency, often using techniques like speculative decoding, quantization, pruning, and layer fusion to enhance performance while maintaining accuracy.”
Key terms
- Training: The process of feeding data through a model and adjusting its weights until its outputs are accurate.
- Inference: Using a trained model to make predictions or generate outputs on new data.
- Mixed precision: Training with lower-precision number formats where safe, which saves memory and runs math faster on Tensor Cores.
- Latency: How long one request or one transfer takes from start to finish.
- Throughput: How much total work finishes per second, for example requests or samples per second.
- Batch: The group of samples a model processes in one step; batch size is how many samples are in that group.
- Gradient: The correction signal computed in training that says how much, and in which direction, to adjust each weight.
Try it
Sample question
Which statement best contrasts training and inference?
Show the answer
Answer: Training adjusts a model's weights by passing data through it and propagating errors back. Inference uses the trained model to make predictions on new data, often in real time.
Training is how a model learns. Data passes through the network, the error is propagated back through its layers, and the model adjusts its weights and tries again. A weight is one of the numbers inside the model that training tunes. Inference is when a trained model makes predictions on new data. NVIDIA notes inference cannot happen without training.
What NVIDIA says (3)
“Instead, the error is propagated back through the network’s layers, and the model must adjust its weights and try again.”
“Inference is the process where a trained AI model generates new outputs by reasoning and making predictions on new data — classifying inputs and applying learned knowledge in real time.”
“Inference can’t happen without training.”
Practice 1.2 (11 questions) Full Essential AI Knowledge guide
← 1.1 The NVIDIA software stack · 1.3 AI, machine learning and deep learning →