Skip to content
Qubitium edited this page Dec 2, 2026 · 8 revisions

SINQ

🏠 Home · 🧭 Choose a method · 🚀 Quickstart · 🧰 Help

On this page

SINQ (Sinkhorn-normalized quantization) fits low-bit weights without calibration data by default. It balances the row and column scales of eligible weight tiles before fitting a uniform affine grid or an NF3/NF4 codebook. A-SINQ is the optional calibrated mode. Both modes use the same GPT-QModel checkpoint layout and inference backend.

Use GPTQModel.load for SINQ checkpoints. Plain Transformers warns about gptqmodel_sinq and leaves the quantized linear layers randomly initialized.

Quantize, save, and load

import torch
from gptqmodel import BACKEND, GPTQModel, SINQConfig

model = GPTQModel.load(
    "Qwen/Qwen3-0.6B",
    quantize_config=SINQConfig(device="cpu"),
    dtype=torch.bfloat16,
)
model.quantize()
model.save_quantized("Qwen3-0.6B-sinq")

quantized = GPTQModel.load(
    "Qwen3-0.6B-sinq",
    device="cpu",
    dtype=torch.bfloat16,
    backend=BACKEND.GPTQ_TORCH,
)

BACKEND.AUTO also selects SinqLinear for compatible SINQ checkpoints. The kernel supports BF16 and FP16 activations on CPU, NVIDIA CUDA, and AMD ROCm and returns the activation dtype.

With the uniform grid and 1D tiling, eligible inference calls reuse the Torch fused GEMV and small-batch GEMM paths on NVIDIA Ada and supported ROCm families. These paths consume packed weights directly. The Torch streaming path decodes a tile at a time. All three paths require the scaled weight to fit the activation dtype. The dense fallback uses a temporary weight decoded and scaled in the activation dtype when it fits, or an FP32/FP64 decode and reduction when it would overflow. The 2D uniform path uses a wide reduction, and NF3/NF4 use a Torch codebook gather.

Fused linear throughput

The benchmark compares a single SINQ linear forward with the Torch GPTQ fused forward on the same device and packed layout. It uses FP16 activations, 4-bit uniform 1D weights, group_size=128, and seven projection shapes. Each timing is the median of cold-cache runs. Ratios below 1× favor SINQ. The table includes shapes where both methods selected a fused kernel.

Device class Input rows SINQ / GPTQ latency range Median ratio
NVIDIA CUDA 1 0.93×–1.09× 1.02×
NVIDIA CUDA 8 1.02×–1.10× 1.04×
NVIDIA CUDA 32 1.00×–1.11× 1.06×
NVIDIA CUDA 64 0.97×–1.21× 1.05×
AMD ROCm 1 1.00×–1.04× 1.02×
AMD ROCm 8 1.14×–1.41× 1.25×

Single-row GEMV applies sinq_scale per input channel. Small-batch GEMM applies the scale per weight element during decode, which adds more work on the measured ROCm path. Fused eligibility depends on the device, input shape, and dtype, so use the benchmark to check which rows run fused on your device.

From the source checkout, run PYTHONPATH="$PWD" python scripts/benchmark_sinq_fused.py --device cuda:0. Use --batches for a comma-separated list of input row counts and --dtype to select float16 or bfloat16. Benchmark source · Reported results

A-SINQ with calibration

Set SINQConfig(awq=True) and pass representative samples in CalibrationConfig.dataset. Keep the default tiling_mode="1d" for A-SINQ. The calibration search cannot score 2D tiles when the column scales span multiple output-row blocks.

A-SINQ sets offload_to_disk=False and logs a warning if disk offload was enabled. Its calibration pre-pass forwards the full dense model, which must fit on the calibration device. Weight-only quantization then runs layer by layer. Plain SINQ keeps the default offload_to_disk=True. SINQ configuration

import torch
from gptqmodel import CalibrationConfig, GPTQModel, SINQConfig

# Replace calibration_texts with representative samples for your model.
model = GPTQModel.load(
    "Qwen/Qwen3-0.6B",
    quantize_config=SINQConfig(awq=True, device="cpu"),
    dtype=torch.bfloat16,
)
model.quantize(calibration=CalibrationConfig(dataset=calibration_texts))
model.save_quantized("Qwen3-0.6B-a-sinq")

The pre-pass captures linear inputs and scores AWQ-style per-input-channel scale candidates by reconstruction error on those inputs. When a candidate improves on plain SINQ, the quantizer folds the scale into the weight before fitting the low-bit grid, skips Sinkhorn for that module, and stores the inverse in sinq_scale. Modules that receive no usable activations or for which plain SINQ scores best keep the calibration-free path. Reload the saved model with GPTQModel.load as in the example above.

