compressed-tensors 0.19.0


pip install compressed-tensors

  Latest version

Released: Sep 21, 2026

Project Links

Meta
Author: The vLLM Project

Classifiers

compressed-tensors

The compressed-tensors library extends the safetensors format, providing a versatile and efficient way to store and manage compressed tensor data. This library supports various compression schemes, making it a unified format for handling models compressed with algorithms like GPTQ, AWQ, SmoothQuant, and SparseGPT, across formats like INT8, FP8, NVFP4, MXFP4, MXFP8, and more.

Why compressed-tensors?

As model compression becomes increasingly important for efficient deployment of LLMs, the landscape of quantization and compression techniques has become increasingly fragmented. Each method often comes with its own storage format and loading procedures, making it challenging to work with multiple techniques or switch between them. compressed-tensors addresses this by providing a single, extensible format that can represent a wide variety of compression schemes.

  • Unified Checkpoint Format: Supports various compression schemes in a single, consistent format.
  • Wide Compatibility: Works with popular quantization methods like GPTQ, SmoothQuant, AWQ, AutoRound, etc. See llm-compressor
  • Flexible Quantization Support:
    • Activation quantization
    • Mixed precision
    • Low/arbitrary-bit
    • KV cache quantization
    • Non-uniform schemes (different layers can be quantized in different ways!)
  • Sparsity Support: Handles both unstructured and semi-structured (e.g., 2:4) sparsity patterns.
  • Transform Support: Rotation-based quantization techniques (Hadamard, random Hadamard, random matrix transforms).
  • Checkpoint Conversion: Convert between formats like AutoAWQ, ModelOpt NVFP4, FP8 block, and compressed-tensors.
  • Model Offloading: Transparent CPU/disk/distributed offloading for models larger than available VRAM.
  • Open-Source Integration: Designed to work seamlessly with Hugging Face models, PyTorch, vLLM, and SGLang.

This allows developers and researchers to easily experiment with composing different quantization methods, simplify model deployment pipelines, and reduce the overhead of supporting multiple compression formats in inference engines.

Installation

From PyPI

Stable release:

pip install compressed-tensors

Nightly release:

pip install --pre compressed-tensors

From Source

git clone https://github.com/vllm-project/compressed-tensors
cd compressed-tensors
pip install -e .

Development

Install the development dependencies and run the linting, formatting, and type checks:

pip install -e .[dev]
make quality   # check
make style     # auto-fix

Pre-commit Hooks

We provide pre-commit hooks that run the same checks as make quality (plus a DCO sign-off hook) before each commit, so problems are caught locally instead of in CI. After installing the [dev] dependencies, enable them once per clone:

pre-commit install

The hooks then run automatically on git commit. To run them against all files on demand:

pre-commit run --all-files

To bypass the hooks for a single commit, use git commit --no-verify; to skip one hook, prefix the command with SKIP=<hook-id> (e.g. SKIP=flake8).

Getting Started

Compressing a Model to MXFP4

The following example loads Llama 3 8B, applies round-to-nearest (RTN) MXFP4 weight quantization, compresses the weights, and saves the result. No calibration data is needed — scales are computed directly from the weights.

model_name = "meta-llama/Meta-Llama-3-8B"
device = "cuda:0" if torch.cuda.is_available() else "cpu"

# Load the model
model = AutoModelForCausalLM.from_pretrained(
    model_name, device_map=device, torch_dtype="auto"
)

# Set-up the quantization config. This defines:
# 1. What quantization scheme we're applying and to which layers
# 2. Any layers that should be ignored
# In this case, all the Linear layers are targeted, apart from the lm_head
config = QuantizationConfig(
    config_groups={"MXFP4": ["Linear"]},
    ignore=["lm_head"],
)
# Apply the config to the model. This step uses the config to define
# the quantization parameters (such as the scales) for the targeted layers
# and attaches a QuantizationScheme which defines how the weights and activations
# should be quantized (e.g number of bits, group or block sizes, etc)
apply_quantization_config(model, config)

