Large Language ModelsInference & Performance Optimization

How do you design cost-efficient, statistically sound multi-objective hyperparameter optimization for LLM inference under limited GPU benchmarking budgets?

Question 285 of 309 · Updated

On this page

1. Why inference tuning is an optimization problem#

An LLM inference configuration combines serving decisions: GPU type and count, tensor/pipeline parallelism, quantization, KV-cache dtype, maximum batched tokens, concurrent sequences, chunked prefill, speculative decoding, scheduler policy, and runtime/kernel versions. Each candidate consumes scarce benchmarking resources: model loading, warmup, realistic traffic replay, tail-latency measurement, quality checks, and repeated runs.

The best configuration is rarely the one with the highest raw throughput. Production teams balance:

  • SLO-compliant goodput.
  • p95/p99 time to first token (TTFT).
  • Inter-token latency (ITL) or time per output token (TPOT).
  • Error, timeout, and OOM rates.
  • Task-specific quality and correctness.
  • GPU-hours, energy, and cost per successful request.
  • Operational complexity and capacity headroom.

This is an expensive, black-box, multi-objective optimization problem. The goal is not to exhaustively test every combination. It is to spend a fixed GPU budget discovering a small set of feasible, non-dominated candidates, then independently confirm the deployment choice.

2. Define hard constraints before soft objectives#

Do not put every metric into a weighted score immediately. Some are hard product or safety requirements:

  • p99 TTFT below 800 ms.
  • p99 TPOT below 45 ms.
  • Request error rate below 0.1%.
  • Quality regression no worse than 0.3 percentage points.
  • Model fits in GPU memory with operating headroom.

A configuration violating a hard requirement is infeasible even if its throughput or cost is attractive.

Among feasible candidates, optimize objectives such as maximizing SLO-compliant goodput and minimizing cost per successful request or energy per output token.

LaTeX

subject to latency, error-rate, quality, and memory constraints. Here theta is a serving configuration, G is goodput, and C is cost per successful request. The values above are illustrative; derive thresholds from actual product SLOs.

This separation prevents an optimizer from trading away a hard requirement for a small gain elsewhere.

3. Build a realistic conditional search space#

Search dimensions include:

Parallelism and hardware

  • GPU model/count, tensor parallelism, pipeline parallelism, replica count, placement and interconnect topology.

Memory and numerical format

  • BF16, FP16, FP8, supported weight/KV-cache quantization, KV-cache memory target, context length, prefix caching.

Scheduling

  • Maximum batched tokens, concurrent sequences, chunked prefill, scheduler policy, speculative decoding parameters.

Workload and deployment

  • Arrival rate, concurrency, prompt/output length distribution, cache hit ratio, streaming mix, model/tokenizer/runtime/kernel versions.

Use conditional search spaces. A quantization option may only be valid on certain hardware or runtime versions; tensor parallelism must fit the GPU topology. Remove invalid combinations before expensive runs.

A practical sequence:

  1. Apply static feasibility filters: memory fit, supported kernels, valid parallelism.
  2. Use low-cost profiling or analytical estimates to remove clearly poor candidates.
  3. Benchmark a diverse initial set.
  4. Refine promising regions with model-based search.
  5. Re-evaluate finalists at full fidelity.

4. Why Pareto optimization beats arbitrary weighted scores#

Suppose candidate A is cheaper but slower, while B is faster but more expensive. A weighted score such as 0.7 times throughput minus 0.3 times cost hides assumptions about the value of latency and money.

A candidate is Pareto-dominated if another candidate is at least as good in every objective and strictly better in one. The Pareto frontier contains candidates not dominated by another feasible candidate.

Example:

  • A: 1,000 good requests/minute, $0.010 per successful request.
  • B: 1,120 good requests/minute, $0.011 per successful request.
  • C: 950 good requests/minute, $0.012 per successful request.

C is dominated by A. A and B may both remain on the frontier: B offers higher goodput but costs more. The team can choose based on demand and budget rather than inventing weights prematurely.

