Model Inference Speed on the Same Hardware: Why It Varies and How to Optimize It

    Models running on the same accelerator can differ substantially in latency, throughput, and memory use. This article explains how sparse and dense architectures, runtime settings, and benchmarking choices contribute to those differences. It also outlines how to run reproducible tests, identify the limiting factor, and choose optimizations that match the workload.

    1. A Speed Difference Does Not Necessarily Indicate a Hardware Problem

    Two models can differ in inference speed by several times even when they run on the same accelerator node with identical input and output lengths and the same runtime version. Performance depends on model architecture, the number of parameters activated per token, memory access patterns, batch scheduling, cache management, precision, the compiler backend, and how performance is measured. A single end-to-end timing can make warm-up, sampling, variable output lengths, GPU memory allocation, or queueing look like an architectural difference.

    Start by choosing metrics that reflect the workload:

    • Time to first token (TTFT) captures the initial delay, including preprocessing and, on cold runs, weight loading and cache initialization.
    • Time per output token reflects the cost of generating tokens after the first one and is particularly sensitive to compute and memory bandwidth.
    • Throughput measures work completed per unit of time and depends heavily on batching, continuous scheduling, and parallelism.
    • Tail latency under concurrency can reveal queueing, load imbalance, and memory fragmentation.
    • Peak GPU memory usage shows how much memory a configuration requires at its busiest point.

    For a fair comparison, hold the input-length distribution, output length, sampling strategy, batch size, precision, and warm-up procedure constant. Use the same reporting method for both models and report p50 and p95 latencies rather than the fastest run.

    2. Sparse and Dense Models Have Different Bottlenecks

    In a sparsely activated model, each token uses only a subset of the parameters or experts. A dense model, by contrast, uses the full set of parameters for each token. Sparse activation reduces theoretical compute per token, but that does not guarantee faster inference. Routing overhead, expert load balance, cross-device communication, memory access locality, and the distribution of tokens within a batch all affect realized performance.

    When tokens are routed across many experts, expert loads are uneven, or sequence lengths vary widely within a batch, extra waiting, communication, and GPU memory fragmentation can offset the compute savings. Dense models perform more computation per token, but their regular operations and predictable memory access patterns can make it easier to achieve high hardware utilization at an appropriate batch size.

    Neither total parameter count nor active parameter count is enough to predict inference speed. Also examine arithmetic intensity, memory bandwidth utilization, cache hit rates, time spent on communication, and idle time caused by scheduling. With long contexts, cache memory can limit concurrency. With short outputs, TTFT and scheduling overhead account for a larger share of end-to-end latency.

    1. For each model configuration:
    2. Fix input and output lengths
    3. Measure:
    4. Time to first token
    5. Time per output token
    6. Throughput
    7. Peak GPU memory usage
    8. Fraction of time spent waiting on communication
    9. Identify the likely bottleneck:
    10. High compute utilization -> compute-bound
    11. High bandwidth utilization with idle compute units -> memory-bound
    12. Significant synchronization waits -> communication- or scheduling-bound

    3. Runtime Configuration: Precision, Batching, and Caching

    Lower precision generally reduces GPU memory usage and bandwidth demand, but quantization can introduce format conversions, operator fallbacks, or calibration overhead. Different architectures can also respond differently to quantization.

    Larger batches can improve throughput at the cost of higher TTFT and tail latency. Continuous batching can improve utilization under concurrent load, but large differences in request length can leave gaps in the schedule and trigger cache reallocations. For long-context workloads, cache paging, reuse, and preallocation policies also affect memory fragmentation and cache hit rates.

    Operator fusion, graph compilation, kernel selection, thread and stream parallelism, and the memory allocator can all change how the same model performs across backends. Keep the runtime version, weight format, batching policy, and precision settings consistent when comparing architectures. Otherwise, a configuration difference can be mistaken for a model difference.

    1. Example benchmark configuration:
    2. Input lengths: [128, 512, 2048]
    3. Output length: 256
    4. Batch sizes: [1, 4, 8]
    5. Precision: half precision
    6. Decoding: greedy
    7. Warm-up runs: 3
    8. Measurement runs: 20
    9. Report: p50 and p95 latency, throughput, peak GPU memory usage

    4. Design a Reproducible Inference Benchmark

    Run both models on the same node with the same driver and runtime versions, weight format, input and output length distributions, batch size, concurrency level, and decoding strategy. Use warm-up runs to trigger weight loading, graph compilation, and cache initialization before collecting measurements. Repeat the measured runs and report percentiles.

    If you use sampling rather than greedy decoding, fix the random seed or at least keep the sampling parameters constant. Account for variation in generated output lengths when comparing throughput. Record device temperature, clock frequencies, power limits, and peak GPU memory usage to help rule out thermal throttling or fallbacks caused by memory pressure.

    To isolate a bottleneck, start with a single request, greedy decoding, and a fixed short output. Once you have a baseline, increase batch size, input length, and concurrency one at a time. Look for points where latency or throughput changes sharply. Then disable or swap one suspect setting at a time, such as quantization, graph compilation, cache reuse, or the parallelism strategy, to see which change drives the result.

    For sparse models, inspect the distribution of work across experts and the stability of routing within batches. For dense models, focus on operator fusion, batch scheduling, and cache memory usage.

    5. Optimize for the Bottleneck and the Workload

    • Compute-bound: Evaluate precision formats, operator fusion, batch-size tuning, and kernel selection.
    • Memory-bound: Review weight layout and cache paging, reduce intermediate tensor copies, and improve cache reuse.
    • Communication- or scheduling-bound: Examine the granularity of parallel work, synchronization frequency, the spread of sequence lengths within batches, and queueing policies.

    For sparse models, balancing expert loads, managing expert capacity, stabilizing routing, and improving batch scheduling can be more effective than simply increasing parallelism. For dense models, continuous batching, quantization, memory preallocation, and operator fusion often offer more direct gains.

    Treat an inference speed gap as evidence of different bottlenecks under a specific workload, not as a universal model ranking. For interactive serving, prioritize TTFT and tail latency. For offline processing, focus on throughput and GPU memory limits. For long-context workloads, track cache hit rates and memory fragmentation. Consistent metrics, controlled experiments, and ongoing monitoring make performance differences easier to reproduce, explain, and optimize.