# Compute weight scales using round-to-nearest quantization
for name, module in model.named_modules():
    # Only target layers with a QuantizationScheme attached
    scheme = getattr(module, "quantization_scheme", None)
    if scheme is None or scheme.weights is None:
        continue

    weight = module.weight.data
    args = scheme.weights
    # MXFP4 uses group-wise quantization for its weights, with group_size 32
    group_size = args.group_size

    if group_size is not None and group_size > 0:
        reshaped = weight.unflatten(-1, (math.ceil(weight.shape[-1] / group_size), group_size))
        min_val = reshaped.amin(dim=-1)
        max_val = reshaped.amax(dim=-1)
    else:
        min_val, max_val = torch.aminmax(weight)

    # Calculate the quantization parameters, such as the weight scale, using the min and max values
    scale, _ = calculate_qparams(min_val, max_val, args)
    # Update the parameters attached to the module based on the calculated value
    # In this case, we update the `weight_scale` attached to the targeted linear layers
    update_offload_parameter(module, "weight_scale", scale)


output_dir = "./Meta-Llama-3-8B-MXFP4"
# set-up a compressor 
compressor = ModelCompressor.from_pretrained_model(model)
# Compress the model using the calibrated scales and save it using the mxfp4-pack-quantized format.
# This format defines the weight packing, which can be seamlessly loaded through vLLM.
compressor.compress_model(model)
model.save_pretrained(output_dir)
# Update the model's config with the relevant compressed-tensors details, illustrated below. 
compressor.update_config(output_dir)

Once done, the config.json will have the following quantization_config:

"quantization_config": {
    "config_groups": {
      "group_0": {
        "format": "mxfp4-pack-quantized",
        "input_activations": {
          "actorder": null,
          "block_structure": null,
          "dynamic": true,
          "group_size": 32,
          "num_bits": 4,
          "observer": null,
          "observer_kwargs": {},
          "scale_dtype": "torch.uint8",
          "strategy": "group",
          "symmetric": true,
          "type": "float",
          "zp_dtype": null
        },
        "output_activations": null,
        "targets": [
          "Linear"
        ],
        "weights": {
          "actorder": null,
          "block_structure": null,
          "dynamic": false,
          "group_size": 32,
          "num_bits": 4,
          "observer": "memoryless_minmax",
          "observer_kwargs": {},
          "scale_dtype": "torch.uint8",
          "strategy": "group",
          "symmetric": true,
          "type": "float",
          "zp_dtype": null
        }
      }
    },
    "format": "mxfp4-pack-quantized",
    "global_compression_ratio": null,
    "ignore": [
      "lm_head"
    ],
    "kv_cache_scheme": null,
    "quant_method": "compressed-tensors",
    "quantization_status": "compressed",
    "sparsity_config": {},
    "transform_config": {},
    "version": "0.18.1.dev0+gac8e2ba.d20260813"
  },

See examples/ for more examples including quantization with calibration and checkpoint conversion (examples/convert_checkpoint/).

Citation

If you find compressed-tensors useful in your research or projects, please consider citing it:

