Registry / llm-agents / llmcompressor

llmcompressor

JSON →
library0.12.0pypypiunverified

LLM Compressor (current version 0.10.0.1) is a Python library for compressing large language models, offering both training-aware and post-training techniques. Built on PyTorch and HuggingFace Transformers, it provides a flexible and user-friendly interface for researchers and practitioners to quickly experiment with techniques like quantization and sparsity. The library maintains an active development pace with frequent patch releases and regular feature updates.

pip install llmcompressor
INSTALL
IMPORT
SIG · LLMCOMPRESSOR
L
llmcompressor
llm-agentspythonv0.12.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
timeout
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AutoModelForCausalLM
from llmcompressor.models import AutoModelForCausalLM
QuantizationModifier
from llmcompressor.modifiers import QuantizationModifier
SparseMLRecipe
from llmcompressor.recipes import SparseMLRecipe
Compressor
from llmcompressor.compression import Compressor
AutoTokenizer
from transformers import AutoTokenizer
Required for model tokenization, part of HuggingFace Transformers.

This quickstart demonstrates how to initialize `llmcompressor` for a simple post-training quantization (PTQ) workflow. It involves loading a Hugging Face model, defining a compression recipe in YAML, and setting up the `Compressor`. For actual PTQ, a calibration dataloader is required when calling `compressor.compress()`.

from transformers import AutoTokenizer from llmcompressor.models import AutoModelForCausalLM from llmcompressor.recipes import SparseMLRecipe from llmcompressor.compression import Compressor import torch # 1. Load a pre-trained model and tokenizer model_name = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForCausalLM.from_pretrained(model_name) # 2. Define a compression recipe (e.g., for 8-bit quantization) # This YAML describes a simple post-training quantization (PTQ) modifier. # For full functionality, specific targets and calibration data would be needed. recipe_yaml = """ quantization_modifiers: - !QuantizationModifier start: 0.0 scheme_args: num_bits: 8 symmetric: False per_channel: True """ # 3. Parse the recipe recipe = SparseMLRecipe.parse_yaml(recipe_yaml) # 4. Create a Compressor instance # The model will be modified in-place when compression is applied. # For PTQ, a calibration dataloader is typically required for `compressor.compress()`. compressor = Compressor(recipe=recipe, model=model, tokenizer=tokenizer) # 5. Apply compression (requires calibration data for true PTQ) print("Compressor initialized. To apply compression with Post-Training Quantization (PTQ),") print("you would typically call: compressor.compress(dataloader=your_calibration_dataloader)") print("For this quickstart, we've demonstrated the setup without running full PTQ.") # Example of saving (after actual compression) # compressor.save_compressed_model("path/to/save/compressed_model")
Debug
Known issues
gotchaLLM Compressor frequently updates its dependency on `compressed-tensors`. Mismatched versions between `llmcompressor` and `compressed-tensors` can lead to runtime errors or unexpected behavior.
fix
Always ensure `llmcompressor` and its dependencies are up-to-date, or explicitly install compatible versions. Refer to the GitHub releases for specific `compressed-tensors` versions used in each `llmcompressor` release.
affects: All versions
gotchaMany advanced compression techniques, especially certain quantization methods, are highly optimized for or require specific hardware (e.g., NVIDIA GPUs with CUDA). Running on CPU may lead to significantly slower performance or limited feature availability.
fix
Ensure you have a CUDA-enabled GPU and a PyTorch installation compiled with CUDA support for optimal performance. Check documentation for specific hardware requirements for desired modifiers.
affects: All versions
gotchaFor Post-Training Quantization (PTQ), the `compressor.compress()` method typically requires a representative calibration dataloader to collect statistics about activations. Omitting this can result in errors or poor quantization quality.
fix
Always provide a `dataloader` argument to `compressor.compress()` when performing PTQ to enable proper calibration. Refer to examples for how to prepare a calibration dataloader.
affects: All versions
Upgrade
Version history
0.12.0latest on PyPI · released Jun 15, 2026
Audit
Dependencies
torchrequiredCore deep learning framework dependency.
transformersrequiredIntegration with HuggingFace models and utilities.
sparseml.corerequiredUnderlying core compression framework logic.
sparseml.pytorchrequiredPyTorch-specific components for compression.
compressed-tensorsrequiredOptimized tensor representations for compressed models, frequently updated.
autoroundoptionalAdvanced rounding-based quantization algorithm. Requires x86_64.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
llmcompressor — pip install llmcompressor · libregistry