LLM Inference on Heterogeneous Compute: A Practical Adaptation Guide
This article explains how to adapt large model inference across different accelerators without rewriting the model for every chip. It defines what a complete adaptation must satisfy, then walks through a unified operator layer, precision conversion paths, parallelism and KV-cache strategies for limited VRAM, the system requirements introduced by long-context architectures, and a four-layer validation and rollout process. The goal is stable contracts for operators, precision, parallelism, and evaluation, so a new accelerator mainly requires a new backend rather than a new model branch.
Large model inference is moving from “runs on a few high-end accelerator cards” to “must run on many kinds of compute, run stably, and stay maintainable.” Large parameter counts, long context lengths, and low-precision weights tend to arrive together: the model is bigger and the sequences are longer, while on-site VRAM, interconnect bandwidth, and numeric format support are inconsistent. If every new chip means rewriting a set of kernels, revising the parallel strategy, and manually re-checking accuracy, the delivery schedule collapses under hardware differences. The more reliable approach is to converge those differences into a single software stack, keeping model structure, weight semantics, and evaluation criteria unchanged, and making only the operator, compilation, precision, and parallelism layers replaceable.
Define the adaptation boundary first
Adaptation is not just copying weight files to a new machine and getting a few tokens out. At minimum, four things must hold at the same time.
First, consistent compute semantics. The numeric definitions of matmul, normalization, rotary position embedding, attention, activations, and residual connections must not be rewritten per chip, otherwise benchmark scores and business results are not comparable.
Second, resources must actually fit. KV caches for long contexts, expert routing, or large hidden dimensions can saturate VRAM and bandwidth. “It barely runs on a high-end card” does not count as a completed adaptation.
Third, the precision path must be explainable. The low-bit weights used during training or release are not necessarily natively supported by the target chip. Any conversion must state the rounding method, the scaling granularity, and which layers stay at higher precision.
Fourth, it must be regression-testable. The same prompts, the same decoding configuration, and the same stop conditions must allow comparison of loss ranges, sampling consistency, and latency breakdown across chips, rather than only confirming that “the service came up.”
A practical split is five stages: operator replacement, precision conversion, parallel partitioning, long-context scheduling, and end-to-end acceptance. Give each stage inputs, outputs, and failure criteria so that late-stage problems can still be localized.
Absorb hardware differences with a unified operator layer
Different accelerator cards have different instruction sets, tensor cores, memory hierarchies, and collective communication, but the set of operator types in the model graph is relatively stable. Replacing key operators in the original implementation with an operator library that offers “one interface, multiple backends” is the highest-leverage step in multi-chip adaptation.
The interface layer should fix tensor layout, data types, reduction dimensions, whether the operation is in-place, and how unaligned lengths are handled. The backend layer then maps to each chip’s matmul, vector instructions, or runtime graph. This way model code avoids large amounts of conditional branching, and adding a chip mainly means adding a backend rather than changing the network structure.
In practice, prioritize operators with high compute share and high numerical sensitivity: large matmuls, attention (including variants), normalization, gated activations, and indexing/routing. For memory-bound small operators, if fusion gains exceed the benefit of hand-writing, leave fusion and memory planning to the compiler to reduce intermediate tensor round-trips.
Unified does not mean forcing a lowest common denominator. When a chip lacks a certain low-precision matmul instruction, the backend should fall back to a supported precision and log the reason; do not scatter chip checks through business code. Compilation caches and the search space for kernel autotuning should also be isolated per chip, so the optimal block size on chip A is not applied to chip B.
A hardware-agnostic call site can stay simple:
y = gemm(x, w, out_dtype=bf16, accum=fp32)attn = attention(q, k, v, mask, kv_layout="paged")
The real differences live in the backend registered at runtime. What regression compares is output error and performance counters, not whether the kernel source is identical.
Precision: from lower bit widths to formats the hardware can run
Inference weights in common use come in 4-bit, 8-bit, or 16-bit floating-point/integer formats. The problem is that lower bit widths are often natively supported only on newer high-end cards, while many already-deployed chips stably support only 8-bit or 16-bit. If the deployment plan is hard-bound to the lowest bit width, the model cannot enter the mainstream compute pool.
Engineering-wise, separate “release precision” from “runtime precision.” Weight files should retain traceable scale factors, group sizes, and outlier handling; at load time, choose a path based on target chip capability, for example dequantizing low-bit weights to 8-bit before compute, or promoting directly to 16-bit. Accumulation and normalization generally stay at higher precision to avoid error amplification in deep layers.
Mixed precision is not arbitrary layer-by-layer downgrading. A more reasonable strategy is:
- Keep higher precision for numerically sensitive normalization, residual scaling, and routing gates;
- Use lower precision for compute-heavy projection matrices, within the error budget;
- Keep the scaling before the attention softmax consistent with the scaling of queries and keys, to prevent overflow or all-zero results;
- After conversion, check per-layer relative error on a small calibration batch, rather than only checking whether the final text “looks fine.”
The error budget must be written down in advance. For example, if per-layer relative error exceeds a threshold, fall back that layer’s precision instead of applying one rule to the whole model. Conversion must also handle the data type and broadcast rules of the scale factors themselves; if group quantization is mistakenly treated as per-tensor scaling, systematic bias appears on long sequences.
Documentation should retain three paths: native low precision, promote to 8-bit, and promote to 16-bit. The online default should be the best value-for-money path that the target chip stably supports and that stays within the error budget, with fallback allowed per request or per model version. After hardware generations change, lower precision can be re-enabled without touching business interfaces.
Parallelism for low VRAM: adding cards is not the answer
With large parameters and long contexts, single-card VRAM usually runs out before compute does. Data parallelism raises throughput but does not reduce the VRAM of a single replica. Tensor parallelism, pipeline parallelism, and expert parallelism can split weights or activations, at the cost of communication and load balancing.
An easily overlooked point: not all parameter groups should use the same partitioning. Embeddings, the output head, certain attention groups, or routing parameters have access patterns different from the main body weights. Forcing them onto the same parallel dimension as the body causes duplicated storage, non-divisible shapes, or collective communication deadlock. Giving such parameter groups an independent tensor parallel strategy often unlocks a batch of configurations that “look like they have enough VRAM but won’t start”: split body weights along the hidden dimension, vocabulary-related parameters along the vocabulary dimension, and cache along sequence or batch.
When partitioning, check three things. Whether the dimension divides evenly, and whether padding is removed before reduction when it does not. Whether the semantics of communication primitives on the target chip match the mathematical definition, especially the effect of reduction order on floating-point results. Whether the system can shrink to a smaller parallel degree and keep serving on failure, instead of taking the whole group down.
For long contexts, the KV cache usually consumes more VRAM than the weights. Paged cache, prefix reuse, and per-request budget eviction are more effective than blindly increasing batch size. The budget must constrain input length, generation length, and concurrency together; their product is the cache ceiling. Raising only “max context” without limiting concurrency means the service gets its cache exhausted at peak.
System requirements from long-context architectures
To cut the compute and cache cost of million-token contexts, two model-side techniques are common: hybrid attention, where some layers do sparser or more compressed history access while others keep denser local precision; and improved cross-layer signal propagation, which reduces gradient or residual information decay in very deep networks. For the inference system, these structures mean attention is no longer a single kernel.
During adaptation, split the different attention paths into independently testable operators, and verify masks, windows, compressed states, and cache layout separately. If compressed state cannot be paged, long requests fragment contiguous VRAM. The scheduler should account for and queue by each request’s real attention pattern, rather than estimating a uniform “same cost per token,” otherwise the gains from sparse layers are eaten by a wrong batching strategy.
Optimizers, training-stage alignment, and distillation affect whether the weights themselves are good; the inference side does not need to reproduce training, but it must ensure that the chat template, stop tokens, and tool-call format produced by post-training parse identically on every chip. Format inconsistency creates the illusion of “degraded model capability” when in fact the template or special tokens are being truncated incorrectly.
Validation, performance, and rollout
Acceptance is best done in four layers, from fast to slow.
Operator layer: with fixed small inputs, compare max error and mean squared error against a reference implementation, covering boundary lengths, all-masked cases, and empty batches.
Module layer: run a single attention layer, a full block, and vocabulary projection separately, which makes it easier to tell a numerical problem from a partitioning problem.
Model layer: with a fixed random seed and decoding parameters, compare answer agreement on a set of public or internal tasks; also record first-token latency, decode throughput, peak VRAM, and communication share.
Business layer: replay with the real length distribution and observe timeouts, rejection rate, and cache hits. Do not use only short sentences to represent long context in load tests.
Performance comparisons must use the same precision path, the same parallel degree, and the same batching strategy. Different absolute latency between chips is normal; more useful metrics are whether error against the reference stays within budget, whether VRAM grows linearly or sub-linearly with sequence length, and whether service quality after failure fallback is predictable.
The rollout configuration should state explicitly: runtime precision, parallel degree, max concurrency, max context, cache page size, and the fallback switches for precision or parallelism failures. Monitoring should cover at least VRAM watermark, cache hit rate, communication wait, numerical alerts, and request queue depth. When widespread garbled or repeated output appears, suspect masks, scaling, and stop tokens first, rather than immediately concluding that “the chip can’t run large models.”
Suggested order of work
Teams can proceed in this order, avoiding a full-chip, extreme-low-precision goal from day one.
- Fix reference results and error thresholds on one mature backend.
- Replace hot operators through the unified operator interface, ensuring correctness before fusion.
- Enable the 8-bit and 16-bit runtime paths, and confirm that low-bit weights can be promoted in an explainable way.
- Design separate partitioning for vocabulary, cache, and body weights, and find the minimum configuration that starts on moderate VRAM.
- Validate the cache layout and scheduling cost of hybrid attention with real long sequences.
- Fix fallback, monitoring, and the regression set into the release process, then extend to more chips.
The key to multi-chip availability is not maintaining a model branch per hardware, but giving operators, precision, parallelism, and evaluation stable contracts. Once the contracts are clear, onboarding a new card mainly means adding a backend and re-tuning, while the model and business interfaces stay unchanged. That is how heterogeneous compute turns from “the demo runs” into operable inference capability: short migration paths, explainable numeric behavior, and manageable boundaries for VRAM and long context.
