Production Inference with Open-Source LLM Engines on Domestic AI Accelerators

    This article examines how to bring open-source inference engines to production on domestic AI accelerators. It breaks down three optimization tracks—operator kernels, communication and memory management, and scheduling—and outlines an evaluation framework, a staged rollout path with rollback, observability practices, and common pitfalls. The methodology is vendor-neutral and can be reproduced on general-purpose cloud capabilities such as container platforms, object storage, logging, and monitoring with alerting, including those offered by Baidu AI Cloud.

    1. Background and Problem Definition

    A notable signal has recently emerged in the industry: an open-source inference engine announced the open-sourcing of production-grade inference code running on a domestic AI acceleration platform, now serving large-scale live user traffic in a real production environment. The significance of such an event lies not in any specific product, but in validating a general engineering path—high-performance inference can reach a usable, controllable, and reproducible level on heterogeneous compute through open collaboration and systematic optimization.

    For developers and enterprise users, the real pain points cluster in four areas:

    • Incomplete operator coverage causes fallbacks and performance collapse;
    • Multi-GPU, multi-node communication becomes the throughput bottleneck, with scaling efficiency degrading as scale grows;
    • Coarse-grained GPU and host memory management frequently triggers swapping and fragmentation in long-context scenarios;
    • Rigid scheduling and batching strategies fail to balance low latency and high throughput at the same time.

    This article abstracts these problems from a neutral perspective and presents a vendor-agnostic engineering methodology, along with how to implement it on top of the general-purpose cloud capabilities provided by Baidu AI Cloud (container platform, object storage, message queue, logging service, monitoring and alerting, and so on).

    2. Three Optimization Tracks for Inference Engines

    2.1 Core Operator Optimization: From “It Runs” to “It Runs Fast”

    Operators are the foundation of inference performance. Production-grade optimization typically spans the following layers:

    • Operator fusion at the computation-graph level, merging the scaling, masking, softmax, and weighted sum in attention to reduce reads and writes of intermediate tensors;
    • Rewriting memory access patterns for the hardware memory hierarchy to improve data locality and reduce bandwidth pressure;
    • Quantization and low-precision compute paths that raise output per unit of compute within an acceptable accuracy range;
    • Efficient handling of variable-length sequences, avoiding large amounts of wasted computation introduced purely for alignment.

    The fusion logic can be sketched as:

    1. # Pseudocode: fused execution of an attention fragment, avoiding intermediate tensor materialization
    2. def fused_attention(q, k, v, mask=None):
    3. scores = matmul(q, transpose(k)) * scale_factor
    4. if mask is not None:
    5. scores = add_mask(scores, mask)
    6. probs = softmax_inplace(scores) # in-place compute, saves one GPU memory round trip
    7. return matmul(probs, v)

    In practice, this must be paired with an “operator coverage checklist”: annotate one by one which operators use high-performance implementations and which fall back to generic ones, and set performance red-line alerts on the fallback paths to avoid hard-to-diagnose latency spikes in production.

    2.2 Communication and Memory Management: The Ceiling on Scaling Efficiency

    In multi-GPU, multi-node deployments, communication often hits the wall before compute does. Reusable optimization techniques include:

    • Overlapping communication with computation, hiding part of the communication in tensor parallelism behind compute;
    • Hierarchical collective communication, using high-bandwidth interconnects within a node and compressing data volume across nodes;
    • Micro-batch partitioning in pipeline parallelism to reduce the bubble ratio;
    • GPU memory pooling and chunked management, combined with a paging mechanism for the KV cache, to reduce fragmentation and repeated allocation;
    • Using host memory as a second-level cache to smooth swapping in and out under long context and high concurrency.

    The memory budget can be constrained by a simplified inequality:

    1. per-GPU memory ≥ weight shard + peak activations + KV cache + communication buffers + safety margin

    The KV cache grows linearly with concurrency and context length, making it the item most likely to get out of control. In production practice, hard caps are usually set on maximum context, maximum concurrency, and cache occupancy, and queuing or degradation is enforced when limits are exceeded rather than letting it drag down the entire GPU.

    2.3 Inference Pipeline and Task Scheduling: Governing Latency and Throughput Separately

    Low latency and high throughput are essentially two sets of goals that require different strategies:

    • Continuous batching: dynamically assembling batches at the request level to avoid waiting for a full batch;
    • Chunked prefill: splitting long prompts into chunks and interleaving them with the decode phase to mitigate first-token latency jitter;
    • Priority queues: interactive requests go first, offline batch jobs yield;
    • Warm-up and always-on replicas: reducing the impact of cold starts on tail latency;
    • Elastic autoscaling: triggered by queueing time and memory watermark rather than CPU metrics alone.

    A minimal viable scheduling feedback loop can be described as:

    1. while service_alive:
    2. batch = scheduler.form_batch(max_tokens=BUDGET, prio_first=True)
    3. result = engine.step(batch)
    4. metrics.observe(latency_p99=result.latency, kv_usage=result.kv_ratio)
    5. if metrics.latency_p99 > SLO:
    6. scheduler.shrink_batch()
    7. elif metrics.kv_usage < LOW_WATER:
    8. scheduler.grow_batch()
    9. sleep(interval_ms)

    3. Evaluation and Rollout Path for Production

    3.1 Build a Systematic Evaluation Framework

    Do not look at a single throughput number. It is recommended to fix four categories of metrics: first-token latency, per-token latency, end-to-end P99, and cost per request; and to record operator fallback rate, communication wait ratio, memory fragmentation rate, and cache hit rate alongside them. All data must come from reproducible load-test scripts and a fixed dataset; otherwise cross-version comparisons are meaningless.

    3.2 Canary Rollout and Rollback

    Rollout follows the order “offline load test → small-traffic canary → region-by-region ramp-up → full rollout”, with a one-click rollback to the previous inference image and configuration preserved at every stage. Configuration and model weights are managed separately, with weights stored in object storage and version numbers and checksums pinned in the release manifest.

    3.3 Observability

    The logging service is responsible for structured recording of the request path, while monitoring and alerting cover four core signals: latency, error rate, memory, and queue length. It is recommended to set tiered thresholds for each signal class, alerting the on-call person first and then automatically triggering rate limiting, to avoid the lag of manual intervention.

    4. Common Pitfalls

    • Optimizing operators without changing scheduling, so gains are eaten by queueing time;
    • Blindly increasing batch size, causing tail latency to exceed SLO;
    • Ignoring fallback paths, so performance suddenly degrades on long-tail inputs;
    • Lacking a versioned load-test baseline, making it impossible to tell whether an optimization actually helped;
    • Basing capacity planning on averages while ignoring peak concurrency combined with long context.

    5. Conclusion

    Production-grade usability of inference engines on domestic acceleration platforms comes down to three things holding simultaneously: no weak spots in operators, controllable communication and memory, and scheduling strategies aligned with goals. This methodology is independent of any specific brand; developers can reproduce the same path in a cloud environment with general-purpose capabilities such as a container platform, object storage, logging, and monitoring with alerting, including Baidu AI Cloud, and iterate continuously in a data-driven way to ultimately deliver online inference services that are low-latency, economical, and stable.