Skip to content

feat(sinq): add A-SINQ with the AWQ activation-aware scale search - #6615

Merged
ZX-ModelCloud merged 1 commit into
mainfrom
feat/sinq-awq
Dec 1, 2026
Merged

ZX-ModelCloud merged 1 commit into
mainfrom
feat/sinq-awq

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds A-SINQ, the calibrated SINQ variant: SINQConfig(awq=True) captures
native linear inputs, reuses the project's AWQ activation-aware scale search,
folds the winning per-input-channel scale into the weight, and stores its
inverse in the existing sinq_scale tensor. Packing, the checkpoint layout and
SinqLinear are unchanged.

Based on current main (includes the NF4/NF3 codebook change, #6608); the
A-SINQ path is orthogonal to the codebook and gate-scope additions.

Net: 13 files, +1221 / -103.

Problem

Plain SINQ is calibration-free. At 4 bits / group 128 on WikiText-2 it lands
behind same-bit GPTQ on both benchmark models (17.530 vs 17.496 on
SmolLM2-135M, 16.100 vs 15.103 on Qwen2.5-0.5B-Instruct). The AWQ search
already produces the per-input-channel scale that SINQ's Sinkhorn column axis
only approximates, so the calibration pre-pass reuses it.

What Changed

  • gptqmodel/quantization/sinq_awq.py (new): captures each target linear's
    native input rows, scores the 20-point AWQ grid plus the calibration-free
    result through SINQ's own affine fit, and returns one scale per module.
    Modules without captured rows, or whose best candidate is the calibration-free
    result, keep plain SINQ. Rows are staged per calibration batch and moved to
    the host, so the accelerator holds one batch of activations.
  • gptqmodel/quantization/sinq.py: SINQ(awq_scale=...) folds the scale into
    the tile before the affine fit and divides it out of the stored column scale.
    The calibrated scale replaces Sinkhorn's column estimate, so the walk is
    skipped for A-SINQ. The NF4/NF3 fit and the per-tile gate are unchanged for
    the plain path.
  • gptqmodel/quantization/awq/quantize/scale.py: AWQ_SCALE_GRID and
    awq_scale_candidates are now shared; awq_processor.py consumes the helper
    instead of its inline copy (no behavior change).
  • gptqmodel/quantization/config.py: SINQConfig gains awq, awq_samples,
    awq_grid, with validation, dynamic-override rejection and serialization.
  • gptqmodel/models/base.py: _calibrate_sinq_awq prepares the calibration
    rows, moves the dense model to the calibration device, runs the pre-pass and
    restores device/training/cache state; the scales are handed to the weight-only
    processor.
  • gptqmodel/looper/weight_only_processor.py: passes the per-module scale to
    SINQ.
  • scripts/benchmark_sinq_ppl.py: asinq config plus --awq-samples /
    --awq-grid, and records calibration samples, tokens, grid, time and peak.
  • Docs, tests and the benchmark result tables below.

Follow-up intentionally out of scope: 2D tiling, fused SINQ GEMM, and
per-layer scale search for models whose calibration rows are not captured.

Flow

Before (plain SINQ):

flowchart LR
    A["dense W"] --> B["Sinkhorn walk<br/>row + column scales"]
    B --> C["affine or NF4/NF3 fit per group"]
    C --> D["qweight, scales, zeros"]
    B --> E["sinq_scale = column scale"]
Loading

After (A-SINQ):

flowchart LR
    A["calibration rows X"] --> B["capture native linear inputs"]
    B --> C["AWQ grid: 20 candidates<br/>plus plain SINQ"]
    C --> D["fold s into W"]
    D --> E["affine fit per group<br/>walk skipped"]
    E --> F["qweight, scales, zeros"]
    D --> G["sinq_scale = 1 / s"]
Loading

Situation -> before -> after:

Situation Before After
4-bit accuracy Calibration-free SINQ, behind GPTQ on both models A-SINQ, 2.1% ahead of GPTQ on SmolLM2-135M and 2.1% behind on Qwen2.5-0.5B-Instruct
Column axis Sinkhorn estimate from the weight Calibrated AWQ scale, searched per module
Row axis Sinkhorn row scale Absorbed by the per-group affine scale
Calibration requirement None CalibrationConfig.dataset when awq=True
Checkpoint / kernel GPTQ-shaped tensors plus sinq_scale Unchanged

Why the scale is folded before the fit

The reference A-SINQ applies the AWQ scale after the Sinkhorn walk. Measured
on Qwen2.5-0.5B-Instruct (35 sampled layers, 16 calibration windows of 512
tokens), mean per-layer output error relative to plain SINQ:

Fold position Mean error vs plain SINQ
After Sinkhorn (reference order) 1.05x
Before Sinkhorn 0.95x
Before the fit, walk skipped 0.80x

Sinkhorn's column estimate is proportional to the column magnitude of the tile
it normalizes, so folding first and keeping the walk divides the calibration
back out. Its row estimate is absorbed by the per-group affine scale: row-only
normalization measured identically to no normalization. A-SINQ therefore uses
the calibrated scale as the column axis and skips the walk.

Tests

  • Unit tests executed and passed.
  • New targeted unit tests added for the fold order, the Sinkhorn skip, the
    calibration-free fallback, capture row identity, config round trip and the
    tiny-model end-to-end path.
python -m pytest -q tests/test_sinq.py
# 110 passed

python -m pytest -q tests/test_sinq_gpu.py
# 23 passed, 4 skipped (NVIDIA; the ROCm-only fused-decode tests skip); 27 passed (AMD)

python -m pytest -q tests/module_tree/test_awq_relationships.py \
  tests/module_tree/test_bloom_awq_relationships.py \
  tests/module_tree/test_definition_subset_ordering.py \
  tests/module_tree/test_registered_module_plans.py \
  tests/test_awq_position_kwargs.py tests/test_awq_scale_search_memory.py \
  tests/test_awq_scale_search_safety.py tests/test_awq_weight_mean.py \
  tests/test_bloom_awq_replay.py
# 670 passed

python -m pytest -q tests/test_weight_only.py tests/test_weight_only_config.py \
  tests/test_weight_only_looper.py tests/test_weight_only_processor_error.py \
  tests/test_weight_only_failed_run_device_5011.py \
  tests/test_weight_only_smoother_unapplied_5401.py
# 167 passed

python -m pytest -q tests/test_docs_contract_refs.py
# 267 passed

bash format/check.sh
# All checks passed

Red/green: reintroducing the post-Sinkhorn order makes
test_sinq_awq_folds_scale_before_the_affine_fit and
test_sinq_awq_skips_the_sinkhorn_column_estimate fail; the committed code
passes both.

Measured Impact

WikiText-2 perplexity, weight-only, 4-bit, group_size=128. Every checkpoint is
reloaded before scoring; GPTQ uses 128 calibration windows of 512 tokens, A-SINQ
uses 16 (8,192 tokens) and the 20-point grid.

Metric FP16 GPTQ SINQ A-SINQ
SmolLM2-135M PPL 14.540 17.496 17.530 17.133 (-2.1% vs GPTQ)
Qwen2.5-0.5B-Instruct PPL 13.918 15.103 16.100 15.425 (+2.1% vs GPTQ)

Calibration cost (one pre-pass; wall-clock varies with host load):

Model Calibrated layers Capture Search Total Peak
SmolLM2-135M 207 1.5 s 38.3 s 39.9 s 461 MiB
Qwen2.5-0.5B-Instruct 162 1.6 s 17.8 s 19.4 s 1,484 MiB

The branch is rebased onto the merged 2D-tiling (#6614) and fused-decode
(#6619) changes. A re-run of the SmolLM2-135M row on that base reproduced the
numbers exactly: A-SINQ 17.133 versus GPTQ 17.496.

A-SINQ is ahead of same-bit GPTQ on SmolLM2-135M and 2.1% behind on
Qwen2.5-0.5B-Instruct; the remaining gap is GPTQ's second-order error feedback.
Raising awq_samples did not help: Qwen2.5-0.5B-Instruct scored 15.72 with 64
windows (32,768 tokens) against 15.42 with 16.

Reproduce:

python scripts/benchmark_sinq_ppl.py --model HuggingFaceTB/SmolLM2-135M \
  --configs dense,rtn,gptq,sinq,asinq --bits 4 --group-size 128
python scripts/benchmark_sinq_ppl.py --model Qwen/Qwen2.5-0.5B-Instruct \
  --configs dense,rtn,gptq,sinq,asinq --bits 4 --group-size 128

Model Support / Module Plan

Not applicable: no MODEL_MAP entry, alias or definition changes.

Skips / unverified

  • Only 4-bit is benchmarked. The 3-bit and 2-bit A-SINQ paths run the same code
    but were not scored.
  • A-SINQ with NF4/NF3 codebooks is not benchmarked; the fold applies before the
    codebook fit, so the path runs, but no accuracy number is claimed.
  • No MoE checkpoint was calibrated end-to-end. Uncaptured modules keep plain
    SINQ; the fallback is unit-tested.
  • The reference implementation's num_betas and L1 variants are not exposed.

Related

Comment thread gptqmodel/quantization/sinq.py Fixed
@ZX-ModelCloud
ZX-ModelCloud marked this pull request as ready for review December 1, 2026 07:55
Plain SINQ is calibration-free and lands behind same-bit GPTQ at 4 bits.
SINQConfig(awq=True) captures native linear inputs, scores the project's
twenty-point AWQ scale grid plus the calibration-free result through
SINQ's own affine fit, and folds the winning per-input-channel scale into
the weight. The inverse is stored in the existing sinq_scale tensor, so
packing, the checkpoint layout and SinqLinear are unchanged.

The scale is folded before the fit rather than after the Sinkhorn walk.
Sinkhorn's column estimate is proportional to the column magnitude of the
tile it normalizes, so folding first and keeping the walk divides the
calibration back out: on Qwen2.5-0.5B-Instruct the mean per-layer output
error is 0.95x of plain SINQ with the walk and 0.80x without it. The
calibrated scale therefore replaces the column axis; the row axis is
absorbed by the per-group affine scale.

WikiText-2 perplexity, 4-bit, group_size=128, 16 calibration windows:
SmolLM2-135M 17.133 vs GPTQ 17.496; Qwen2.5-0.5B-Instruct 15.425 vs
GPTQ 15.103 (plain SINQ: 17.530 / 16.100). The pre-pass costs 39.9 s /
461 MiB and 19.4 s / 1,484 MiB respectively.

AWQ_SCALE_GRID and awq_scale_candidates now live in
gptqmodel/quantization/awq/quantize/scale.py so the AWQ processor and
A-SINQ share one candidate definition.
@ZX-ModelCloud
ZX-ModelCloud merged commit 4f3ba22 into main Dec 1, 2026
6 checks passed
@ZX-ModelCloud
ZX-ModelCloud deleted the feat/sinq-awq branch December 1, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant