In this tutorial, we explore how to apply post-training quantization to an instruction-tuned language model using llmcompressor. We start with an FP16 baseline and then compare multiple compression strategies, including FP8 dynamic quantization, GPTQ W4A16, and SmoothQuant with GPTQ W8A8. Along the way, we benchmark each model variant for disk size, generation latency, throughput, perplexity, and output quality. We also prepare a reusable calibration dataset, save compressed model artifacts, and inspect how each recipe changes practical inference behavior. By the end, we get a practical understanding of how different quantization methods affect model efficiency, deployment readiness, and performance trade-offs.
We install all required libraries, import the core packages, and verify that a CUDA-enabled GPU is available. We define the base Qwen2.5 instruction model, create a working directory, and prepare helper functions for memory cleanup, model size calculation, generation timing, and perplexity evaluation. We also create a reusable benchmark function that loads any model variant, tests its generation speed, calculates perplexity, and stores the results for final comparison.
We first benchmark the original FP16 model to establish a reliable baseline for subsequent comparisons. We then apply FP8 dynamic quantization using llmcompressor, where linear layers are compressed while the language modeling head remains in higher precision. We save the compressed FP8 model and run the same benchmark again to compare its size, latency, throughput, and perplexity against the baseline.
We build a small calibration dataset using UltraChat samples so that the calibrated quantization recipes can observe realistic instruction-style inputs. We convert each chat example into model-compatible text through the tokenizer's chat template. We then tokenize the samples with a fixed maximum sequence length, creating a reusable dataset for GPTQ and SmoothQuant-based compression.
We apply GPTQ quantization with W4A16 scheme (4-bit weights, 16-bit activations) using a group size of 128. This significantly reduces model size and speeds up inference, albeit with a modest increase in perplexity. Finally, we apply SmoothQuant with GPTQ W8A8 (8-bit weights and activations) to further optimize for throughput while maintaining quality. Each variant is benchmarked and compared.