Machine Learning Model Optimization: How It Works and What It Measures

Machine learning and optimization for deployment: how pruning, quantisation and distillation trade accuracy, latency, memory and cost per request.

Machine Learning Model Optimization: How It Works and What It Measures
Written by TechnoLynx Published on 11 Jul 2026

Model optimisation for deployment changes a trained model through pruning, quantisation or a more efficient topology, to cut inference latency and cost. Success is judged on four measures at once. The first is accuracy against the unoptimised reference model, using a metric defined for that deployment. The second is latency at a stated percentile, and for language models that means time to first token, inter-token latency and end-to-end latency, each specified separately. The third is memory, which covers parameters, the KV cache and runtime activations. The fourth is cost per query.

Machine Learning and Optimization: Training a Model Versus Deploying One

Training optimisation is about how a model learns: the optimiser that updates the weights, the learning rate schedule, the hyperparameters. If that is your question, our explainer on choosing a deep learning optimizer such as SGD or Adam covers it, and hyperparameter sweeps and who should run them covers the search side.

Deployment optimisation starts from the original, already trained model. The TensorFlow Model Optimization guide lists the usual levers: reducing parameter count with pruning, reducing numerical precision with quantisation, and replacing the topology with a more efficient one through methods such as distillation. The same guide gives the reason the work exists: latency, memory use and often power consumption all matter once a model is deployed. Menghani’s 2021 efficiency survey puts the same point another way: as models have grown in parameters, latency and resources, these footprint metrics have to be tracked alongside quality.

The two jobs overlap more than the labels suggest. Quantisation-aware training (QAT) retrains the model, so a quantisation project can still need GPU-hours. The real dividing line is the goal. Training optimisation is trying to get a better model. Deployment optimisation is trying to keep the model you have while changing what it costs to run.

Accuracy, Latency, Memory or Cost per Request: Which One Does Optimisation Measure?

It measures all four, because they are coupled and trade against each other. A result that reports only one of them is incomplete. A 2026 framework paper on constraint-driven optimisation (arXiv 2607.13735) says the accuracy metric has to be defined per deployment (exact match, task success rate, factuality, calibration error or human preference win rate) and measured against the unoptimised reference. NVIDIA’s TensorRT documentation defines latency as the time from an input being presented until its output is available, and throughput as inferences completed per unit time. Memory budgets have to hold parameter storage, the KV cache and runtime activations. On enterprise GPU nodes the bottleneck moves away from parameters and towards the KV cache for many concurrent sessions. Kurtic and colleagues (2024) measured 4-bit weight-only quantisation cutting cost per query by 2 to 3 times on 8B and 70B Llama models, compared with BF16.

Measured Latency, Not FLOPs or Parameter Counts

Parameter count and FLOPs are the proxies people reach for, and they do not reliably predict wall-clock inference time. The Prune-Quantize-Distill study gives a clean example. Pruning half the weights shrank the checkpoint from 42.65 MB to 26.97 MB, yet CPU latency rose slightly, from 2.45 ms to 2.55 ms. Those authors conclude that compression choices should be evaluated in the joint accuracy-size-latency space using measured runtime.

Measurement conditions also change the result. NVIDIA warns that two runs of the same TensorRT engine on the same GPU can disagree by tens of percent if clocks float in one run and lock in the other, or if thermal throttling starts partway through. Input values can change power draw and therefore timing, so NVIDIA recommends inputs that match the real value distribution. A larger batch size can improve throughput while also raising latency, so both have to be measured at each candidate batch size. Which metrics to keep watching after launch is covered in our guide to machine learning model performance metrics to track in production.

How Can You Improve a Machine Learning Model After It Has Been Trained?

You improve it with pruning, quantisation and knowledge distillation, alone or combined. The three are not interchangeable, because each one does a different job.

Quantisation: The Most Reliable Speed Lever

