FP8+Int4 Mixed-Precision Quantization Inference on Domestic AI Chips: A Deployment Practice

    This article presents an engineering practice for deploying FP8+Int4 mixed-precision quantized inference on domestic AI chips. It explains why reducing weight size is the primary lever for lowering per-token inference cost, how FP8 and Int4 are assigned according to layer sensitivity, and a six-stage workflow covering baseline creation, layer-wise sensitivity analysis, declarative configuration, calibration, operator and kernel adaptation, and serving. It also describes a three-layer precision validation method and common deployment pitfalls, with the goal of building a reproducible, measurable, and rollback-capable pipeline that balances cost reduction and precision stability.

    1. The Starting Point: Where Inference Costs Actually Go

    Once large models enter scaled service, the cost structure shifts fundamentally: training is a one-time investment, while inference is an ongoing expense. The cost per token consists of three parts: compute overhead, memory capacity overhead, and memory bandwidth overhead. During autoregressive decoding, every generated token requires moving all weights from memory to the compute units once. Therefore, weight size directly determines memory traffic, and memory traffic directly determines the concurrency a single card can support.

    This explains a conclusion that is often overlooked: the most effective lever for reducing inference cost is not increasing the batch size, but making the weights smaller. Moving weights from FP16 to Int4 reduces their size by four times, lowers both memory footprint and memory traffic, and multiplies the number of concurrent requests a single card can serve. The fixed cost allocated to each token then decreases. The value of mixed quantization lies precisely in finding the engineering optimum between “as small as possible” and “no precision collapse.”

    2. Why FP8 and Int4 Together, Not a Single Precision

    Lower-bit quantization is not a case of the more aggressive, the better. Different layers vary greatly in sensitivity to quantization error:

    • Attention and normalization-related computations, as well as output projection layers: their numerical distributions have a large dynamic range and contain outliers, so low-bit quantization causes noticeable precision loss.
    • Large matrix multiplications in feed-forward networks: these account for the highest proportion of parameters and have relatively stable distributions, making them the part with the largest compression benefit and the least precision sensitivity.
    • Activations: the per-token dynamic range is much larger than that of weights, so activations usually require higher precision than weights.

    The division of labor between FP8 and Int4 corresponds directly to this difference. FP8 has exponent bits and a wide dynamic range, making it suitable for tensors sensitive to outliers. Int4 has high storage density, making it suitable for very large weight matrices. By mixing the two, the strategy preserves precision in sensitive places and compresses size in redundant places.

    It is important to emphasize that mixed quantization is not a matter of arbitrarily assigning which precision to which layer. It is a data-driven sensitivity search problem.

    3. Implementation Path: A Six-Stage Engineering Loop

    Stage 1: Establish a Precision Baseline

    Any quantization work must first have a reproducible FP16/BF16 baseline. The baseline is not just an overall score. It should fix the evaluation set and sampling parameters, perplexity or task accuracy, pass rates for long-context and structured output such as JSON mode, and several manually constructed edge cases. Without this step, all later judgments that “precision has not changed” are subjective.

    Stage 2: Layer-by-Layer Sensitivity Analysis

    Conduct replacement experiments layer by layer: quantize a single layer while keeping the others at high precision, observe the metric shift, and obtain a sensitivity ranking for each layer. In practice, second-order information such as a Hessian diagonal approximation, or a simpler proxy such as the cosine similarity between outputs before and after quantization, is often used because it costs less.

    Stage 3: Generate a Mixed-Precision Configuration

    Divide layers into three tiers: keep at higher precision, 8-bit floating point, and 4-bit integer. The configuration itself should be a versionable declarative file rather than constants scattered through code:

    1. # Illustrative configuration, not an interface for any specific product
    2. quant_policy:
    3. default: fp8_e4m3
    4. overrides:
    5. - match: "layer_norm.*"
    6. dtype: keep_high_precision
    7. - match: ".*attention.*proj"
    8. dtype: fp8_e4m3
    9. - match: ".*ffn.*"
    10. dtype: int4
    11. group_size: 128
    12. symmetric: true
    13. activation:
    14. dtype: fp8_e4m3
    15. granularity: per_token

    Stage 4: Calibration

    4-bit quantization is extremely sensitive to calibration data. Key points include: the calibration set must cover the real business distribution in terms of length, language, and domain; the sample size should be sufficient but not unnecessarily large; per-channel or group-wise quantization should be used to limit error propagation; and outlier channels should be preserved or smoothed. Calibration is a one-time offline task, and its output is a quantization parameter table delivered together with the model.

    Stage 5: Operator and Kernel Adaptation

    This is the step most likely to become a bottleneck when deploying on domestic AI chips. The actual benefit of mixed quantization depends on whether efficient low-bit general matrix multiplication kernels exist and whether dequantization operators can be fused with adjacent operators. Without fusion, dequantization degenerates into standalone memory reads and writes, and the benefit is consumed by memory traffic. The recommended engineering order is: first map the model computation graph and mark all quantization/dequantization boundaries; then confirm the operator support matrix of the target chip; for unsupported operators, fall back to higher precision rather than forcing simulation.

    Stage 6: Serving and Delivery

    Package the quantized model as an inference service, with a request routing and batching scheduler in front to aggregate concurrent requests into effective batches. Use a container platform to host multiple versions for canary releases, and use logging and monitoring/alerting to track first-token latency, throughput, memory watermark, and error rate. During the canary phase, make sure the quantized version and the baseline version handle real traffic in parallel for online comparison, rather than relying only on offline evaluation.

    4. Precision Validation: Making “Unchanged” Measurable

    “Precision unchanged” must be translated into thresholds. A three-layer validation approach is recommended:

    1. Distribution layer: KL divergence of the logits distribution for the same input before and after quantization, and Top-1 agreement rate.
    2. Task layer: drift in standard evaluation set metrics does not exceed a predefined tolerance.
    3. Business layer: business metrics such as structured output parsing success rate, long-context consistency, and refusal rate do not degrade.

    Illustrative validation code:

    1. # Illustrative pseudocode
    2. def validate(quant_model, base_model, samples, tol=1e-2):
    3. report = {}
    4. for name, metric in METRICS.items():
    5. base = evaluate(base_model, samples, metric)
    6. quant = evaluate(quant_model, samples, metric)
    7. drift = abs(base - quant) / max(abs(base), 1e-6)
    8. report[name] = {"base": base, "quant": quant, "drift": drift}
    9. assert drift <= tol, f"{name} precision drift exceeds limit: {drift}"
    10. return report

    5. Common Pitfalls

    • Compressing only weights and ignoring activations: when activations remain at high precision, memory traffic benefits are largely offset.
    • Calibration set does not match the business distribution: a typical cause of good offline metrics but poor online experience.
    • Ignoring long-tail operators: a small number of unsupported operators may force the entire pipeline to fall back.
    • Lack of a rollback mechanism: without a parallel baseline during canary release, problems cannot be quickly isolated.
    • Treating quantization as a one-time script: after model iteration, the configuration is not synchronized, and precision silently degrades.

    6. Summary

    The core of achieving low-cost inference on domestic AI chips is not finding some “magic precision,” but establishing a reproducible, measurable, and rollback-capable engineering pipeline. It uses memory traffic and memory footprint as the main cost line, layer-wise sensitivity analysis as the basis for decisions, FP8 for sensitive tensors and Int4 for large-volume weights, operator fusion to determine actual benefit, and three-layer validation to defend the precision floor. Once this pipeline works, the model and the chip are delivered as an integrated system. Lower cost per token and stable precision are no longer contradictory; they become two sides of the same engineering method.