Quantization in Machine Learning and Large Language Models
Last Updated on January 3, 2025 by Editorial Team
Author(s): ANSHUL SHIVHARE
Originally published on Towards AI.
This member-only story is on us. Upgrade to access all of Medium.
Quantization is a powerful technique in machine learning aimed at reducing the computational and memory requirements of models. This makes them highly efficient for deployment, especially on resource-constrained devices like mobile phones, IoT devices, and edge servers. By representing model weights and activations with lower precision data types, such as 16-bit floats or 8-bit integers, quantization enables faster inference and smaller model sizes. However, this optimization comes with a tradeoff: a potential loss of precision that can impact model performance.
In this blog, weβll dive deep into the different types of quantization, their significance, and practical examples to illustrate how they work. Numerical demonstrations are also included for better clarity.
Dynamic quantization is a straightforward method applied after training. Here, model weights are pre-quantized, and activations are quantized dynamically during inference. This is done just before computation, converting activations into int8 format for efficient matrix multiplications.
Significance:
It accelerates computations due to the reduced precision of int8 operations.Maintains a good balance between model accuracy and performance.Easy to implement without requiring model retraining.Weights (original):W=[0.156,β0.783,0.243] (32-bit floats)Quantization (int8):Using a scale S=0.01,W_quantized= round(W/S)=[16,β78,24]Reconstruction:W_reconstructed= SΓ W_quantized= [0.16,β0.78,0.24]
Example:
Consider a language model used for text classification. By dynamically quantizing… Read the full blog for free on Medium.
Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming aΒ sponsor.
Published via Towards AI