Quantisation stores weights and activations at lower precision, for example 8-bit integers instead of 32-bit floats. Some hardware needs lower precision before it can use its fastest paths. Post-training quantisation (PTQ) calibrates a pre-trained model on a small dataset to set clipping ranges and scaling factors. Its overhead is low and it works when data is scarce or unlabelled, but it usually loses more accuracy than QAT, especially at low bit widths. QAT recovers that accuracy by retraining, which can take several hundred epochs at low precision.

For large language models, recent evidence shows smaller accuracy losses than prior work reported. In over 500,000 evaluations across the Llama-3.1 family, Kurtic and colleagues found FP8 effectively lossless and well-tuned INT8 losing 1 to 3%. They also found 4-bit weight-only quantisation competitive with 8-bit. Which format wins depends on the deployment pattern. Weight-only quantisation mainly speeds up the memory-bound decode stage, while quantising weights and activations together helps the compute-bound prefill stage. The same study recommends W4A16 for synchronous deployments and W8A8 for asynchronous continuous batching. The speed-up you actually get also depends on the hardware, because on-chip memory, bandwidth and cache hierarchy all affect it.

Pruning: Smaller, but Not Always Faster

Pruning removes parameters from a network. Whether that makes inference faster depends on the sparsity structure and the hardware support. Unstructured pruning tends to keep accuracy better but may not reduce CPU latency, because of irregular memory access. Structured pruning gives direct speed-ups but often hurts accuracy on compact backbones. In the 2024 PQV-Mobile study on DeiT vision transformers, pruning 9.375% of the model and quantising to int8 cut latency 7.18 times for a 2.24% accuracy loss. Pushing pruning to 25% made the int8 model 27.9% faster again, but accuracy loss rose to 3.41%.

Treat published pruning gains with some caution. Blalock and colleagues (2020) aggregated results from 81 papers and concluded that the field lacks standardised benchmarks and metrics, to the point where techniques are hard to compare.

Distillation: The Accuracy Recovery Step

Knowledge distillation trains a constrained student to imitate a higher-capacity teacher, and it is often used to recover accuracy after other compression steps. Used on its own for aggressive compression, distillation tends to lose more accuracy than quantisation or pruning, which can hold performance at 4 times compression or more. Combined with them, it has shown strong results. The Prune-Quantize-Distill study shows the division of labour clearly. INT8 QAT alone gave a 2.48 times speed-up but dropped validation accuracy from 73.98% to 69.63%. Adding distillation as the last stage brought accuracy back to 76.91% at essentially the same latency (1.00 ms against 0.99 ms). Order matters too. With the components and budgets held fixed, prune, then QAT, then distillation gave the best accuracy across backbones.

Choosing Techniques by Constraint, in a Sensible Order

The constraint-driven framework (2026) describes any deployment along five interacting dimensions: data availability, latency budget, memory budget, accuracy tolerance and retraining budget. Each dimension rules certain techniques in or out:

Constraint Tight end Looser end
Data availability No task data: training-free methods such as PTQ only Hundreds of thousands of examples: full retraining and large-scale distillation
Latency budget Real-time, under 200 ms: speculative decoding, early exiting, distillation to a smaller model Batch or offline: throughput first, where continuous batching works well
Memory budget Edge devices: PTQ (for example AWQ) first, then structured or N:M sparsity with accelerated kernels Enterprise GPU nodes: the bottleneck moves to KV cache management
Accuracy tolerance Mission-critical, under 0.5% loss: well-calibrated 8-bit quantisation Cost-sensitive, over 2% loss acceptable in exchange for throughput
Retraining budget Zero: PTQ, training-free sparsification, inference engine tuning Hundreds of GPU-hours: QAT, architecture search, structured pruning

The paper calls its accuracy thresholds illustrative and not comparable across metrics, so treat the accuracy row as a map of options, not a set of cut-offs.

The same framework suggests working through the constraints in four phases. Phase one is memory, which decides whether the model loads at all. Phase two is latency, tuning the serving engine once the model fits. Phase three is data and retraining, through parameter-efficient fine-tuning or distillation. Phase four is accuracy and cost, through cascade routing or outlier protection. The authors present this order as a heuristic, not a rule, and expect teams to go back to earlier phases as later constraints come into play.

