How mit-han-lab/smoothquant works
Project Overview and Purpose
• The project is focused on post‐training quantization of LLMs. It provides a training‐free method—“SmoothQuant”—that migrates activation outliers to weights, enabling an INT8 quantization of both activations and weights. This offers significant speedups and memory reductions.
• Key use cases include integrating with PyTorch (with support for CUTLASS INT8 GEMM kernels via torch‐int), and deployment into production frameworks such as FasterTransformer, NVIDIA TensorRT‐LLM, ONNX Runtime, Amazon SageMaker, and Intel Neural Compressor.
Analyzing the File Structure
• Top-Level Components:
– The root includes project meta files (LICENSE, README.md, setup.py) and auxiliary directories.
– The smoothquant/ directory contains the core library code: modules for calibration, quantization (“smooth.py”), fake quantization simulation (“fake_quant.py”), the OPT-specific quantization wrapper (“opt.py”), and perplexity evaluation (“ppl_eval.py”).
– The act_scales/ directory holds precomputed activation scales for various models.
– The examples/ directory features demonstration scripts and notebooks that illustrate key usage scenarios (e.g., generating activation scales, exporting INT8 models, and evaluating performance on OPT and Llama models).
– The assets/ and figures/ directories contain presentation material (PDF slides and architecture/accuracy figures), which are useful for understanding the methodology.
Main Components
• Pre-trained LLM Input:
– Represent the starting LLM models (e.g., OPT, Llama, Falcon) that will be quantized.
• Calibration / Activation Scale Generation:
– Include a component that represents scripts like generate_act_scales.py and the act_scales data. This stage collects calibration data (using datasets like Pile validation data) to compute activation channel scales.
• SmoothQuant Core Transformation:
– The heart of the system lives in the smoothquant/ directory.
▪ The “smooth” module: Applies the mathematically equivalent transformation shifting quantization difficulty from activations to weights.
▪ The “calibration” module: Handles calibration related processes where activation statistics are used.
▪ The “fake_quant” module: Simulates INT8 inference using FP16 so that performance and accuracy can be compared.
▪ The “opt” module: Implements INT8 optimized inference for the OPT model via custom PyTorch modules (that depend on torch-int and CUTLASS kernels).
▪ The “ppl_eval” module: Provides evaluation of language modeling perplexity applying quantization.
• External Dependencies and Integrations:
– Include integration points with external tools such as PyTorch, torch-int (for INT8 GEMM kernels via CUTLASS), FasterTransformer, TensorRT-LLM, ONNX Runtime, and others as noted in the README.