Keep true optimization objectives small, often two or three. With many objectives, a large fraction of trials can become non-dominated. Model secondary metrics as constraints. NVIDIA AIPerf documents Pareto-aware Bayesian optimization for trade-offs such as throughput versus p99 TTFT. This is an implementation option, not a requirement to use one specific tool.

5. Spend GPU budget using multi-fidelity evaluation#

Full production-like benchmarks are expensive. Multi-fidelity optimization uses cheaper measurements to decide which candidates deserve more resources.

Inference fidelity can vary through shorter duration, fewer requests, representative trace segments, fewer repetitions, lower arrival-rate sweeps, or a subset of workload classes.

Fidelity 0 — static checks

  • Verify model loads and fits in memory.
  • Check kernel and quantization compatibility.
  • Estimate GPU count and memory feasibility.
  • Cost: CPU time or a brief GPU smoke test.

Fidelity 1 — smoke and short profile

  • Load model, warm up, send a short trace.
  • Detect OOM, severe latency, invalid output, unstable throughput.
  • Cost: a few minutes per candidate.

Fidelity 2 — representative medium benchmark

  • Use realistic prompt/output lengths and arrival patterns.
  • Measure TTFT, TPOT, goodput, errors, approximate cost.
  • Cost: tens of minutes per candidate.

Fidelity 3 — full confirmation

  • Full traffic distribution, sufficient tail samples, repeated paired runs, quality evaluation.
  • Reserve for finalists.

Successive halving allocates a small budget to many candidates, eliminates poor performers, and increases the budget for survivors. Hyperband combines brackets to reduce dependence on one initial budget. ASHA keeps workers busy when trials finish at different times.

But early measurements are not always predictive. A configuration with expensive warmup may look bad in a short test but become efficient at steady state. A quantized candidate may perform well on short prompts but fail on long-context quality or KV-cache pressure. Rankings can cross as concurrency rises.

Therefore:

  • Do not prune solely on one noisy short run.
  • Give candidates comparable warmup and minimum measurement exposure.
  • Include multiple workload slices in early screening.
  • Keep an exploration path for candidates poorly represented by the proxy.
  • Validate low-fidelity ranking against historical full-fidelity outcomes.

Multi-fidelity saves budget only when cheaper measurements are informative about the final decision.

6. Use Bayesian optimization when measurements are expensive#

Random search is a useful baseline and often finds diverse configurations. Bayesian optimization becomes attractive when each evaluation is costly and the search space is manageable.

A surrogate model learns from previous measurements and an acquisition function proposes promising next trials. For multiple objectives, Pareto-aware methods estimate expected improvement in dominated hypervolume.

A practical approach:

  • Start with a space-filling initial design, including known-good baseline settings.
  • Use random or quasi-random sampling to cover the space.
  • Fit surrogate models to latency, goodput, cost, and other outcomes.
  • Suggest candidates balancing exploration and exploitation.
  • Apply hard feasibility checks before scheduling GPU time.
  • Update the model as runs complete.
  • Stop at a predeclared budget or convergence condition.

Bayesian optimization is not magic. It can struggle with highly categorical, discontinuous, conditional, or high-dimensional spaces. GPU outcomes can be noisy and non-stationary. If the space is small, random search plus engineering judgment may be simpler.

Do not treat a predicted optimum as measured truth. Actual benchmark results establish observed performance; independent confirmation is still required.

7. Worked numerical example: a 120-GPU-hour tuning budget#

A team tunes a 70B model deployment with 120 GPU-hours. Hard constraints:

  • p99 TTFT below 800 ms.
  • p99 TPOT below 45 ms.
  • Error rate below 0.1%.
  • Quality drop no worse than 0.3 percentage points.
  • No OOM under target traffic.

Objectives: maximize SLO-compliant goodput and minimize cost per successful request.