Configuration

Field Default Accepted values and behavior
bits 4 2, 3, 4, or 8. Two-bit is experimental and SINQConfig(bits=2) logs a warning. Prefer 4-bit for published checkpoints. Three-bit packing requires both input and output widths divisible by 32.
group_size 64 -1 for the full input width, or 8, 16, 32, 64, 128, 256, 512, or 1024. A trailing partial group is fitted separately.
sinkhorn_iters 16 Positive integer iteration limit. The normalization keeps the best balance found for each tile.
kurtosis_threshold 10.0 Positive finite value or None. A finite kurtosis at or below the threshold passes the gate. Set None to apply Sinkhorn to every tile on the plain SINQ path.
gate_scope "group" "group" checks tiles individually when the module fails the gate. "module" makes one decision for the entire module.
tiling_mode "1d" "1d" uses the full output width for each input-channel group. "2d" uses square tiles along both weight axes, with group_size as the tile width and height. Partial edge tiles are fitted separately.
codebook "uniform" "uniform" fits an asymmetric affine grid. "nf4" requires bits=4; "nf3" requires bits=3.
awq False Boolean. Set True for A-SINQ with CalibrationConfig.dataset.
awq_samples 16 Positive integer. Maximum number of prepared calibration batches used by A-SINQ. At batch_size=1 each batch contains one prepared sample.
awq_grid 20 Integer of at least 2. Number of A-SINQ scale candidates evaluated per target, in addition to plain SINQ.

On the plain SINQ path, both scopes apply Sinkhorn to all the tiles of a module that passes the gate. If it fails and gate_scope="group", the quantizer checks each tile in the selected geometry, including partial edge tiles. Tiles above the threshold or with non-finite kurtosis use the selected codebook without Sinkhorn and store a column multiplier of one. With codebook="uniform", this is plain asymmetric RTN. Set gate_scope="module" for one decision per module.

Try SINQConfig(bits=3, group_size=128, tiling_mode="2d") to compare square tiles against the 1D default on your model. The 2D tiling benchmark saw lower perplexity for both tested models at 3-bit with group size 128, mixed results at other settings, and 1.2× to 3.5× longer quantization times across the sweep.

QuantizeConfig(method="sinq", ...) also constructs a SINQConfig. SINQ uses torch.int32 packing, sym=False, and desc_act=False. It validates any supplied mse value before disabling MSE search. Per-module dynamic rules can set the group size or exclude modules. With the uniform grid, they can also select the bit width. Set the codebook and Sinkhorn controls on the run-level config. For example, use SINQConfig(bits=3, codebook="nf3") for NF3. See QuantizeConfig Reference.

Checkpoint layout and compatibility

Each quantized linear stores GPTQ-shaped qweight, qzeros, scales, and g_idx, plus a required sinq_scale tensor. In 1D mode its shape is [in_features]. In 2D mode its shape is [ceil(out_features / tile_size), in_features], with tile_size = group_size or in_features when group_size=-1. Each row of that tensor applies to its own output-row block. The row multiplier is folded into the stored group scales.

effective_weight = (codes - logical_zero_points) * group_scales * sinq_scale

With NF3 or NF4, qweight holds codebook indices and qzeros is a placeholder. The decoder looks up each index and subtracts the continuous shift from the required sinq_zero tensor before applying the group and column scales. Fresh checkpoints write sinq_zero as FP32, with one value per group and output channel. The reader also accepts finite FP16 or BF16 shifts. Saved config records codebook at the top level and under meta.weight_only. Older checkpoints without the field use the uniform grid.

Fresh quantization writes sinq_scale in FP32. The loader also accepts FP16 or BF16 with the same shape and requires finite, positive values. Both in-memory and file-based dequantization apply the column scale when reconstructing the dense weight. The config stores tiling_mode at the top level and under meta.weight_only. Checkpoints without this field default to 1D. With group_size=-1, all input channels share one affine group and the packer derives an all-zero g_idx if you omit it.

When A-SINQ is enabled, the saved config records awq, awq_samples, and awq_grid at the top level and under meta.weight_only. Loading uses the saved scales and needs no calibration data.

Saved metadata uses quant_method: "gptqmodel_sinq" and "sinq" for the method and format. The writer adds "gptqmodel": {"load_with": "GPTQModel.load", "hf_compatible": false} inside config.json's quantization_config and at the top level of quantize_config.json. Transformers 5.23's SINQ reader expects a separate W_q / meta layout. See Hugging Face integration.

Source and further reading

Clone this wiki locally