Inferflow: an Efficient and Highly Configurable Inference Engine for Large Language Models

Shuming Shi, Enbo Zhao, Deng Cai, Leyang Cui, Xinting Huang, Huayang LiarXiv 2024 · DOI

Abstract

Inferflow is an open-source, modular inference engine designed to simplify the deployment of Large Language Models (LLMs) through a zero-code configuration approach. By treating model architectures as compositions of atomic building blocks, Inferflow allows users to serve new models without modifying source code. The engine introduces a novel 3.5-bit quantization scheme that bridges the performance gap between 3-bit and 4-bit methods, and a hybrid partitioning strategy to optimize multi-GPU inference in bandwidth-constrained environments.

Introduction

The rapid evolution of Large Language Model (LLM) architectures has created a significant engineering burden. Most existing inference engines require "hard-coding" support for new models, necessitating manual implementation of specific normalization functions or attention mechanisms. Inferflow addresses this by providing a modular framework where new architectures can be defined via simple configuration files.

Overview of Inferflow's technologies and major concerns, highlighting its modular framework and quantization capabilities.

Methodology

Modular Framework of Atomic Building Blocks

Inferflow moves away from model-specific scripts (e.g., modeling_llama.py) in favor of "atomic" modules. These include standardized implementations of normalization functions (e.g., RMSNorm), activation functions (e.g., SwiGLU), and position embeddings (e.g., RoPE). Serving a new model involves specifying which blocks it utilizes in a JSON-like configuration file, enabling "compositional generalizability."

3.5-bit Quantization

To balance memory efficiency and model accuracy, Inferflow introduces a 3.5-bit quantization scheme. While standard 3-bit quantization uses 8 levels ($2^3$), Inferflow uses a 7-bit integer to represent two adjacent weights. This allows for $11 \times 11 = 121$ states (fitting within the 128 states of 7 bits), effectively providing 11 quantization levels per weight, or approximately 3.46 bits. This mathematical compromise aims to avoid the significant accuracy degradation often seen when dropping from 4-bit to 3-bit quantization.

Hybrid Model Partitioning

Traditional multi-GPU strategies often force a choice between high-latency pipeline parallelism and high-bandwidth tensor parallelism. Inferflow implements a hybrid approach that assigns specific layers and attention heads across devices. This strategy is particularly effective for hardware setups with lower interconnect speeds, balancing decoding speed and overall throughput.

Evaluation and Results

The engine's performance was evaluated using the Wikitext-2 dataset to measure perplexity across several models, including Bloom-3B, LLAMA2-7B/13B, and Falcon-40B.

Perplexity results across different quantization levels, demonstrating the performance of the 3.5-bit (Q3H) scheme.

Key Findings

  • Quantization Quality: Results on LLAMA2-13B demonstrate that the 3.5-bit (Q3H) scheme achieves a perplexity of 6.897. This is a marked improvement over the 7.278 recorded for 3-bit quantization and approaches the 4-bit baseline of 6.514.
  • Inference Efficiency: On a 4x NVIDIA Tesla V100 setup, the Hybrid Partitioning strategy achieved a throughput of 24 tokens/s. This significantly outperformed standard tensor-wise partitioning (12 tokens/s) and provided a superior balance compared to layer-wise partitioning, which suffered from low decoding speeds (8 tokens/s).
  • Security and Extensibility: Inferflow includes a custom C++ pickle parser to load PyTorch .bin files safely, avoiding the security risks of executing arbitrary Python code during model loading.

Conclusion

Inferflow demonstrates that LLM serving can be made both highly efficient and easily extensible through modular design and innovative quantization. By finding the "sweet spot" in bit-depth and optimizing multi-GPU communication, it provides a robust platform for deploying diverse model architectures. Future work will focus on integrating speculative decoding and automating the optimal assignment of layers in hybrid partitioning setups.

Summary updated

Abstract

We present Inferflow, an efficient and highly configurable inference engine for large language models (LLMs). With Inferflow, users can serve most of the common transformer models by simply modifying some lines in corresponding configuration files, without writing a single line of source code. Compared with most existing inference engines, Inferflow has some key features. First, by implementing a modular framework of atomic build-blocks and technologies, Inferflow is compositionally generalizable to new models. Second, 3.5-bit quantization is introduced in Inferflow as a tradeoff between 3-bit and 4-bit quantization. Third, hybrid model partitioning for multi-GPU inference is introduced in Inferflow to better balance inference speed and throughput than the existing partition-by-layer and partition-by-tensor strategies.
BibTeX
@misc{shi2024inferflow,
  author = {Shuming Shi and Enbo Zhao and Deng Cai and Leyang Cui and Xinting Huang and Huayang Li},
  title = {{Inferflow: an Efficient and Highly Configurable Inference Engine for Large Language Models}},
  year = {2024},
  eprint = {2401.08294},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.08294},
}
Figure