Budget allocation

  • 10 GPU-hours: baseline measurement, environment validation, workload calibration.
  • 30 GPU-hours: 30 short candidate profiles at roughly one GPU-hour each.
  • 40 GPU-hours: 10 survivors receive four GPU-hours each.
  • 24 GPU-hours: three finalists receive eight GPU-hours each.
  • 16 GPU-hours: independent confirmation, technical reruns, canary preparation.

Total: 10 + 30 + 40 + 24 + 16 = 120 GPU-hours. This is illustrative. A two-GPU run lasting one hour consumes two GPU-hours.

Illustrative outcomes

  • A: 1,050 good requests/minute; $0.010 per successful request; constraints pass.
  • B: 1,180 good requests/minute; $0.011 per successful request; constraints pass.
  • C: 1,250 good requests/minute; $0.009 per successful request; p99 TTFT is 1,050 ms, so infeasible.
  • D: 980 good requests/minute; $0.008 per successful request; quality drops 0.7 percentage points, so infeasible.

C's raw throughput does not make it eligible. D's low price does not justify quality loss. A and B are feasible trade-offs. If capacity is needed, B may be chosen; if A meets demand, its lower unit cost may be preferable.

The selected candidate is rerun against the incumbent on an untouched confirmation workload. The final choice depends on confirmation evidence, not the optimizer's prediction or the best short-profile score.

8. Production incident: the optimizer found a benchmark specialist#

A team tunes a 70B chat model across quantization, tensor parallelism, batched tokens, and concurrency. The optimizer reports a candidate with highest throughput and lowest estimated cost.

After rollout:

  • Long-context requests have worse p99 TTFT.
  • Short requests queue during bursts.
  • Structured-extraction quality falls.
  • GPU memory headroom is insufficient during prefix-cache churn.

The early benchmark used mostly short prompts, stable arrivals, and warm prefix caches. The optimizer was not broken; the measurements did not represent production.

Root cause

  • Workload proxy omitted important traffic segments.
  • Hard latency and quality constraints were not applied during candidate eligibility.
  • Short runs favored configurations whose warmup/cache behavior did not generalize.
  • The team selected a scalar winner and discarded trade-off information.

Fix

  1. Rebuild benchmark workload from privacy-safe production distributions.
  2. Add short, long-context, burst, cache-hit, and cache-miss strata.
  3. Define hard feasibility gates before optimization.
  4. Optimize goodput and unit cost, retaining latency and quality as constraints.
  5. Calibrate low-fidelity ranking against full runs.
  6. Reserve untouched confirmation data and GPU-hours.
  7. Canary and roll back on SLO or quality violations.

9. Make the experiment budget explicit and auditable#

A search budget should be measured in GPU-hours and wall-clock time, not just trial count.

One trial on eight GPUs for 30 minutes costs:

LaTeX

Forty such trials cost 160 GPU-hours before reruns, warmup, and confirmation.

Track:

  • GPU model/count and actual allocation duration.
  • Start/end time and GPU-hours.
  • Model load and warmup time.
  • Benchmark duration and request count.
  • Candidate configuration and code hash.
  • Workload, tokenizer, model and dataset versions.
  • TTFT, TPOT, goodput, errors, quality and cost.
  • Fidelity level and promotion/pruning reason.
  • Failed runs, OOMs, exclusions, optimizer suggestion and seed.

A simple budget guard:

PYTHON
def can_schedule(trial_gpu_count, estimated_minutes, spent_gpu_hours, budget_gpu_hours, reserve_gpu_hours): estimate = trial_gpu_count * estimated_minutes / 60 available = budget_gpu_hours - spent_gpu_hours - reserve_gpu_hours return estimate <= max(0, available)

The reserve prevents exploratory trials consuming the GPU-hours needed for full confirmation. Update spend from actual allocation and runtime, not estimates alone.

10. Example Optuna multi-objective structure#

Optuna supports multi-objective studies and multiple samplers. Exact sampler and constraint APIs depend on installed version. This illustrates the experiment shape, not a drop-in serving integration.

