Intermediate2h20m

Quantization in Depth

Instructors: Marc Sun, Younes Belkada

Hugging Face logo

Earn an accomplishment with PRO · Updated Oct 7, 2025

  • Intermediate
  • 2h20m
  • 18 Video Lessons
  • 13 Code Examples
  • 1 Graded Assignment PRO
  • Earn an accomplishment with PRO
  • Updated Oct 7, 2025
  • Instructors: Marc Sun, Younes Belkada
  • Hugging FaceHugging Face
  • Learn more aboutMembership PRO Plan

What you'll learn

  • Try out different variants of Linear Quantization, including symmetric vs. asymmetric mode, and different granularities like per tensor, per channel, and per group quantization.

  • Build a general-purpose quantizer in Pytorch that can quantize the dense layers of any open source model for up to 4x compression on dense layers.

  • Implement weights packing to pack four 2-bit weights into a single 8-bit integer.

Course recap

PRO

This advanced course builds on Quantization Fundamentals to implement quantization primitives from scratch. Students implement symmetric and asymmetric linear quantization at different granularities (per-tensor, per-channel, per-group), build a custom model quantizer, and tackle challenges of extreme low-bit quantization including weight packing for 2-bit and 4-bit precision.

Concept map

Concepts in Quantization in Depth and the courses that connect to themQuantization in DepthSymmetric vs. asymmetric quantizationSymmetric vs. asymmetric…Per-tensor quantizationPer-channel quantizationPer-group quantizationWeight packingQuantizationQuantization FundamentalsPretraining LLMsAI Coding Workflows From Cloud to LocalAI Coding Workflows From…Building Adaptive AI AgentsBuilding Adaptive AI Agen…Concepts in Quantization in Depth and the courses that connect to themQuantization in DepthQuantization in…Symmetric vs. asymmetric quantizationSymmetric vs. a…Per-tensor quantizationPer-tensor quan…Per-channel quantizationPer-channel qua…Per-group quantizationPer-group quant…Weight packingQuantization

Key concepts

  • Symmetric vs. asymmetric quantizationSymmetric maps [-r_max, r_max] to [-q_max, q_max] (no zero-point needed); asymmetric maps [r_min, r_max] to [q_min, q_max]
  • Per-tensor quantizationSingle scale for entire weight tensor; simplest but least accurate
  • Per-channel quantizationSeparate scale per output channel; better accuracy for varied weight distributions
  • Per-group quantizationSeparate scale per group of weights within a channel; best accuracy, most overhead
  • Weight packingStoring sub-byte weights (2-bit, 4-bit) packed into higher-precision containers (INT8, INT32) since PyTorch lacks native support
  • QuantizationDeep implementation of linear quantization scale/zero-point formulas

About this course

In Quantization in Depth you will build model quantization methods to shrink model weights to ¼ their original size, and apply methods to maintain the compressed model’s performance. Your ability to quantize your models can make them more accessible, and also faster at inference time.

Implement and customize linear quantization from scratch so that you can study the tradeoff between space and performance, and then build a general-purpose quantizer in PyTorch that can quantize any open source model. You’ll implement techniques to compress model weights from 32 bits to 8 bits and even 2 bits.

Join this course to:

  • Build and customize linear quantization functions, choosing between two “modes”: asymmetric and symmetric; and three granularities: per-tensor, per-channel, and per-group quantization.
  • Measure the quantization error of each of these options as you balance the performance and space tradeoffs for each option.
  • Build your own quantizer in PyTorch, to quantize any open source model’s dense layers from 32 bits to 8 bits.
  • Go beyond 8 bits, and pack four 2-bit weights into one 8-bit integer.

Quantization in Depth lets you build and customize your own linear quantizer from scratch, going beyond standard open source libraries such as PyTorch and Quanto, which are covered in the short course Quantization Fundamentals, also by Hugging Face.

This course gives you the foundation to study more advanced quantization methods, some of which are recommended at the end of the course.

Who should join?

Building on the concepts introduced in Quantization Fundamentals with Hugging Face, this course will help deepen your understanding of linear quantization methods. If you’re looking to go further into quantization, this course is the perfect next step.

Course Outline

18 Lessons・13 Code Examples
Unlock certificates

Elevate your learning experience with Pro

Upgrade to Pro and gain unlimited accomplishments on your resume

Learn More

Instructors

Marc Sun

Marc Sun

Machine Learning Engineer at Hugging Face

Younes Belkada

Younes Belkada

Machine Learning Engineer at Hugging Face

Course access is free for a limited time during the DeepLearning.AI learning platform beta!

Want to learn more about Generative AI?

Keep learning with updates on curated AI news, courses, and events, as well as Andrew’s thoughts from DeepLearning.AI!