Engineering Production-Grade AI Inference on Domestic Accelerators
This article explains how to turn model inference from a working demo into a production service on domestic AI accelerators. It covers layered architecture, request governance, dynamic and continuous batching, model hot updates, cache isolation, heterogeneous resource abstraction, observability, capacity and cost, and security—plus a reproducible request-handling sketch and rollout metrics.
Engineering Production-Grade AI Inference on Domestic Accelerators
1. Background: production inference is more than “the model runs”
When inference service code that has already carried large-scale live traffic is published, its value is not just another sample. It turns single-node experiments into engineering assets for a production system. Loading a model and returning one request only proves basic function. Serving commercial traffic also requires answers to engineering questions: how to rate-limit and queue at peaks, how to control tail latency, how to batch for throughput without sacrificing fairness, how to hot-swap and roll back model versions, how to isolate and evict caches, how to abstract and fail over heterogeneous accelerators, how to locate faults, and how to account for cost.
Peak FLOPS on a single card may still lag in the short term. Production inference is not a contest of one peak number. It is stability, latency distribution, throughput efficiency, utilization, cost control, and operability. A reproducible production-grade reference implementation lowers the cost of teams learning from scratch and gives domestic accelerators an engineering baseline to take commercial traffic. A reference is not the end: teams still need an adaptation layer, governance, and an operations loop around their own workloads.
2. Layered architecture
Split a production inference service into six layers so ingress, scheduling, execution, and operations are not coupled in one process.
- Ingress: authentication, quotas, rate limits, request validation, timeouts, protocol conversion, and canary routing.
- Scheduler: queues, priority, fairness, dynamic batching, deadline control, and backpressure.
- Inference execution: model load, batch execution, cache management, operator calls, precision policy, and fault isolation.
- Resources: heterogeneous accelerators, general-purpose CPUs, memory, storage, and network, hidden behind a unified resource abstraction.
- Observability and governance: metrics, logs, traces, alerts, audit, and capacity watermarks.
- Data and cache: model registry, config center, object storage, message queues, and cache services.
The goal is not extra complexity. It is controlled change: ingress policy changes do not touch execution; model versions can canary and roll back; resource failures can be isolated; observability can drive capacity planning.
3. Key engineering practices
3.1 Request governance and backpressure
Production traffic is bursty and uneven. Ingress should apply tenant- and model-level limits and distinguish interactive online, batch offline, and high-priority work. The scheduler should track queue depth and apply backpressure when queues exceed a threshold instead of growing without bound. Timeout budgets should propagate from the edge so downstream work stops after the client has already timed out. Retries need budgets and backoff so retry storms do not amplify failures. Circuit breaking and degradation should cover model unavailability, accelerator faults, and dependency timeouts. Tenant fairness matters: one tenant’s bulk traffic must not starve others’ online requests.
3.2 Dynamic and continuous batching
Batching is the main lever for throughput, but larger is not always better. The scheduler should jointly consider max batch size, max token budget, request deadlines, priority, and wait time. Online traffic cares about tail latency; offline jobs care about throughput. Isolate queues and assign weights for mixed serving. Continuous batching can admit new requests mid-execution, but must handle cache lifetime and fairness. Abstracted control flow:
while service_running:batch = select_ready(queues,max_batch_size,max_token_budget,deadline_policy,fairness_policy)if batch.is_empty():wait_or_evict_idle_cache()continueresult = execute_batch(batch)update_metrics(batch, result)release_or_retain_cache(batch)
Scheduling policy should be configurable, observable, and roll-backable. Changes to batch size or queue weights should go through load tests and canaries.
3.3 Model versions and hot updates
Do not replace models by taking the service down. Keep version metadata, adapter config, and checks in a model registry. The execution layer can preload and switch with double buffering. Send a new version to a small canary first, split by tenant, scenario, or request share; expand only after latency, error rate, and resource watermarks look healthy. Validate rollback in advance: old versions still load, caches remain compatible, config is reversible. Watch memory fragmentation and when the old version is freed so a switch does not double memory and cause OOM.
3.4 Cache and state
Caches include prefix cache, session state, and intermediate results. They cut repeated work but need tenant isolation, lifetime, eviction, and consistency. Isolate prefix cache by tenant and model version to avoid cross-tenant leakage. Session stickiness needs TTLs so resources are not held forever. Cache hit rate is a core metric, but do not keep large amounts of useless entries to inflate it. Evict using recency, resource cost, and request priority—not a single dimension.
3.5 Heterogeneous resource abstraction
On domestic accelerators, drivers, runtimes, compilers, operator libraries, and inference engines often differ. Build a unified resource layer for device discovery, allocation, model load, operator invocation, and recovery. Maintain an operator coverage matrix: which model structures run natively, which fall back to CPU, which need precision policy changes. Fallbacks need expected performance and alerts so silent degradation does not hide latency regressions. Isolate faults to a card or instance so they do not cascade across the cluster.
3.6 Observability
Production services must be observable. Core metrics include request rate, error rate, P99 latency, queue length, batch-size distribution, cache hit rate, utilization, model-load time, and rollback count. Structure logs; traces should span ingress, scheduling, execution, and cache access. Grade alerts for capacity watermarks, error spikes, tail-latency degradation, and resource faults. Error budgets can decide whether to pause releases. Optimization without metrics is untrustworthy; releases without rollback signals are uncontrolled.
3.7 Capacity and cost
Plan capacity from load-test models, not guesswork. Tests should cover single requests, mixed load, bursts, long context, failed retries, and model switches. Autoscale on queue length, resource watermarks, and predicted traffic—not only CPU or accelerator utilization. Mixed serving improves efficiency if isolation and priority protect online traffic from offline jobs. Cost should allocate by tenant, model, and business line to drive quotas and capacity work.
3.8 Security and compliance
Enforce tenant isolation, least privilege, redaction of sensitive data, and audit logs. Restrict access to model files, config, and cache. Verify integrity of models and dependencies in the supply chain. Keep approval and audit records for releases. In multi-tenant setups, cache and resource isolation are especially important to reduce leakage via side channels or error messages.
4. Reproducible request-handling sketch
def handle_request(request):identity = authenticate(request)if not identity.valid:return reject(401, "unauthorized")quota = check_quota(identity.tenant, request.model)if not quota.allow:return reject(429, "quota_exceeded")if not validate(request):return reject(400, "invalid_request")plan = route(model=request.model,tenant=identity.tenant,priority=request.priority,deadline=request.deadline)ticket = scheduler.submit(plan, request)return stream_response(ticket)
Three principles: authenticate and check quota at the edge; route and allocate budget before scheduling; return results asynchronously via a ticket. Production code still needs timeout cancellation, retry budgets, and metric instrumentation.
5. Rollout path and evaluation metrics
Use shadow traffic, small canaries, per-tenant canaries, then full rollout. Each stage needs a load-test baseline, dashboards, and a rollback plan. Metrics should at least cover availability, P99 latency, throughput, error rate, cache hit rate, utilization, cost per request, and rollback success rate. Common mistakes: looking only at peak compute, load-testing without observing, unbounded batches, unisolated caches, no operator coverage matrix, and releases without rollback. A public production-grade reference shortens the start; whether you can take commercial traffic depends on continuous governance and operations around it.