PYTHON
import optuna def objective(trial): max_batched_tokens = trial.suggest_categorical( "max_batched_tokens", [4096, 8192, 16384] ) max_num_seqs = trial.suggest_categorical( "max_num_seqs", [32, 64, 96] ) quantization = trial.suggest_categorical( "quantization", ["bf16", "fp8"] ) result = run_inference_benchmark( max_batched_tokens=max_batched_tokens, max_num_seqs=max_num_seqs, quantization=quantization, fidelity="medium", ) return ( result.goodput_requests_per_second, result.cost_per_successful_request, ) study = optuna.create_study( directions=["maximize", "minimize"], ) study.optimize(objective, n_trials=30)

A real deployment also needs persistent study storage, GPU leases/queues, static compatibility and memory checks, budget-aware scheduling, immutable artifacts, and final confirmation.

The snippet does not automatically enforce p99 or quality thresholds. Represent them through supported constraints or explicit eligibility filters, and verify behavior for the selected sampler and library version.

11. Common mistakes#

  • Pruning from a misleading proxy: validate proxy-to-full-fidelity correlation.
  • Optimizing too many objectives: keep primary objectives few; use hard constraints for product requirements.
  • Using arbitrary weights: preserve Pareto trade-offs when weights are not defensible.
  • Ignoring GPU-hour accounting: track actual resource spend, not trial count.
  • Letting experiments interfere: isolate trials or explicitly model shared-GPU contention.
  • Using one traffic shape: include long-context, burst, cache-hit and cache-miss traffic.
  • Pruning every unusual candidate: preserve exploration diversity and validate early stopping.
  • Trusting predicted optima: remeasure finalists.
  • Spending the entire budget exploring: reserve resources for confirmation.
  • Confusing Pareto optimality with readiness: a non-dominated candidate may still violate a hard SLO.

12. Production operating procedure#

Before search:

  • [ ] Define primary objectives and hard constraints.
  • [ ] Fix GPU-hour and wall-clock budgets.
  • [ ] Record incumbent and baseline.
  • [ ] Validate workload representativeness.
  • [ ] Prune invalid combinations statically.
  • [ ] Choose random, Bayesian, or multi-fidelity search based on space and evaluation cost.

During search:

  • [ ] Record every trial and actual resource spend.
  • [ ] Isolate GPU allocations.
  • [ ] Compare candidates at comparable fidelity.
  • [ ] Track proxy-to-full-fidelity ranking quality.
  • [ ] Preserve diversity and avoid premature pruning.
  • [ ] Stop exploration early enough to fund confirmation.

Before promotion:

  • [ ] Select from feasible Pareto candidates.
  • [ ] Run repeated full-fidelity paired benchmarks.
  • [ ] Use untouched confirmation workload.
  • [ ] Check quality, TTFT, TPOT, goodput, errors, and unit cost.
  • [ ] Canary with rollback thresholds.
  • [ ] Archive search history and decision rationale.

13. Interview-ready answer#

I treat LLM inference tuning as expensive, constrained multi-objective optimization. First, I define hard requirements for latency, quality, error rate, and memory, then optimize a small number of objectives such as SLO-compliant goodput and cost per successful request. I build a valid conditional search space and use static checks to eliminate impossible configurations. To conserve GPU-hours, I use a multi-fidelity funnel: short representative profiles screen candidates, while promising candidates receive longer benchmarks. Bayesian or Pareto optimization can guide the search when measurements are expensive, but I retain exploration diversity and validate that low-fidelity rankings predict full-run outcomes. I track actual GPU-hours, isolate experiments, reserve budget for repeated confirmation, and promote only a feasible Pareto candidate that passes an untouched workload and production canary.

Key takeaway#

A limited GPU budget should buy information, not simply a large number of benchmark runs. Define feasibility first, use multi-fidelity screening only when it predicts full runs, preserve Pareto trade-offs, account for real GPU-hours, and protect an independent confirmation budget.

Related questions

Explore other topics:Deep LearningRetrieval-Augmented GenerationAI Agents