LLM Inference at Scale: Engineering a Profitable Token Factory in the Domestic Chip Era

    This article explains why stacking accelerators does not create a profitable inference pipeline, and what actually does. It breaks down the Token factory as a production line measured by cost per million tokens, the hardware-software mismatch between older accelerators and MoE, long-context models, the resource contention between prefill and decode, and the adaptation gap created by weekly model releases across more than twenty domestic chip backends. It then covers a unified system software stack as a shared foundation, constrained auto-tuning in sparse search spaces, a four-step rollout with quantifiable acceptance criteria, and supporting cloud capabilities.

    1. Stacking Accelerators Is Not Capacity: A Token Factory Is a Production Line

    Racking accelerators, powering them on, and starting a service is still a long way from an inference line that stays profitable and survives heavy traffic. A “Token factory” is essentially a production line with a single north star metric: cost per token. Upstream sits the model weights and inference framework; in the middle are compilation, operators, memory, and scheduling; downstream are the gateway, rate limiting, caching, and metering. Efficiency loss in any stage converts directly into marginal cost per million tokens.

    From a production-line view, four quantities must be watched at once: throughput (tokens/s), latency distribution (especially P99), cost per token, and effective utilization (the share of compute actually spent generating rather than waiting or moving data). Optimizing only one usually degrades another, which is why many teams “swap in new cards and see no speedup.”

    2. The Mismatch Starts in Hardware: Old Architectures Meet New Model Shapes

    Today’s mainstream LLMs commonly use mixture-of-experts (MoE) structures and very long contexts, but the accelerators deployed at scale earlier were not designed with either in mind: memory capacity and bandwidth were sized for dense-model assumptions, and the interconnect topology gives little attention to the frequent All-to-All communication of expert parallelism (EP). The result is that memory runs out before compute does, and communication becomes the bottleneck before computation does.

    Newer high-compute chips ease peak compute pressure but do not automatically solve software coordination. Once the hardware ceiling rises, scheduling, memory management, and operator implementations that still rest on old assumptions will let the added compute be consumed by more waiting and more data movement.

    3. The Real Bottleneck Is the Software Stack: Prefill and Decode Contend for Resources

    Autoregressive inference has two phases with very different resource profiles:

    • Prefill: processes a long prompt in one pass, is matrix-multiply heavy, consumes compute, and is compute-bound.
    • Decode: generates token by token, reads the key-value cache (KV Cache) at every step, consumes memory bandwidth, and is bandwidth-bound.

    Long-context agent scenarios amplify this conflict: contexts easily reach hundreds of thousands of tokens, KV Cache usage balloons, and when requests from both phases run in the same batch, a long prefill blocks short decodes, producing jitter where “compute waits on data and bandwidth gets squeezed” and P99 latency destabilizes.

    Common composable engineering measures include: phase-separated deployment (separate prefill/decode pools, each with its own parallelism and batching strategy), paged KV management to reduce fragmentation, prefix caching to reuse system prompts and tool definitions, KV quantization and offloading to slower media, and priority- and SLA-aware continuous batching. Illustrative policy configuration logic follows (pseudocode only, to express scheduling intent):

    1. # Pseudocode: phase-based pooling + priority continuous batching
    2. scheduler = Scheduler(
    3. pools={
    4. "prefill": Pool(parallel="TP+EP", max_batch_tokens=131072),
    5. "decode": Pool(parallel="TP", kv_page_size=16, kv_quant="int8"),
    6. },
    7. policy=PriorityContinuousBatching(
    8. prefill_max_wait_ms=8, # avoid long prompts blocking generation
    9. decode_sla_p99_ms=300,
    10. prefix_cache=True, # reuse system prompts and tool definitions
    11. ),
    12. )

    4. The Underrated Gap: Weekly Model Iteration vs. Adapting to 20+ Chip Backends

    Model capability updates almost weekly, while domestic accelerators differ in microarchitecture, memory hierarchy, and low-level instruction sets, so each backend needs its own operator implementations, compilation path, and performance tuning. If application teams carry all of this work, effort is repeatedly burned on isomorphic labor: the same attention variant, the same class of normalization and quantization operators must be rewritten, retested, and retuned across more than twenty backends.

    This gap determines that a commercial team’s real competitive edge is not “how many cards we support” but “how fast we can land a new model stably on heterogeneous compute while keeping unit cost predictable.”

    5. The Approach: A Unified System Software Stack as a Shared Foundation

    The converging industry practice is to adopt an open-source unified system software stack that turns the heaviest, most repetitive low-level work into shared assets. A mature foundation typically provides three layers of capability:

    1. Unified operator layer: built on a high-performance operator template ecosystem, accumulating over a thousand general-purpose operators that cover high-frequency patterns such as attention, normalization, quantization, MoE routing, and communication, implemented once and reused across backends;
    2. Unified compilation layer: a single repository manages backends from multiple chip vendors, connecting mainstream inference and training frameworks directly to heterogeneous compute and hiding instruction-set differences;
    3. Progressive abstraction layer: a ladder of abstractions descending from high-level frameworks to low-level kernels, letting teams descend as needed instead of facing bare hardware all at once.

    For a Token factory, this foundation turns “adaptation” from a one-off project expense into a reusable production-line capability.

    6. The Hidden Barrier to Letting AI Optimize AI: Sparse Search Spaces

    Using auto-tuning, or even AI-generated operators, to squeeze out hardware performance is key to raising the line’s ceiling, but there is a commonly ignored prerequisite: the algorithm must first “understand” the infrastructure. Exposing the raw hardware instruction space directly to a tuning algorithm looks maximally flexible, yet the search space is extremely sparse—a slight parameter deviation triggers illegal instructions, precision anomalies, or performance cliffs, so most sampled points are invalid solutions and the search struggles to converge on a robust one.

    Standardized compilers, progressive abstraction, and a rigorously validated unified operator ecosystem effectively lay a high-determinism middle layer above bare hardware: illegal combinations are rejected at compile time, candidate solutions naturally fall in the runnable range, and the density of valid feasible solutions rises sharply, turning tuning from “blind search” into “near-neighbor refinement.” The engineering payoff shows up in three places: lower tuning time, reproducible results, and no need to redo the search when migrating across backends.

    1. # Pseudocode: constrained auto-tuning on a unified foundation
    2. autotune --kernel attention_paged \
    3. --backends auto \
    4. --search-space constrained \ # illegal combinations pruned by the compilation layer
    5. --metric "throughput@p99<300ms" \
    6. --cache reuse # reuse historical best configurations

    It is worth stressing that even if operators are eventually generated autonomously by AI, the value of a shared foundation will not weaken but will stand out more as a “verifiable engineering anchor”: it supplies constraints, validation, and reuse—the three things that decide whether auto-generated results can go to production.

    7. Rollout Path and Common Cloud Capabilities

    A four-step rollout is recommended, each with quantifiable acceptance criteria:

    1. Baseline measurement: fix the model and dataset, record throughput, P99, cost per token, and effective utilization as a reference;
    2. Bottleneck localization: use monitoring, alerting, and log services to connect full-link tracing and distinguish compute-bound, bandwidth-bound, and communication-bound cases;
    3. Foundation integration: let the unified operator and unified compilation layers absorb adaptation, keeping only differentiating policies on the application side;
    4. Closed-loop tuning: chain auto-tuning, configuration caching, and canary release into a loop, so each model iteration requires only incremental validation.

    Common cloud capability categories fill in the line’s periphery: container platforms for elastic scaling and canary rollout, object storage for models and datasets, message queues for peak shaving, log services plus monitoring and alerting for observability, and gateways for rate limiting and multi-tenant isolation. In scenarios like these, Baidu AI Cloud is typically used to provide heterogeneous compute resource pools and general engineering capabilities related to inference acceleration, helping teams focus on the model and business strategy itself.

    8. Conclusion

    Competition in LLM commercialization in the domestic chip era is shifting from “who owns more compute” to “who can reliably convert compute into billable tokens.” Hardware mismatch, two-phase resource contention, and the software gap between weekly model iteration and heterogeneous chips are three stacked real constraints. Only a unified system software stack as a shared foundation—combined with a standardized operator ecosystem, constrained auto-tuning, and common cloud capabilities—can raise tuning efficiency and effective utilization at the same time, putting cost per token on a sustainably declining path.