Leanpub Header

Skip to main content

LLM Quantization Recipes

A Practical Guide to Compressing Large Language Models Without Losing Their Intelligence

This book is 100% completeLast updated on 2026-07-13

LLMs are too big for single GPUs, but quantization fixes that. This book cuts through the hype to show you how to actually compress models using GPTQ, AWQ, GGUF, and NF4 without losing quality. You get real benchmarks, working code, and a clear way to pick the right tool for your hardware. Stop guessing and start deploying efficient models today.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
106
Pages
About

About

About the Book

Large language models have become too big to run on a single GPU. Quantization is the technology that makes them deployable, and it has evolved from an academic curiosity into an engineering discipline with its own algorithms, toolchains, and best practices. This book explains how LLM quantization works, from first principles through production deployment. You will learn the internals of GPTQ, AWQ, GGUF, NF4, and other methods; understand their trade-offs in quality, speed, and memory; and find clear guidance for choosing the right approach for your hardware and use case. Along the way you will encounter real benchmarks, reproducible code examples, and a decision framework for navigating one of the most rapidly evolving areas of applied machine learning.

Bundle

Bundles that include this book

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 400 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

A Practical Guide to Compressing Large Language Models Without Losing Their Intelligence

Introduction: Why Compress the Mind?

  1. What You Will Learn
  2. How This Book Is Organized
  3. Prerequisites

Chapter 1: The Compression Imperative

  1. The Size Explosion: From GPT-2 to Today
  2. Why Raw Parameters Are a Bottleneck
  3. What Quantization Actually Does
  4. A Brief History of Model Compression
  5. What This Book Covers (and Does Not)

Chapter 2: Foundations of Numerical Precision in Deep Learning

  1. Floating-Point Arithmetic: FP32, FP16, BF16
  2. Integer Representations: INT8, INT4, INT2
  3. Mixed Precision and the NF4 Format
  4. How GPUs and CPUs Handle Different Datatypes
  5. The Information Theory of Weight Distributions

Chapter 3: Post-Training Quantization vs. Quantization-Aware Training

  1. Post-Training Quantization (PTQ): The Quick Path
  2. Quantization-Aware Training (QAT): The Careful Path
  3. Weight-Only Quantization: The LLM Sweet Spot
  4. Activation Quantization and the Outlier Problem
  5. Hybrid Approaches and Per-Token Strategies

Chapter 4: Calibration – Teaching Precision to Models

  1. The Role of Calibration Data
  2. Min-Max vs. Percentile Clipping
  3. Moving Average and Histogram-Based Methods
  4. Optimal Perceptual Quantization (OPQ)
  5. How Much Calibration Data Do You Really Need?

Chapter 5: GPTQ – Greedy One-Shot Quantization

  1. The Hessian Approximation Idea
  2. Layer-by-Layer Greedy Optimization
  3. The GPTQ Algorithm Step by Step
  4. AutoGPTQ: The Practical Implementation
  5. Strengths, Limitations, and Typical Results
  6. Mathematical Derivation: Why the Hessian Works
  7. Complete Production GPTQ Quantization Script
  8. Production Readiness Checklist for GPTQ

Chapter 6: AWQ – Activation-Aware Weight Quantization

  1. The Activation Magnitude Insight
  2. Weight Scaling Before Quantization
  3. The AWQ Algorithm: Smoothing and Rescaling
  4. AWQ vs. GPTQ: A Head-to-Head Comparison
  5. Practical Usage with AutoAWQ
  6. Complete Production AWQ Quantization Script
  7. Production Readiness Checklist for AWQ
  8. Case Study: Deploying a 70B Model on a Single A100

Chapter 7: GGUF and the llama.cpp Ecosystem

  1. The GGML Legacy and GGUF’s Design
  2. K-Quants: Q4_0, Q4_K_S, Q5_K_M, Q8_0
  3. How llama.cpp Runs Quantized Models on CPU
  4. Performance on CPUs vs. GPUs with Metal/Vulkan
  5. Community Toolchains and Model Hubs
  6. Importance Matrix (imatrix) Quantization: A Deep Dive
  7. Complete GGUF Conversion Pipeline

Chapter 8: BitsAndBytes and the NF4 Revolution

  1. The bitsandbytes Library Architecture
  2. NormalFloat4: Why It Beats Plain INT4
  3. QLoRA: Fine-Tuning in 4 Bits
  4. 8-Bit Adam and Optimizer Quantization
  5. Practical Usage with the Transformers Library
  6. Complete Production QLoRA Fine-Tuning Script
  7. Production Readiness Checklist for QLoRA

Chapter 9: Unsloth – Speed Through Quantized Fine-Tuning

  1. The Fine-Tuning Bottleneck
  2. Unsloth’s Architecture and Optimizations
  3. Patched Transformers: How the Speedup Works
  4. Benchmarks: Unsloth vs. Standard QLoRA
  5. Practical Usage and Limitations

Chapter 10: Advanced Frameworks – Bartowski, ByteShape, and Apex

  1. Bartowski’s Quantization Pipeline
  2. ByteShape: Understanding This Approach
  3. NVIDIA Apex: From Mixed-Precision Training to FP8
  4. Other Notable Methods: SmoothQuant, ZeroQuant, SPA
  5. The Fragmentation Problem in Toolchains

Chapter 11: Deployment Scenarios and Hardware Considerations

  1. Local Inference on Consumer GPUs
  2. CPU-Only Deployment and Edge Devices
  3. High-Throughput Server Serving
  4. Mobile and On-Device LLMs
  5. Case Study: Deploying a Customer Support Chatbot on a Single GPU
  6. The Memory Bandwidth Bottleneck

Chapter 12: Benchmarking, Best Practices, and Decision Framework

  1. A Reproducible Benchmarking Protocol
  2. How to Measure Quantization Quality
  3. Perplexity, Accuracy, and Latency Benchmarks
  4. Common Pitfalls and Debugging Tips
  5. The Quantization Decision Framework
  6. Future Directions: What’s Next in Model Compression

Conclusion: The Democratized Model

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub