A Software Path to Online Inference on Heterogeneous Accelerators

    In online large-model serving, peak throughput on a hardware spec sheet often diverges from what users actually experience: a card may have high theoretical throughput while the service still suffers from slow first tokens, choppy output, and high unit cost. This article explains why the bottleneck usually lies in how software organizes compute, memory access, and scheduling for interactive traffic rather than in whether the chip can do matrix multiplication. It covers the metrics that matter (time to first token, decode speed, and unit cost under latency constraints), why memory movement rather than arithmetic dominates, how to apply operator fusion within numerical and shape constraints, what runtime scheduling must handle, how to build a cost model for hardware selection, and a staged path from testing to carrying production traffic, along with common failure modes and boundaries.

    In online large-model serving, peak throughput on a hardware spec sheet often diverges from what users actually experience. A card may have high theoretical throughput, yet the service can still deliver slow first tokens, choppy output, and high unit cost. The reason usually is not whether the chip can perform matrix multiplication, but whether the software organizes compute, memory access, and scheduling into a form suited to interactive traffic. For heterogeneous accelerators to enter the production main path, the key is to move inference software from “functionally correct” to “acceptable latency, throughput, and cost at the same time.”

    Align on the Metrics First

    Interactive inference must be evaluated on at least three kinds of metrics at once; a single benchmark score cannot substitute for them.

    The first is time to first token (TTFT), the time from when a request enters the service to when the first output fragment is returned. It is mainly affected by the prefill stage: the entire input must be encoded into the key-value (KV) cache, the amount of computation grows with input length, and the work is often a mix of compute-intensive and bandwidth-intensive operations. In long-context scenarios, TTFT exposes software shortcomings more clearly than short chat prompts do.

    The second is decode speed, the rate at which each request keeps emitting content during the generation stage. Each decode step usually produces only a small amount of new computation but must repeatedly read a large KV cache. At this point the bottleneck often shifts from compute to memory bandwidth and cache hit rate, not floating-point peak.

    The third is unit cost under latency constraints. What production systems care about is: when both TTFT and decode speed fall within a product-acceptable range, how much accelerator time, power, and operational cost each unit of effective output absorbs. A solution with higher peak throughput may not have a better unit cost if it must use more expensive resources, lower utilization, or stricter batching to meet the target. Conversely, a solution with lower peak but a software stack that fits the traffic shape better may be more economical under real load.

    When benchmarking, fix four things: model structure and quantization method, input and output length distributions, concurrency and arrival process, and the threshold for “acceptable latency.” Comparing only idle-limit throughput easily leads to conclusions opposite to what production shows.

    The Bottleneck Is Mostly Data Movement, Not Multiplication

    In a single forward pass, if operators are split into many small kernels and each step writes intermediate results back to main memory and reads them again, a large amount of time is spent on the bus. Compute units on the accelerator wait for data, and peak throughput cannot be realized. This problem is more pronounced on heterogeneous platforms: if the compiler, operator library, and runtime generate kernels from generic templates, they often conservatively keep intermediate tensors, and only part of the hardware capability is used.

    Therefore the first priority is not to blindly add more cards, but to reduce unnecessary memory access:

    • Merge computations that are necessarily adjacent into the same kernel so intermediate results stay in on-chip cache or registers.
    • Avoid splitting normalization, activation, residual, and matrix multiplication into multiple full reads and writes just to keep “operator boundaries clean.”
    • For decode steps, which involve small computation and large cache access, prioritize cache layout and read granularity rather than only optimizing the theoretical efficiency of matrix multiplication.
    • Align quantized data formats with the load width supported by the kernel; otherwise the computation saved is eaten up by inefficient unpacking.

    A simplified execution model helps illustrate the benefit. Suppose the computation amount of a stage is (C), the number of bytes that must be moved from main memory is (B), accelerator throughput is (P), and bandwidth is (W). Stage time is approximately (\max(C/P,\ B/W)) plus kernel launch and synchronization overhead. When (B/W) is larger, further increasing (P) barely shortens time. The goal of fusion is to reduce (B) and the number of launches so that time moves back toward (C/P).

    Operator Fusion Must Respect Numerical and Shape Constraints

    Fusion is not about blindly collapsing every node in the graph into one. In engineering practice, opportunities are usually handled in four categories.

    1. Elementwise chains. Operators such as normalization, activation, bias, and residual addition, which are memory-heavy and compute-light, are best merged into adjacent matrix multiplication or attention output. After fusion, verify numerical error element by element, especially when low-precision accumulation and scaling order change.

    2. Inside attention. If score computation, masking, normalization, and value-vector weighting are split into multiple global reads and writes, bandwidth dominates latency on long sequences. Completing this segment in on-chip tiles is usually more effective than optimizing a single matrix multiplication in isolation. Tile size must be constrained by both on-chip storage capacity and the sequence-length distribution; it cannot be hard-coded to a single benchmark length.

    3. Separate paths for prefill and decode. Prefill consumes a long input at once, suitable for larger tiles and higher parallelism; decode appends only one or a few positions per step, suitable for cache reuse and fewer launches. Sharing the same set of “unfused” operators across both paths often leaves both suboptimal.

    4. Overlap communication with computation. When splitting across multiple cards, if collective communication runs fully serially after computation, scaling efficiency drops quickly. Overlap is possible only when the partitioning scheme, buffers, and synchronization points are planned at the graph level, not patched in before launch.

    An illustrative graph-rewrite logic can be written as the following check, rather than bound to a specific framework API:

    1. for node in graph.topological_order():
    2. if node.is_elementwise() and node.producer_is_fused_candidate():
    3. if numerics_ok(node) and onchip_budget_ok(node):
    4. fuse(node.producer, node)
    5. mark_intermediate_not_materialized(node.input)
    6. elif node.is_attention_block():
    7. plan = choose_tiling(seq_len_histogram, onchip_bytes)
    8. replace_with_blocked_attention(node, plan)

    Before launch, keep both “pre-fusion” and “post-fusion” implementations switchable, and compare numerical range, failure rate, and tail latency on the same batch of requests, so you do not merely see a faster average.

    Runtime Determines Whether the Card Can Absorb Real Traffic

    A single-request microbenchmark running smoothly does not mean the service is smooth. An online system must also handle requests of varying lengths, uneven arrivals, and timeout constraints.

    Dynamic batching must weigh “waiting to fill a batch” against the “TTFT budget.” Waiting too long lets short requests be dragged down by long ones; not waiting lets kernel launches and memory fragmentation reduce utilization. In practice, bucket by input length, cap the maximum waiting time per batch, and queue very long requests separately so that one extremely long prefill does not block the whole card.

    The KV cache is the main memory resident during decode. The page size of cache blocks, prefix reuse, and reclamation policy directly determine how much concurrency can be opened. Pages that are too large cause fragmentation; pages that are too small raise management overhead. Requests with the same prefix should reuse existing cache as much as possible, but there must be explicit invalidation and isolation policies to prevent cross-talk from incorrect reuse.

    The core of continuous batching or stepwise scheduling is to let finished sequences immediately yield their slots and let new requests fill in, rather than having the whole batch finish together. This makes card utilization during decode more stable and tail latency more controllable. The scheduler needs visibility into per-step time, cache occupancy, queue waiting, and timeout ratio, not just average output per second.

    Use a Cost Model for Selection, Not Peak Numbers

    Selection can use a model that is simple enough but must be consistent in definition. Suppose under a given latency threshold, the effective output rate a single card can sustain is (R), and the comprehensive cost per unit time for a single card is (C) (including device amortization, power, rack space, and necessary software maintenance, under the same financial definition). Unit output cost is approximately (C/R). (R) must be measured under the target length distribution and concurrency; vendor peak or idle-limit numbers cannot substitute.

    When comparing two accelerators, look at three things at once: (R) within the threshold, the software complexity required to reach that (R), and whether communication efficiency holds during scaling. If a solution has higher peak but its (R) gain is smaller than its cost increase, an interactive business should not choose it merely for peak. If a solution has ordinary peak but fusion and scheduling bring (R) close to business needs at lower (C), it is a candidate for the main path.

    Also note that “idle-hour price” and “busy-hour guarantee” are not the same thing. Deriving revenue from electricity or rental prices during low-load periods overestimates economics. Capacity planning should be based on peak arrival rate, timeout rate, and failure redundancy, and idle time should be treated as utilization optimization space, not the only measurement scenario.

    Steps from Experiment to Carrying Traffic

    Proceed in order of increasing risk rather than replacing all traffic at once.

    1. Correctness baseline. Use a fixed random seed and a small set of representative long and short requests to compare output difference thresholds, special tokens, and stop conditions before and after fusion. Samples exceeding the threshold must be traceable to the specific fusion segment.

    2. Single-card performance profile. Measure prefill and decode separately, sweeping input length, batch size, and cache occupancy. Plot time versus length and confirm there is no sudden deterioration in a particular length bucket.

    3. Service-level stress test. Use an arrival process and length distribution close to production, and observe TTFT percentiles, decode speed percentiles, timeout rate, and failure rate. An average TTFT that meets the target while high percentiles are poor still cannot carry interactive traffic.

    4. Canary rollout. First shift low-risk, rollback-capable traffic to the new path, keeping the old path as hot standby. Compare resource usage and user-side cancellation rate for the same requests on both paths. A rising cancellation rate often indicates worse perceived experience, even if monitored averages still look good.

    5. Steady-state operation. Set up alerts for kernel fallback ratio, cache allocation failures, queue waiting, sudden increases in per-step time, and numerical protection triggers. Fallback to the unfused implementation should be automatic and observable, not a temporary configuration change.

    Common Failures and Boundaries

    Excessive fusion leads to long compile times, high register pressure, performance regression at certain lengths, and even result drift under low precision. The goal should be “stable improvement across the main length buckets,” not fusing every operator in the graph.

    Optimizing only short-prompt benchmarks fails on long documents and multi-turn conversations, because the KV cache and prefill begin to dominate. The evaluation set must include long inputs.

    Ignoring tail latency and failure redundancy brings good-looking numbers from the test environment into production. Capacity must at least meet the timeout budget when a single point degrades.

    Claiming that economics have “comprehensively surpassed all high-end accelerators” also lacks a basis. Conclusions change with different models, quantization, context lengths, and business thresholds. A responsible statement is: under the declared load and latency constraints, unit cost and experience have reached a production-ready range, and the same definition is used for continuous re-measurement.

    Conclusion

    Whether heterogeneous accelerators can carry online inference depends on whether the software designs memory access, fusion, caching, and scheduling together. TTFT tests the prefill path, decode speed tests the cache and bandwidth path, and unit cost tests whether this path is worth it under real traffic. Measuring these three things accurately and making rollout a staged, rollback-capable process determines whether it enters the production main path more than chasing a single peak number does.