Engineering Production-Grade LLM Inference on Domestic AI Accelerators
This article breaks down the engineering practices required to move large model inference on domestic compute platforms from "it runs" to production-grade service. It covers unit economics such as revenue per card-hour, cost per million tokens, and effective utilization; inference engine adaptation across operators, memory, and parallelism; quantization and precision trade-offs; service governance including SLA, elastic scaling, canary release, and fault isolation; and observability and capacity planning. Readers will find a transferable framework for delivering inference as a measurable, cost-accounted business.
1. The Real Problem: From “It Runs” to “Service at the Highest Standard”
Deploying large model inference on domestic compute platforms is no longer about whether a model can run. The question is whether it can keep serving external traffic at a production-grade standard. Recently published inference code and operating data from an open-source community have shifted the discussion back from compatibility to unit economics: under off-peak pricing, the amortized revenue per card per hour for two classes of accelerator cards is stated explicitly. This means inference can be treated as a business that must account for gross margin, utilization, and SLAs for the first time.
For developers and enterprise users, the pain points concentrate in three areas:
- Missing operators and performance regressions caused by hardware ecosystem differences;
- The tension between memory and throughput under long context and high concurrency;
- Metering, rate limiting, canary release, and fault isolation once the service is productized.
This article takes a neutral view of these problems and lays out a transferable set of engineering practices.
2. Unit Economics: Treating Inference as “Compute Retail”
The essence of off-peak pricing is peak shaving and valley filling. Training and batch jobs saturate the cluster during the day, leaving a window at night for online inference, so the same card generates different revenue at different times. Evaluating whether this model holds requires looking at three metrics together:
- Amortized revenue per card per hour: measures hardware monetization efficiency;
- Cost per million tokens: measures the economics of the model and quantization scheme;
- Effective utilization: the real busy ratio after deducting queuing, cold starts, and failed retries.
The illustrative accounting logic can be written as:
# Illustrative calculation only; not the billing rules of any specific productdef unit_economics(card_hour_revenue, tokens_per_second,concurrency, utilization, cost_per_card_hour):hourly_tokens = tokens_per_second * 3600 * utilizationrevenue_per_mtok = card_hour_revenue / (hourly_tokens / 1e6)gross_margin = (card_hour_revenue - cost_per_card_hour) / card_hour_revenuereturn {"revenue_per_mtok": round(revenue_per_mtok, 3),"gross_margin": round(gross_margin, 3),"effective_concurrency": concurrency * utilization,}
Key takeaway: the lever for improving gross margin is not “buying a more expensive card,” but raising effective utilization and per-card throughput, both of which are determined by the inference engine and scheduling strategy.
3. Inference Engine Adaptation: Operators, Memory, and Parallelism
Adapting to domestic accelerator cards usually falls into three layers:
- Operator layer. If high-frequency operators such as attention, normalization, and positional encoding lack high-performance implementations, fallback paths are triggered and performance can drop by several times. Engineering teams should maintain an operator coverage checklist and a benchmark suite, and turn the regression results of each upgrade into comparable data.
- Memory layer. The KV cache is the main consumer of GPU memory, and its footprint is roughly proportional to batch size, sequence length, and number of layers. Production environments should enable paged cache management and prefix reuse so that requests sharing the same system prompt hit the same cache.
- Parallelism layer. Tensor parallelism reduces per-card memory pressure but adds communication overhead; pipeline parallelism improves overall throughput but is sensitive to load balancing. A practical approach is to use tensor parallelism first to meet single-request latency, then add data parallelism to scale throughput.
A minimal server skeleton:
class InferenceWorker:def __init__(self, model, max_batch=32, max_seq_len=8192):self.model = modelself.max_batch = max_batchself.max_seq_len = max_seq_lendef build_batch(self, requests):# Continuous batching: new requests can be inserted during decoding to reduce idle waitingready = [r for r in requests if r["prompt_tokens"] <= self.max_seq_len]return ready[: self.max_batch]def generate(self, requests):batch = self.build_batch(requests)return self.model.forward_batch(batch)
4. Quantization and Precision: Balancing Cost and Latency
Weight quantization (typically 8-bit or lower integer quantization) significantly reduces memory footprint and improves bandwidth efficiency during decoding; KV cache quantization further expands capacity for long-context scenarios. The key to adoption is a tiered precision strategy: quantization can be aggressive for classification and extraction tasks, while higher precision should be preserved for sensitive tasks such as code generation and mathematical reasoning. Use a fixed evaluation set for per-version regression to avoid a situation where the average score stays flat but long-tail cases break.
5. Service Governance: SLAs, Elasticity, and Canary Release
Production-grade means making external commitments. Define two classes of metrics: latency metrics (time to first token and percentile values of end-to-end latency) and throughput metrics (output tokens per second and concurrency capacity). Build a governance loop around them:
- Admission control: rate limit based on queue length and memory watermark; reject fast rather than let requests queue indefinitely;
- Elastic scaling: trigger scale-out and scale-in on both in-flight request count and memory usage to avoid cold-start jitter;
- Canary release: route a small share of traffic to the new version first, compare percentile latency and error rate, then ramp up;
- Fault isolation: partition resource pools by model or tenant to prevent a single large request from bringing down the whole system.
6. Observability and Capacity Planning
Observability for inference services needs a request-level view rather than a process-level one: log input and output length, queue time, cache hit rate, and retry count for each request to locate long-tail behavior. For capacity planning, multiply the safe per-card throughput measured by load testing by the target utilization, then divide by peak QPS to get the required number of cards, and reserve some headroom for bursts.
7. Conclusion
As inference code for domestic compute reaches production grade, the competitive focus has shifted from hardware specifications to engineering maturity: operator coverage, cache management, quantization strategy, scheduling governance, and observability together determine whether a service can be delivered at the highest standard. Keeping revenue per card-hour, cost per million tokens, and effective utilization on the same dashboard and continuously optimizing them is the foundation on which this compute retail business holds up over the long term.
