LLM Inference Frameworks: Model Compatibility and Quantization in Practice

    This article presents a reusable engineering methodology for LLM inference frameworks across four dimensions: model architecture support, weight format compatibility, quantization and export, and tool calling. It explains how to handle both dense and Mixture-of-Experts (MoE) models, how to load heterogeneous weight sources through a decoupled loader, why quantized files without structural metadata require an explicit source configuration directory, and how mixed-precision export balances memory usage against output quality. It also covers the tool-calling execution chain, practical deployment recommendations, and common pitfalls such as skipping business-specific regression tests before launch.

    1. Introduction: The Core Value of an Inference Framework Is “Compatibility” and “Controllability”

    In enterprise LLM deployments, training and inference are two entirely different technical tracks. Training focuses on convergence speed and memory throughput, while inference focuses on loading convenience, memory footprint, time to first token, and output stability. A mature inference framework typically has to solve three problems at once: supporting mainstream model architectures as broadly as possible; accommodating weight files from different sources and different numerical precisions as flexibly as possible; and providing a simple, unified calling interface so that upper-layer applications do not need to write branching logic for every model.

    This article takes a general technical perspective and covers four dimensions: model architecture support, weight format compatibility, quantization and export, and tool calling (function calling). The goal is a reusable engineering methodology.

    2. Model Architecture Support: Dense Models and Mixture-of-Experts Models

    2.1 Dense Models

    In a dense model, the feed-forward network in every layer is fully activated for all input tokens, and all parameters participate in every forward pass. The advantages are a deterministic compute path, simple operator implementations, and relatively predictable memory bandwidth requirements. The drawback is that as the parameter count grows, compute and memory usage grow linearly with it. Common small and mid-sized dense structures in the industry (roughly the 7B to 30B range) are widely used in device-side and single-GPU scenarios.

    2.2 Mixture-of-Experts (MoE) Models

    A Mixture-of-Experts model replaces the feed-forward layer with multiple “expert” subnetworks, and a gating network selects a small number of experts to participate in the computation for each token. Its defining characteristic is a large total parameter count with a small number of activated parameters per pass, which yields greater model capacity for the same inference compute. Engineering-wise, three things need extra attention:

    • Routing balance: uneven expert load leaves some devices idle while overloading others.
    • Weight size: all expert weights must either stay resident in memory or be swapped in and out on demand.
    • Operator support: grouped or batched expert computation, and the kernel efficiency of sparse activation, directly determine throughput.

    For an inference framework to support both dense and MoE models, it must introduce an abstraction layer at the operator level, changing the definition of a “layer” from a fixed structure to a configurable one, and use a unified configuration to describe hyperparameters such as the number of layers, attention heads, total experts, and activated experts.

    3. Weight Format Compatibility: From Original Precision to a Unified Intermediate Representation

    In real projects, model sources are highly heterogeneous. The common ones are:

    1. Original high-precision weights: FP16 and BF16. FP16 has a smaller dynamic range and can overflow in some training-unstable scenarios. BF16 has the same exponent bits as FP32, is numerically more robust, and is a common choice for training and high-precision inference.
    2. FP8 weights: a lower bit width traded for memory and bandwidth gains. FP8 requires hardware and operator support and is typically used together with per-tensor or per-channel scaling factors.
    3. Quantized weight formats: for example, weight-only quantization schemes that keep INT4/INT8 weights while computing activations in FP16. Memory usage drops significantly and the accuracy loss stays controllable.
    4. Framework-native formats: weights packaged together with the compute graph and metadata, which load faster and carry fewer dependencies.
    5. General-purpose quantization intermediate formats: quantization files widely circulated in the ecosystem, which usually embed metadata such as tensor names, quantization types, and block alignment sizes.

    One point deserves special attention: some general-purpose quantization files contain only tensor data and carry no model architecture hyperparameters. In that case, the loader must be pointed at the original model’s configuration directory to fill in structural information such as layer count, vocabulary size, and normalization scheme; otherwise the compute graph cannot be built correctly. In practice this is usually done with one explicit parameter, for example:

    1. # When loading general-purpose quantized weights, additionally specify the original model config directory
    2. infer --model quantized.bin --source-config /path/to/base_model_config

    This “weights and configuration separated” design is essentially a decoupling of structural description from parameter values, allowing one loader to serve multiple sources.

    4. Quantization and Export: Dynamic Quantization and Mixed Precision

    4.1 Where Dynamic Quantization Fits

    Dynamic quantization determines scaling factors from the distribution of each weight tensor itself and maps floating-point weights to lower-bit-width integers, without retraining and without a calibration set. Its advantage is a very short pipeline that can be automated and produced in batches. The cost is the absence of activation-side calibration, so accuracy is usually slightly worse than static quantization, though for most generation tasks it remains within an acceptable range.

    4.2 Mixed-Precision Export

    For MoE structures, a one-size-fits-all quantization strategy is not optimal: attention and shared layers are relatively sensitive to precision, while expert layers are numerous and the least friendly to memory. The export step therefore typically allows specifying a target precision per module, for example keeping sensitive layers at higher precision while giving expert layers a lower bit width, balancing memory footprint against output quality. The common approach is to control this uniformly through a data type parameter:

    1. # Export a dynamically quantized model and assign a lower bit width to the expert portion
    2. export --input base_model --output model_q4 --quant-type dynamic --moe-data-type int4

    4.3 Notes on Using Exported Models

    Exported artifacts already embed quantization metadata and the structural description, so the precision parameter no longer needs to be specified at inference time and will be ignored. The calling convention stays the same as for the original model; only the model path differs. This is very friendly for engineering integration: upper-layer services do not need two separate code paths for “original model” and “quantized model.”

    For obtaining models, the framework’s built-in download subcommand usually handles it, pulling from a model repository and verifying file integrity, which avoids errors from manually assembling multiple shards:

    1. ftllm download --model <model_name> --output ./models

    5. Tool Calling: Moving Models from “Talking” to “Doing”

    Tool calling (function calling) is the key bridge for bringing LLMs into business systems. The runtime chain generally has four steps:

    1. Tool declaration: a structured schema describing the tool name, purpose, parameter types, and required fields.
    2. Model decision: the model outputs a structured call request based on user intent, rather than natural language.
    3. Host execution: the application side parses the arguments, completes authentication and idempotency checks, and then actually executes.
    4. Result feedback: the execution result is handed back to the model as a new context fragment to generate the final response.

    There are two common implementation routes. The prompt template route constrains the output format through special markers and a parser; it offers good compatibility and low migration cost. The native tool calling route has the inference framework constrain the syntax directly during decoding; output is more stable but requires joint support from both the model and the framework. With either route, it is recommended to:

    • Apply strict type and range validation to arguments, and never concatenate them directly into execution.
    • Set timeouts, retries, and rate limits for tools so that a mistaken model call does not amplify a failure.
    • Keep complete call trace logs for retrospection and evaluation.

    An illustrative call protocol looks like this:

    1. {
    2. "tool": "query_order",
    3. "arguments": { "order_id": "A20240521", "need_detail": true }
    4. }

    6. Deployment Recommendations and Common Pitfalls

    • Precision choice: prefer BF16 when memory is plentiful; choose weight-only quantization when memory is tight; evaluate FP8 when latency-sensitive and the hardware supports it.
    • Format unification: fix one native packaging format within the team as the release artifact to reduce environment differences.
    • Configuration completion: when using quantization files that lack structural information, always specify the source config directory explicitly.
    • Export reproducibility: record the export command, quantization type, and mixed-precision strategy in configuration management to guarantee reproducibility.
    • Capability boundaries: quantization introduces quality variance, so a regression run on your own business evaluation set is required before launch, rather than relying only on general leaderboards.
    • Observability: combine logging services with monitoring and alerting, and build baseline dashboards for time to first token, throughput, and peak memory usage.

    7. Conclusion

    The competitiveness of an inference framework ultimately shows up in the product of three factors: breadth of compatibility × simplicity of invocation × controllability of resources. Abstracting architecture support into configurable structures, unifying weight sources into a decoupled loading flow, turning quantization export into a reproducible pipeline, and constraining tool calling into a verifiable structured protocol is what makes it possible to quickly stand up a stable, portable LLM inference foundation, whether in a cloud environment such as Baidu AI Cloud or in a purely local deployment.