Skip to content

feat(rco): allocate AWQ, EXL3 and GGUF formats under packed-weight budgets - #3561

Merged
Qubitium merged 5 commits into
ModelCloud:mainfrom
Qubitium:feat/rco-format-adapters-clean
Nov 6, 2026
Merged

Qubitium merged 5 commits into
ModelCloud:mainfrom
Qubitium:feat/rco-format-adapters-clean

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Adds a measure → allocate → quantize workflow for per-module AWQ, EXL3 and GGUF choices. Projection identity comes from the model definition tree and its tags through shared discover_projections; there are no projection-name suffix heuristics. The already-merged dependencies (#3562, #3563, #3564) are incorporated from main, resolving the stale stack conflicts.

Search and artifacts

All three adapters use reconstruction-error allocation, with an explicit relative Frobenius or Hessian metric. This does not implement differentiable Gumbel/KL interpolation. AWQ measurements are affine weight reconstruction proxies; final calibrated quantization can change reconstruction quality. EXL3 errors are recomputed from native returned reconstructions against the original Hessian, avoiding native sentinel scores and in-place Hessian contamination.

Versioned score and plan files retain option order, matrix shapes, parameter counts and backend settings. Allocation rejects unlabeled/mismatched scores and conflicting settings. Quantization revalidates the plan and requires the complete model-definition inventory and matching shapes, so --limit samples cannot masquerade as complete-model budgets.

Budget correctness

The runner budgets actual packed projection tensors, including scales, zeros, EXL3 metadata, GGUF blocks and row padding. It excludes biases and unquantized model state. Costs are shape-dependent; for example Q6_K uses 6.5625 bits per full-block weight. The library also supports explicitly labeled nominal budgets when shapes are omitted.

Float64 parameter counts and costs prevent precision-related overspend. The DP accepts per-module option costs and caps its backtrack table. A bounded repair can downgrade a module repeatedly and requires the final exact budget to hold. The discretized/repair solution is not claimed to be a globally optimal solution of the continuous-cost problem.

Measured custom options, AWQ group size/symmetry and EXL3 settings survive all three stages. AWQ 2/3-bit support uses the existing portable GEMM-layout AWQ_TORCH path; native GEMM/GEMV remains 4-bit.

Validation

  • Broad regression run: 274 passed, 34 skipped, covering format allocation, AWQ per-module widths, RCO/search/discovery, GGUF dynamic formats and config dispatch. Final format suite after two additional artifact-validation cases: 73 passed.
  • Complete CPU workflows for AWQ and GGUF: measure, allocate, quantize, save, reload and forward on a local tiny Llama model. Actual saved packed bytes match the reported achieved budget and stay within the target.
  • Extended independent AWQ oracle coverage to 2/3-bit scale search, packing, reload and repeated forwards, with FP16/BF16 activations and symmetric/asymmetric codes. Packed weights/zeros and scales match exactly; quantization checks use at most 1e-6 tolerance and forward checks 2e-3. Repeated forwards retain no dense/expanded weight tensors.
  • Per-module DP costs checked against a brute-force oracle; regressions cover float32 count loss, repeated repair, GGUF padding, EXL3 sentinel handling and malformed/inconsistent artifacts.
  • Ruff and whitespace checks pass.

Test environment: Torch 2.8.0 CPU, Transformers 5.22.1. GPU-only cases were skipped. Native EXL3 GPU quantization and optional native GGUF IQ quantizers were not executed here; EXL3 call semantics and packed-cost accounting have CPU/mock coverage.

@Qubitium
Qubitium marked this pull request as ready for review November 6, 2026 22:10
`AWQConfig` accepts a per-module width through `dynamic` (e.g. W8 on one
layer of a W4 run). `create_quant_module` applied that override when it
built the module, but the staging pass, the clip search and the scale
search all read `qcfg.bits` directly. A W8 module therefore staged 4-bit
codes and packed them into an 8-bit container.

Measured on upstream before this change: a module whose config says
`bits: 8` staged codes in the 4-bit range (widest code 7.0, where W8
allows 127), i.e. it was quantized as W4 and mislabelled as W8.

Resolve the width once in `_module_bits` (falling back to the global
width for an excluded module or a rule that only sets another key --
neither is a width, and coercing them to 0 was wrong too) and thread it
through:

  - `pseudo_quantize_tensor` / `_pseudo_quantize_tensor_into`
  - `_search_best_scale` / `_compute_best_scale` (clip + scale search)
  - the GSQ refine step
  - the packing `create_quant_module` call

A scaling group shares one activation scale, so its first member's width
drives the search; `apply_quant` re-quantizes each module at its own
width afterwards.

The CUDA GEMM/GEMV kernels unpack 4-bit codes only, so a non-4-bit
module now routes to the portable `AwqTorchLinear` (2-8 bits) instead of
being handed to a kernel that cannot represent it.
`GGUFConfig` stores a per-module width and ggml type in separate fields,
because one width maps to several types: width 4 is `q4_0`/`q4_1`/`q4_k`,
width 2 is `q2_0`/`q2_k`, width 5 is `q5_0`/`q5_k_m`. `create_quant_module`
read only the digits and let `_GGUF_DEFAULT_BITS_ALIAS_BY_WIDTH` pick the
type, so a mixed-type checkpoint silently reloaded every module at the
*default* type for its width and discarded the requested one.

Fold the `format` override back into the structured spec before the module
is constructed, so `{"bits": 4, "format": "q4_k"}` builds a `Q4_K` module
rather than a `Q4_0` one.

Measured on a q3_k/q4_k mixed checkpoint: 7 of 14 modules reloaded as
`Q4_0` before this change, 0 after.
`scripts/gsq_paper/rco_allocate.py` and `rco_materialize.py` each repeated a
seven-name tuple:

    PROJECTIONS = ('self_attn.q_proj', ..., 'mlp.down_proj')

An architecture that adds a projection therefore had those tensors dropped
from the width database, the bit budget and the merge -- silently. Ripple-65B
has a gated attention projection `self_attn.g_proj`, so 80 of its 640
quantised modules were never allocated, and the 560 that were got an
assignment chosen against a budget computed from the wrong denominator.

Demonstrated on the previous code with an 8-projection block:

    projections actually in the block : 8
    projections RCO would allocate    : 7
    SILENTLY DROPPED                  : ['self_attn.g_proj']

`gptqmodel/quantization/rco.py` now exposes `discover_projections`, which
walks the live module tree: any `nn.Linear` under an indexed block is
allocatable, minus the vocabulary projections. That covers extra attention
projections, fused `qkv_proj`-style modules and MoE expert projections without
a per-architecture list. `block_of` reports the decoder index, and
`DEFAULT_PROJECTIONS` keeps the paper's seven names as the documented default.

Both scripts now derive the set from the model (or, for the materializer, from
the assignment itself, which is the authority on what the checkpoint holds)
and fall back to the tuple only when discovery yields nothing, so existing
staged arms keep rebuilding exactly the tensors they were written with.
GSQ-RCO shipped for GPTQ only: `scripts/gsq_paper/rco_allocate.py` stages
dense W2/W3/W4 arms and solves the budget. AWQ, EXL3 and GGUF had no
allocation path at all. This adds one adapter per backend, on top of the
three fixes this branch is stacked on (per-module AWQ width, per-module
GGUF type, arch-generic projection discovery).

Each adapter reports its option set, its real per-parameter cost, and which
search produced the assignment:

  AWQ   interpolation   w2/w3/w4      cost = bits + (16+bits)/group
  EXL3  reconstruction  k2/k3/k4      cost = bits
  GGUF  reconstruction  ggml aliases  cost = ggml block bpw

AWQ is scored with the affine quantizer its processor stages, and its arms
are dense, so the paper's interpolation search genuinely applies. EXL3
stores a trellis and GGUF stores ggml blocks; neither is a linear function
of a dense weight, so no dense arms exist to interpolate. Both are scored
with the Hessian-weighted reconstruction error their own quantizer reports.
`RCOPlan.search` records which case a plan is, so a plan cannot be mistaken
for the paper's Gumbel/KL search. GSQ-RCO in `scripts/gsq_paper/` stays
GPTQ-only; no EXL3 or GGUF interpolation path is claimed.

`scripts/gsq_paper/rco_format_allocate.py` drives three stages, so the
expensive measurement runs one GPU per backend while the allocation stays on
the host. The budget is weighted by real `in*out` counts: a 5.2M `k_proj`
must not count the same as a 209.7M `mlp` projection, or the solver "buys"
accuracy by widening every small matrix and narrowing the MLPs.

The DP rounds its unit costs, so `achieved` can exceed the exact target by
up to `0.5 * n / resolution`. The guard allows exactly that bound, retries on
a finer grid, and `repair_overspend` demotes single modules until the exact
budget holds, so a plan never overspends.

`METHOD_SUPPORTED_BITS[METHOD.AWQ]` widens from `(4, 8)` to `(2, 3, 4, 8)`.
Non-4-bit AWQ is only legal because `create_quant_module` routes those
modules to `AwqTorchLinear`; if that routing is removed, this must narrow
again.
@Qubitium
Qubitium force-pushed the feat/rco-format-adapters-clean branch from 32db6eb to 2da7440 Compare November 6, 2026 22:22
Merge main's reviewed model-tree discovery, AWQ staging and GGUF fixes.
Preserve measured options/settings and exact shape-dependent packed costs,
validate score artifacts and plans, and repair overspend without unbounded
DP refinement. Label all adapters as reconstruction search and score EXL3
from returned reconstructions instead of native error sentinels.

Exercise low-bit AWQ independent packing/forward oracles and complete CPU
AWQ/GGUF measure-allocate-quantize-save-reload workflows.
@Qubitium Qubitium changed the title feat(rco): allocate per-module widths for AWQ, EXL3 and GGUF feat(rco): allocate AWQ, EXL3 and GGUF formats under packed-weight budgets Nov 6, 2026
@Qubitium
Qubitium merged commit 0aaf40e into ModelCloud:main Nov 6, 2026
1 check passed
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