Do not add up gains from separate papers. The framework’s authors state that combined effects are not guaranteed to multiply. Quantisation can lower speculative-draft acceptance rates, and continuous batching can raise tail latency for individual requests. Their advice is to benchmark combinations on representative production traffic.

How Do You Know an Optimised Model Has Not Quietly Got Worse?

Matching top-line accuracy does not prove behaviour is unchanged. One study found that compressed language models with accuracy close to the baseline still show “flips”: individual answers that change from correct to incorrect and the other way round. As a result, what users see can differ substantially from the baseline model. A separate study of pruned image models found that models with comparable headline metrics diverged on a narrow subset of examples, and that compression hit the underrepresented long tail hardest.

Calibration is another source of quiet damage. NVIDIA notes that a quantised engine built with random calibration data is only a performance experiment, and that deployment needs representative calibration data followed by accuracy revalidation. Kurtic and colleagues found that random-token calibration degraded accuracy for their 4-bit format, so they calibrated on a curated dataset instead.

Offline checks also have a limit. A golden dataset reflects the queries the team thought mattered, while production traffic has long tails of unusual phrasing, mixed languages and adversarial inputs. Shadow traffic closes that gap with real production data. The candidate model receives a copy of every real request, its outputs are compared with production, and users only ever see the current version. A practical deployment sequence runs offline evaluation, then shadow testing, then A/B testing, then a staged rollout. Shadowing doubles inference spend while it runs, so it is best kept to bounded windows that collect a statistically valid sample.

Post-Optimisation Quality Checklist

  • Accuracy measured on the deployment’s own task metric against the unoptimised reference.
  • Per-example comparison with the baseline, counting answers that flipped in either direction.
  • Per-class or per-slice results with the rare and atypical cases broken out, since that is where compression damage concentrates.
  • Calibration data drawn from the real input distribution, with accuracy revalidated after quantisation.
  • Shadow traffic with tiered checks: deterministic format and safety checks on all pairs, embedding similarity on 10 to 20%, LLM-as-judge on 2 to 5%, and human review of under 1%.

For checks after launch, our model monitoring framework covers what standard metrics miss after deployment.

When Does It Make Sense to Optimise the Model You Already Have Instead of Switching?

Optimise the model you have first. Cost and latency pressure in production rarely calls for a new model. The main levers (batching, caching, routing, quantisation, kernel work, serving configuration and runtime choice) sit below the model layer and can be tuned independently. Replacing the model is the most expensive lever, and it can leave the workload’s economics unchanged.

vLLM’s PagedAttention reduces KV cache fragmentation and served up to 4 times more concurrent requests in its reported experiments. Routing goes a step further. A 2026 study of compound AI systems found configurations within 2.5 to 4 percentage points of monolithic-model accuracy while cutting latency by up to 60% and cost by up to 71%. The reason is that workloads are not uniform. On GSM8K, a small local model such as Llama3.2-3B already solves 78% of problems, so sending every request to the largest model over-provisions the easy ones. FrugalGPT’s cascade router reported up to 98% cost reduction on its workload, and its authors warn that those ratios are workload-specific and must be measured on your own traffic.

Switching is still sometimes the right answer. Across its case studies, the compound AI study also found that model selection dominated system-level performance. Model choice matters, then. It just should not be the first thing you change. For language-model systems, TechnoLynx can audit the serving path for cost and latency gains before any model replacement is considered, as part of its generative and agentic AI engineering work.

Reading Published Speed-Ups Against Your Own Workload

The speed-up and accuracy figures on this page were measured on other teams’ models, hardware, batch sizes and traffic. The 7.18 times speed-up came from DeiT optimised for mobile. In a separate PQV-Mobile test on a DeiT3 model, FBGEMM and x86 were the fastest backends on an AVX-enabled x86 machine. Use these numbers to decide which technique is worth trying. Only a measurement on your own serving path can tell you what you will actually get, at the latency percentile your users feel and with the flips and long-tail errors counted.