New Tool Radar

AI Concepts

How to Use an Importance Matrix with Calibration Text for Quantization

Use an importance matrix from calibration text when you quantize below 4 bits, so the weights that matter most keep more precision.

Schematic illustration of use an importance matrix with calibration text for quantization: step one pick calibration text, step two build the matrix, step three quantize with it.

The i-quants, such as IQ4_XS, are built for low bit rates and work best with an importance matrix: a measurement of which weights matter most, taken from a sample of calibration text. Without that measurement, a low-bit quant treats all weights as equal and damages the important ones. With it, the important weights keep more precision and the rest can go lower.

Prerequisites

  • A model to quantize at a low bit rate, such as an IQ4 level.
  • Calibration text that matches the model’s real use: the same kind of documents it will read.
  • The llama.cpp quantize tool with imatrix support.

Steps

Step 1: Pick calibration text

Choose calibration text that matches what the model will actually do: code for a coding model, prose for a chat model. Mismatched calibration text measures the wrong weights as important.

Step 2: Build the matrix

Run the imatrix tool over the calibration text to produce the importance matrix. This step measures, for each weight, how much the model’s output changes when that weight is changed.

Step 3: Quantize with it

Run the quantizer with the importance matrix and your chosen IQ level. The quantizer then spends its limited bits where the matrix says they matter most.

Worked example: Cedar Street Library catalogue model

The fictional Cedar Street Library quantizes a small model for catalogue questions, using its own catalogue notes as calibration text.

Step Input Output
Calibration text Catalogue notes, plain text Sample of real use
Importance matrix Calibration text run Weight importance scores
Quantize IQ4_XS Matrix plus model Low-bit file, important weights protected

The IQ4_XS file is built with the importance matrix from catalogue notes, so the weights that matter for catalogue questions keep more precision.

Expected result. The low-bit file is produced with an importance matrix built from calibration text that matches the model’s real use. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • An importance matrix helps most below 4 bits; at Q4_K_M and above it matters less.
  • Calibration text that does not match real use can mislead the matrix.
  • This guide describes the workflow; it does not run the quantizer.

Sources

See all