@software{compressedtensors2024,
    title={{compressed-tensors}},
    author={Red Hat AI and vLLM Project},
    year={2024},
    month={4},
    url={https://github.com/vllm-project/compressed-tensors},
}
0.19.1a20260925 Sep 26, 2026
0.19.1a20260924 Sep 25, 2026
0.19.1a20260923 Sep 24, 2026
0.19.1a20260919 Sep 21, 2026
0.19.0 Sep 21, 2026
0.18.1a20260919 Sep 20, 2026
0.18.1a20260914 Sep 15, 2026
0.18.1a20260911 Sep 12, 2026
0.18.1a20260910 Sep 11, 2026
0.18.1a20260903 Sep 04, 2026
0.18.1a20260902 Sep 03, 2026
0.18.1a20260827 Aug 28, 2026
0.18.1a20260826 Aug 27, 2026
0.18.1a20260824 Aug 25, 2026
0.18.1a20260821 Aug 22, 2026
0.18.1a20260818 Aug 19, 2026
0.18.1a20260816 Aug 18, 2026
0.18.1a20260815 Aug 16, 2026
0.18.1a20260814 Aug 15, 2026
0.18.1a20260806 Aug 08, 2026
0.18.0 Aug 08, 2026
0.17.2a20260806 Aug 07, 2026
0.17.2a20260805 Aug 06, 2026
0.17.2a20260804 Aug 05, 2026
0.17.2a20260731 Aug 01, 2026
0.17.2a20260730 Jul 31, 2026
0.17.2a20260729 Jul 30, 2026
0.17.2a20260728 Jul 29, 2026
0.17.2a20260727 Jul 28, 2026
0.17.2a20260724 Jul 25, 2026
0.17.2a20260723 Jul 24, 2026
0.17.2a20260720 Jul 21, 2026
0.17.2a20260716 Jul 17, 2026
0.17.2a20260715 Jul 16, 2026
0.17.2a20260714 Jul 15, 2026
0.17.2a20260707 Jul 08, 2026
0.17.2a20260706 Jul 07, 2026
0.17.2a20260703 Jul 05, 2026
0.17.2a20260702 Jul 03, 2026
0.17.2a20260701 Jul 02, 2026
0.17.2a20260630 Jul 01, 2026
0.17.2a20260629 Jun 30, 2026
0.17.2a20260626 Jun 27, 2026
0.17.2a20260623 Jun 25, 2026
0.17.2a20260622 Jun 23, 2026
0.17.2a20260618 Jun 19, 2026
0.17.2a20260616 Jun 17, 2026
0.17.2a20260611 Jun 11, 2026
0.17.1 Jun 11, 2026
0.17.1a20260610 Jun 11, 2026
0.17.1a20260604 Jun 05, 2026
0.17.1a20260602 Jun 03, 2026
0.17.0 Jun 03, 2026
0.16.1a20260602 Jun 03, 2026
0.16.1a20260529 May 31, 2026
0.16.1a20260526 May 28, 2026
0.16.0 May 28, 2026
0.15.1a20260526 May 27, 2026
0.15.1a20260521 May 22, 2026
0.15.1a20260520 May 21, 2026
0.15.1a20260515 May 16, 2026
0.15.1a20260503 May 06, 2026
0.15.1a20260428 Apr 29, 2026
0.15.1a20260421 Apr 24, 2026
0.15.1a20260416 Apr 17, 2026
0.15.1a20260414 Apr 15, 2026
0.15.1a20260413 Apr 14, 2026
0.15.1a20260409 Apr 09, 2026
0.15.1a20260406 Apr 08, 2026
0.15.0.1 Apr 10, 2026
0.15.0 Apr 08, 2026
0.14.1a20260406 Apr 07, 2026
0.14.1a20260326 Mar 27, 2026
0.14.1a20260325 Mar 25, 2026
0.14.1a20260323 Mar 24, 2026
0.14.1a20260320 Mar 22, 2026
0.14.1a20260317 Mar 18, 2026
0.14.1a20260313 Mar 16, 2026
0.14.1a20260310 Mar 11, 2026
0.14.1a20260309 Mar 10, 2026
0.14.1a20260306 Mar 07, 2026
0.14.1a20260305 Mar 05, 2026
0.14.1a20260225 Feb 27, 2026
0.14.0.1 Mar 11, 2026
0.14.0 Feb 27, 2026
0.13.1a20260225 Feb 26, 2026
0.13.1a20260223 Feb 24, 2026
0.13.1a20260219 Feb 20, 2026
0.13.1a20260218 Feb 19, 2026
0.13.1a20260217 Feb 18, 2026
0.13.1a20260212 Feb 13, 2026
0.13.1a20260211 Feb 12, 2026
0.13.1a20260210 Feb 11, 2026
0.13.1a20260209 Feb 10, 2026
0.13.1a20260205 Feb 08, 2026
0.13.1a20260203 Feb 04, 2026
0.13.1a20260130 Jan 30, 2026
0.13.1a20260127 Jan 28, 2026
0.13.1a20260123 Jan 24, 2026
0.13.1a20260116 Jan 19, 2026
0.13.1a20260115 Jan 16, 2026
0.13.1a20260109 Jan 10, 2026
0.13.1a20260108 Jan 09, 2026
0.13.1a20251215 Dec 16, 2025
0.13.0 Dec 16, 2025
0.12.3a20251215 Dec 16, 2025
0.12.3a20251214 Dec 15, 2025
0.12.3a20251212 Dec 13, 2025
0.12.3a20251203 Dec 04, 2025
0.12.3a20251114 Nov 15, 2025
0.12.3a20251110 Nov 11, 2025
0.12.3a20251030 Nov 01, 2025
0.12.3a20251028 Oct 28, 2025
0.12.3a20251023 Oct 24, 2025
0.12.3a20251013 Oct 14, 2025
0.12.3a20251010 Oct 11, 2025
0.12.3a20251009 Oct 10, 2025
0.12.3a20251008 Oct 09, 2025
0.12.3a20251007 Oct 08, 2025
0.12.3a20251003 Oct 07, 2025
0.12.2 Oct 07, 2025
0.12.2a20251003 Oct 05, 2025
0.12.2a20251002 Oct 02, 2025
0.12.1 Oct 02, 2025
0.12.1a20251001 Oct 01, 2025
0.12.0 Oct 01, 2025
0.11.1a20250929 Sep 30, 2025
0.11.1a20250923 Sep 25, 2025
0.11.1a20250918 Sep 19, 2025
0.11.1a20250917 Sep 18, 2025
0.11.1a20250912 Sep 13, 2025
0.11.1a20250911 Sep 12, 2025
0.11.1a20250910 Sep 11, 2025
0.11.1a20250909 Sep 10, 2025
0.11.1a20250908 Sep 09, 2025
0.11.1a20250904 Sep 05, 2025
0.11.1a20250903 Sep 04, 2025
0.11.1a20250902 Sep 03, 2025
0.11.1a20250828 Aug 29, 2025
0.11.1a20250821 Aug 22, 2025
0.11.1a20250820 Aug 21, 2025
0.11.1a20250819 Aug 19, 2025
0.11.0 Aug 19, 2025
0.10.3a20250815 Aug 16, 2025
0.10.3a20250814 Aug 15, 2025
0.10.3a20250812 Aug 13, 2025
0.10.3a20250811 Aug 12, 2025
0.10.3a20250806 Aug 08, 2025
0.10.3a20250805 Aug 06, 2025
0.10.3a20250731 Aug 01, 2025
0.10.3a20250728 Jul 29, 2025
0.10.3a20250724 Jul 25, 2025
0.10.3a20250721 Jul 22, 2025
0.10.3a20250716 Jul 17, 2025
0.10.3a20250715 Jul 16, 2025
0.10.3a20250711 Jul 12, 2025
0.10.3a20250710 Jul 11, 2025
0.10.3a20250709 Jul 10, 2025
0.10.3a20250708 Jul 09, 2025
0.10.3a20250707 Jul 08, 2025
0.10.3a20250703 Jul 04, 2025
0.10.3a20250701 Jul 03, 2025
0.10.3a20250620 Jun 24, 2025
0.10.2 Jun 23, 2025
0.10.2a20250620 Jun 21, 2025
0.10.2a20250617 Jun 18, 2025
0.10.2a20250616 Jun 17, 2025
0.10.2a20250613 Jun 14, 2025
0.10.2a20250612 Jun 13, 2025
0.10.2a20250611 Jun 12, 2025
0.10.2a20250609 Jun 10, 2025
0.10.2a20250606 Jun 06, 2025
0.10.1 Jun 06, 2025
0.10.1a20250605 Jun 06, 2025
0.10.1a20250604 Jun 05, 2025
0.10.0 Jun 05, 2025
0.9.5a20250604 Jun 05, 2025
0.9.5a20250603 Jun 04, 2025
0.9.5a20250602 Jun 03, 2025
0.9.5a20250530 May 31, 2025
0.9.5a20250528 May 29, 2025
0.9.5a20250521 May 22, 2025
0.9.5a20250520 May 21, 2025
0.9.5a20250519 May 20, 2025
0.9.5a20250514 May 15, 2025
0.9.5a20250513 May 14, 2025
0.9.5a20250512 May 13, 2025
0.9.5a20250509 May 10, 2025
0.9.5a20250507 May 08, 2025
0.9.5a20250502 May 03, 2025
0.9.5a20250428 Apr 29, 2025
0.9.5a20250425 Apr 28, 2025
0.9.5a20250424 Apr 25, 2025
0.9.4 Apr 24, 2025
0.9.4a20250421 Apr 23, 2025
0.9.4a20250414 Apr 15, 2025
0.9.4a20250412 Apr 12, 2025
0.9.4a20250410 Apr 11, 2025
0.9.4a20250408 Apr 09, 2025
0.9.3 Apr 02, 2025
0.9.2 Feb 18, 2025
0.9.1 Jan 23, 2025
0.9.0 Jan 15, 2025
0.8.1 Dec 11, 2024
0.8.0 Nov 12, 2024
0.7.1 Oct 17, 2024
0.7.0 Oct 09, 2024
0.6.0 Sep 23, 2024
0.5.0 Aug 08, 2024
0.4.0 Jun 21, 2024
0.3.3 May 07, 2024
0.3.2 Apr 29, 2024
0.3.1 Apr 25, 2024
0.3.0 Apr 25, 2024
Extras:
Dependencies:
torch (>=2.10.0)
transformers (>=4.45.0)
pydantic (>=2.0)
loguru
psutil