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-03

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
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.

Share this book

Bundle

Bundles that include this book

Author

About the Author

Steve T. Publications

Steve T. is a cybersecurity leader, researcher, and engineer with more than 20 years of experience across application security, infrastructure security, vulnerability management, software development, and secure engineering practices. Having built his career alongside the growth of the modern internet, he has worked through multiple generations of technology, evolving security threats, and changing development methodologies.

He is currently part of the advanced research organization at a leading cybersecurity company, where he focuses on emerging threats, security innovation, and the practical application of research. His work involves investigating new attack techniques, evaluating emerging technologies, conducting deep technical analysis, and helping organizations better understand and manage complex security risks.

In addition to his research responsibilities, Steve leads a team of senior engineers and subject matter experts who create technical books, training programs, and educational resources for security professionals. Through this work, he helps engineers, developers, architects, and security practitioners strengthen their skills and build more secure systems.

Steve's technical expertise spans software development, reverse engineering, web application security, penetration testing, security architecture, incident response, vulnerability research, operating system internals, and secure software development. His ability to analyze systems at both the source code and binary levels enables him to bridge the worlds of software engineering, security research, and practical defense.

Over the course of his career, Steve has worked with organizations across a wide range of industries, helping them identify, assess, and remediate security weaknesses in critical applications and infrastructure. He is recognized for combining deep technical expertise with a pragmatic approach to security, focusing on solutions that are effective, sustainable, and aligned with business goals.

Through his work in research, engineering, leadership, and education, Steve continues to contribute to the advancement of cybersecurity and the development of secure, resilient technology systems.

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