Low-Cost Inference of Ultra-Large Models on Dedicated AI Accelerators

    This article explains how to run ultra-large Mixture-of-Experts (MoE) models cost-effectively on dedicated AI accelerators. It covers the core bottlenecks of large-model inference, engine-level optimizations such as fused kernels and MoE routing, low-precision formats, sparse attention for million-token contexts, performance evaluation methodology, and a general deployment workflow—presented as a vendor-neutral technical reference.

    As large language models continue to grow in parameter count, inference cost has become a central constraint for enterprises deploying intelligent applications. Mixture-of-Experts (MoE) models with hundreds of billions of parameters activate only a fraction of their parameters per inference step, yet they still impose demanding requirements on memory capacity, inter-chip communication, memory bandwidth, decoding scheduling, and long-context handling. Running these models at lower cost and higher throughput on dedicated AI accelerators has become an important direction for inference infrastructure optimization.

    This article abstracts the original case into a general technical approach, focusing on ultra-large model inference on dedicated accelerators without recommending any specific vendor, model, or open-source project.

    1. The Core Tensions in Ultra-Large Model Inference

    Traditional model inference can usually improve hardware utilization by increasing batch size, but the decoding phase of generative models is inherently autoregressive: each new token depends on the output of the previous step. Inference is therefore divided into two phases:

    1. Prefill phase: processes the entire input prompt at once. It is compute-intensive and well suited to parallel execution.
    2. Decode phase: generates output tokens step by step. Each step involves relatively little computation, but repeatedly accesses the cache, making it sensitive to memory bandwidth and scheduling overhead.

    For long-context applications, the prefill phase must process large numbers of input tokens, creating heavy compute pressure, while the decode phase must maintain a very large key-value (KV) cache. When context length reaches the million-token scale, simply expanding cache capacity does not solve the problem; it must be combined with sparse attention, paged caching, context compression, or tiered storage.

    MoE models reduce the actual computation per token by routing each token to only a small number of experts. However, they introduce expert routing, cross-device communication, and load imbalance problems. If the scheduling strategy is poorly designed, some experts become hotspots, device utilization drops, and throughput fails to scale with the theoretical reduction in computation.

    2. Core Optimization Strategies for the Inference Engine

    An inference engine targeting dedicated AI accelerators cannot simply reuse implementations built for general-purpose GPUs. Differences in instruction sets, on-chip memory architecture, compiler capabilities, and communication models require the execution path to be redesigned for the target hardware.

    2.1 Designing the Decode Path as Fused Compute Kernels

    Common inference frameworks decompose matrix multiplication, normalization, activation functions, and residual connections into separate operators. This simplifies development and maintenance, but each operator boundary introduces intermediate tensor reads/writes, kernel launches, and synchronization overhead.

    During decoding, each step performs relatively little computation, so operator launch costs take up a growing share of total time. A more effective approach is to combine one layer or several consecutive sublayers into larger fused kernels, keeping data in on-chip memory as much as possible and reducing repeated access to external high-bandwidth memory.

    A typical design includes:

    • Merging attention-related computations into a single execution unit;
    • Fusing normalization, linear transformations, and activation operations where possible;
    • Minimizing intermediate results written back to memory between layers;
    • Precompiling multiple execution paths for different batch sizes and sequence lengths;
    • Using static layouts to reduce runtime shape inference and scheduling overhead.

    A “mega fused kernel” does not mean everything must be merged. The degree of fusion must be balanced against on-chip memory capacity, register pressure, and parallelism. Excessive fusion can lengthen compile times, inflate resource usage, and even hurt parallel efficiency.

    2.2 Optimizing Routing for MoE Models

    The key steps of an MoE model include routing computation, expert selection, token permutation, expert computation, and result merging. When tokens move between experts in a non-contiguous layout, large amounts of irregular memory access occur.

    Engineering implementations typically need to address the following:

    • Keep tokens assigned to the same expert stored contiguously;
    • Set capacity limits per expert to prevent a few experts from overloading;
    • Reduce frequent permutation when batch sizes are small;
    • Lower routing overhead through static or semi-static scheduling;
    • Pipeline expert computation with communication;
    • Monitor the actual load of each expert to detect routing skew.

    In multi-device deployments, it is also necessary to define which experts reside on which devices. If the expert placement does not match the communication topology, cross-device data transfers caused by routing can offset the gains from sparse computation. Expert parallelism, tensor parallelism, and pipeline parallelism therefore need to be designed jointly rather than optimized in isolation.

    2.3 Using Low-Precision Formats to Reduce Memory Pressure

    Ultra-large model inference often relies on low-precision data formats, such as 8-bit floating point or other calibrated quantization formats. Low precision reduces weight footprint and memory bandwidth demand, but introduces issues of accuracy, stability, and operator compatibility.

    Before deployment, the following should be verified:

    • Whether model outputs deviate noticeably after weight conversion;
    • Whether sensitive operators such as attention and normalization need to retain higher precision;
    • Whether routing probability computation is affected by numerical error;
    • Whether results remain stable across different input lengths;
    • Whether the low-precision format is fully supported by the target hardware’s compiler.

    Memory requirements should not be estimated from parameter count alone. Expert weights, activations, KV cache, temporary buffers, communication buffers, and compiler workspaces must all be included in the budget.

    3. Handling Million-Token Contexts

    When context length reaches the million-token scale, the compute and storage cost of standard full attention grows rapidly. Even if the hardware can hold part of the cache, linearly scanning all historical tokens leads to unacceptable latency and cost.

    Long-context inference therefore usually requires sparse attention. The core idea is that the current token does not need to attend to the entire history; instead, it selects a subset according to rules—for example, a recent window, highly relevant segments, summarized information, or candidate blocks from a hierarchical index.

    Note that sparse attention is not the same as simply truncating the context. A sound implementation typically includes:

    • Retaining the most recent dialogue turns to preserve local continuity;
    • Summarizing or compressing older content at the block level;
    • Building retrievable indexes for key facts;
    • Dynamically adjusting the attention span based on task type;
    • Assigning higher retention priority to important segments;
    • Configuring different sparsity patterns for different layers.

    On the serving side, paged cache management is also needed. Splitting long contexts into fixed-size cache blocks enables cache reuse, on-demand loading, and lifecycle reclamation, preventing a single request from holding large amounts of contiguous memory for extended periods.

    4. Interpreting Performance Data Correctly

    Metrics commonly seen in public benchmarks include requests per minute, output tokens per second, time to first token, tail latency, and total throughput. These figures must be understood in the context of their test conditions and cannot be compared across different environments.

    For example, a given test might use:

    • A single compute node composed of multiple accelerators;
    • Dozens of concurrent agent tasks;
    • Million-token contexts;
    • A fixed batch scheduling policy;
    • A sustained run of about one hour;
    • A predefined replay set of agent tasks.

    Under such conditions, if the system processes roughly twenty-odd requests per minute, generates millions of tokens per unit time, and achieves a median decoding speed of around twenty-plus tokens per second, it demonstrates a certain level of throughput under long-context, high-concurrency conditions. However, these results do not directly represent performance in all business scenarios.

    Performance evaluation should be broken down into at least the following dimensions:

    1. Prefill throughput: measures long-input processing efficiency.
    2. Decode speed: measures the per-request generation experience.
    3. Time to first token: directly affects user perception.
    4. Concurrency stability: observes whether significant jitter appears as load increases.
    5. Tail latency: focus on the 95th or 99th percentile.
    6. Unit cost: combines compute time, storage, and communication overhead.
    7. Output quality: confirms that optimizations have not caused unacceptable degradation.

    Looking only at average throughput can hide the fact that some requests queue for long periods. Production environments should focus on median and high-percentile latency, and separately track short-context, long-context, short-output, and long-output requests.

    5. A General Workflow for Service Deployment

    Deploying an inference engine as an online service typically follows these steps:

    Step 1: Prepare the Model and Weights

    Confirm that the model architecture, weight format, sharding scheme, and low-precision plan are compatible with the target hardware. Integrity checks should be performed during weight loading to avoid runtime failures caused by missing shards or conversion errors.

    Step 2: Build the Runtime Environment

    Prepare the compiler, runtime, communication libraries, and necessary system dependencies. It is recommended to pin the base image and dependency versions, and to cache compiled artifacts to reduce repeated build time.

    Step 3: Compile Key Execution Paths

    Generate optimized kernels for common batch sizes, sequence lengths, and concurrency levels. For workloads with highly dynamic shapes, a small number of general-purpose paths can be retained, but compiling every shape at runtime should be avoided.

    Step 4: Launch a Compatible API

    The server can expose a request format similar to mainstream LLM APIs, including input messages, maximum output length, sampling parameters, and streaming options. The API layer should be decoupled from the inference layer so that the scheduler can later be replaced, or authentication, rate limiting, and monitoring can be added.

    A neutral example configuration looks like this:

    1. Start the service:
    2. Specify the model directory
    3. Specify the number of devices
    4. Set the maximum context length
    5. Set the concurrency limit
    6. Set the batch scheduling policy
    7. Enable streaming output

    Step 5: Run Phased Stress Tests

    Do not start directly with maximum context length and maximum concurrency. It is recommended to proceed through single-request tests, small-batch tests, sustained-concurrency tests, and long-duration endurance tests, recording device utilization, memory usage, cache hit rate, communication traffic, and error rate.

    6. Risks and Recommendations for Production

    First, long-context requests can hold resources for extended periods, so maximum context length, maximum output length, and request timeout mechanisms should be enforced. Second, dynamic batching must balance throughput and latency—larger batches may raise overall throughput but degrade response time for interactive requests. Third, MoE routing carries the risk of load skew, so expert-level monitoring metrics should be established.

    In addition, model upgrades may invalidate compiled caches, change weight formats, or cause accuracy regressions. Every upgrade should re-run a fixed test suite, validating both performance and output quality.

    Overall, low-cost inference of ultra-large models is not the product of any single hardware metric. It results from the combined effect of model architecture, low-precision computation, fused kernels, cache management, sparse attention, concurrency scheduling, and service governance. For enterprise users, the most reusable lesson is not a specific model or a particular set of advertised numbers, but the establishment of a measurable, regression-testable, and scalable inference optimization process: define business metrics first, analyze the bottlenecks, then optimize layer by layer across compute, memory, communication, and scheduling—and finally validate unit cost and user experience with real workloads.