Repository navigation
Conversation
Contributor
|
I'll fix CI failures and address comments from users with write access that start with 'Devin'.
|
Contributor
Devin Review🟢 Devin Review found nothing to fix · View findings |
Keep main's FP8 load-only guard in quantize() alongside the solver/format planning path.
Qubitium
marked this pull request as ready for review
November 19, 2026 03:20
Keep both attn_mask helpers: main's align_single_head_capture (used by the capture path) and this branch's tokenizer_bos_token_id (used by the BOS-only statistic masking).
# Conflicts: # gptqmodel/models/loader.py
Qubitium
marked this pull request as draft
November 19, 2026 11:35
Qubitium
marked this pull request as ready for review
November 20, 2026 01:06
# Conflicts: # gptqmodel/models/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add CPU-only, executable feasibility proofs that solver choice can be separated from target numeric format. GPTQ/AWQ reference equations and the existing GSQ categorical primitive directly optimize legal hardware-format payloads; RCO's existing budget math and discrete allocator accept their actual storage costs.
Now includes the selected matched-config API and a qualified CPU GPTQ → MXFP4 lifecycle on Qwen2.
quantize(config=...)automatically prints and validatesmodel.plan()before calibration; unsupported combinations fail closed.exportand legacy method-based paths remain available.What Changed
Typed
solvers/formats,MatchedQuantizeConfig(QuantizeConfig), declared-role/glob/regexMatcher, isolated per-run config snapshots, and automatic planning.Public
quantize(CalibrationConfig(dataset=...), config=...)integrates main's calibration API: shared preparation, minimum length, sorting, concatenation and BOS-only statistic masking; old calibration kwargs/bare datasets are rejected.CPU blocked GPTQ and stage-group replay, packed-only MXFP4 inference, and versioned sharded safetensors save/load/re-save.
Matched API, lifecycle diagram, measured Qwen2.5-0.5B results and limits.
Finite CPU emulation of packed affine INT4, MXFP4, NVFP4, MXFP8 E4M3/E5M2, and ordinary per-tensor FP8 E4M3. FP4/FP8 element conversion needs no native low-precision dtype.
Exact stored-scale projection, canonical packed payloads, GPTQ activation-order handling, explicit AWQ input transforms, GSQ hard-payload acceptance, and RCO exact-bit budget checks.
Reproducible correlated-linear experiments with calibration/held-out data, RTN and INT4-then-convert controls, independent normal-equation/codebook/allocation oracles.
Mechanism, equations, measured results, format sources, and limits, linked from README.
nvfp8deliberately fails closed: NVIDIA's cited documentation names ordinary FP8, MXFP8, and NVFP4, not a distinct NVFP8 encoding.Means over seeds 0/1/2, weights 8×64, calibration 256×64, held-out 512×64, CPU FP64 arithmetic with format-constrained stored scales. All 18 format/seed pairs improved over RTN for each solver. These synthetic results are not LLM-quality guarantees or a solver ranking. RCO selects NVFP4/INT4/FP8 using 9,152 of 9,600 bits and exactly matches exhaustive allocation.
Qwen2.5-0.5B CPU validation
All 168 decoder projections, FP32 source, four CPU threads, 2,048 WikiText-2 training tokens for calibration. Held-out evaluation uses eight 128-token rows (1,016 next-token predictions), not full-corpus perplexity.
The quality regression is real; this is lifecycle validation, not accuracy parity. Native GPU layouts/kernels, MoE replay, AWQ/MXFP8 model lifecycles, activation quantization, and GIL=0 remain unqualified.
Tests
CI
All checks pass. The branch previously carried its own copy of
.github/workflows/awq_cpu.yml; main removed that workflow in #5117 (the AWQ CPUsuites moved out of pull-request CI), so merging main dropped it here as well and
the two red AWQ jobs no longer run. Nothing is disabled or bypassed.
Local verification on
origin/main@eea7f19d9(aarch64, torch 2.11):Attention-sink calibration and quality diagnosis
The matched CPU path now accepts the public
CalibrationConfigdirectlyand honors its BOS-only exclusion policy. Forward tokens/masks are unchanged;
only Hessian statistic rows are filtered. Shared tokenizer-BOS lookup avoids
divergence from the legacy runner. All-excluded input fails before mutation.
Same-model/same-held-out-token controls (1,016 predictions; not full WikiText):
The public sink option drops zero rows for this BOS-less tokenizer; the enabled
run reproduces the original quantized logit hashes exactly. Native inspection
does find non-BOS positional sinks, but explicitly removing first-position
statistics in a separate native-replay diagnostic worsens this small evaluation.
The scale-search control uses E8M0 exponent offsets -2/-1/0/+1 and is diagnostic,
not a newly shipped solver recipe. Fixed-grid GPTQ math matches the independent
oracle; the original 2,048-token recipe gives almost no PPL gain over RTN on
this small evaluation. These controls do not establish a general quality ranking.
Increasing the calibration prefix from 16 to 64 windows (2,048 to 8,192 tokens)
improves GPTQ perplexity to 34.45291 with the unchanged solver/scales recipe.
The source-model logit hashes and held-out tokens are identical. BOS exclusions
remain zero; public save/load/re-save again preserves payloads and logits exactly.
This control supports calibration sensitivity, not a full-corpus quality claim.
Red evidence: the new exact-Hessian/forward-context regression fails on the
preceding revision because it rejects the sink option, and passes with this
change. Coverage includes interior BOS, padding, non-BOS first tokens, strict
flag typing, and all-statistics-excluded failure before mutation.
Calibration API integration
Merged main's public
CalibrationConfigAPI while retainingconfig=for theindependent solver/format targets.
quantize()validates and plans beforeconsuming data, binds the model-owned preparer on a copy, and passes all preparation
settings through. Batch size other than one and adapter calibration fail closed.
An explicit tokenizer uses Tokenicer and persists through save/load. Caller-owned
configuration and forward context remain unchanged by sink-statistic exclusion.
The revalidated 0.5B run matches the pre-migration run exactly: all 458
checkpoint tensors, dense/quantized held-out logit hashes, greedy token IDs,
storage counts, and perplexity. The shared preparation removes no rows from
these equal-length windows. The BOS-less tokenizer still excludes zero sink rows.
Red evidence:
test_calibration_config_object_reaches_matched_sink_statisticsfails on the pre-adaptation runner with
TypeError: 'CalibrationConfig' object is not iterable; it passes after integration. New consumer-level coverage usesrow lists, mappings, columns, tensors and a one-shot generator across native,
ascending and descending order, minimum-length filtering, interior BOS, text
concatenation with a BOS separator, padded tails, and tokenizer/packed-logit
roundtrips, and caller-owned configuration reuse across models. Existing
shared-calibration tests also cover the legacy runner.
Prior lifecycle and reference validation
New regressions cover automatic planning before calibration, unsupported/empty/overlapping matches, independent normal-equation solves and scalar decodes, configuration propagation, partial-failure cleanup, transactional save, corrupted layout metadata, packed storage after forward/reload, padded SDPA, and FP16/BF16/FP64 native-load roundtrips. Lower-precision whole-model casts also alter nonpersistent RoPE buffers: planning/saving now reject them rather than silently changing reload numerics. Use
load(dtype=...)instead. Initial sharded-save tests caught missing per-shard metadata and failed before the writer correction.Environment repair: the snapshot's cached PyPcre wheel raised SIGILL in an unchanged GGUF config test. Rebuilding the same 0.6.4 version with
--no-cache-dir --no-binary=pypcrefixed it; the complete baseline suite above then passed, with no code workaround or skipped cases.test_e8m0_scale_selection_at_power_boundary_neighboursceil(log2())implementation, which rounded above-boundary values back onto the boundaryfrexpmantissa comparisontest_zero_tiny_outliers_and_rtn_grid_idempotencetest_gptq_matches_independent_constrained_least_squarestest_solver_improves_real_hard_target_payload_not_just_soft_loss, conversion controltest_awq_keeps_transform_and_optimizes_target_format_objectivetest_gsq_frozen_scales_hard_guard_and_rng_ownership, identity-metric controlModel Support / Module Plan
Qwen2 adds an explicit non-inherited CPU GPTQ/MXFP4 capability. No
MODEL_MAP, module-tree paths, AWQ overrides, or fusion qualifications change. Real tiny Qwen2 models verify semantic selectors, all seven decoder projections, unmatched weights and native replay. The existing registry/consumer suite passes; unqualified definitions and fused/remote-code/lazy-source models fail closed.AWQ onboarding safety
No new model/format combination is AWQ-scaling-qualified by this PR; AWQ/MXFP8 requests are explicitly rejected by the new planner. The reference is a standalone linear objective and retains the FP32 input transform explicitly. Production graph folding, residual branches, replay, clipping, and model-specific qualification remain out of scope.
Logic Flow Documentation
flowchart TD A["BaseQModel.quantize: validate unbound CalibrationConfig"] --> B["BaseQModel.plan: resolve_plan"] A -->|invalid API| X["Fail before weight mutation"] B --> C["ModulePlan roles and declared paths"] C --> D{"Solver/format/model lifecycle supported?"} D -->|no| X D -->|yes| E["Print all assignments; validate call options"] E -->|unsupported options| X E -->|valid| P["CalibrationConfig.bind: model.prepare_dataset"] P --> Q["Normalize, filter, concatenate, sort and batch"] Q -->|invalid data| X Q -->|valid| R["Separate statistic masks from forward masks"] R -->|no retained statistics| X R -->|valid| F["quantize_model: capture first decoder inputs"] F --> G["Replay stage group; Hessian.capture excludes padding and configured BOS rows"] G --> H["solve_gptq_hessian: legal E2M1 on stored E8M0 scales"] H --> I["MXFP4Linear: packed bytes and scale bytes only"] I --> J["Replay updated layer; propagate hidden states"] J -->|next group/layer| G J -->|complete| K["BaseQModel.save: save_checkpoint"] G -->|failure| Y["Remove hooks; incomplete model cannot retry/save"] K --> L["Staging: safetensors shards and solution manifest"] L -->|publish| M["GPTQModel.load: load_checkpoint"] M --> N["Validate schema/layout/dtypes; reconstruct packed modules"] N --> O["Forward with bounded temporary decode; no dense cache"] classDef failure fill:#fee,stroke:#c22 class X,Y failurequantization/config.py:4775models/base.py:2103plan→ stage-group CPU runnermodels/base.py:2136,quantization/solver_format.py:75CalibrationConfig, copied binding and shared filtering/sort/concatenation before statisticsmodels/base.py:3435,models/loader.py:2489docs/format-solver-feasibility.mdand linked from README.flowchart TD A["W, calibration X, target format"] --> V{"Valid finite CPU problem?"} V -->|No| E["ValueError; no solution published"] V -->|Yes| G["fit_grid: legal stored scales and blocks"] G --> Q["solve_gptq: target projection and error feedback"] G --> S["solve_gsq: categorical relaxation and hard guard"] V -->|Yes| W["solve_awq: diagonal transform and target-grid search"] Q --> P["FormatGrid.pack"] S --> P W --> P P --> F["SolverResult.forward: temporary CPU decode"] P --> R["allocate_rco: measured errors and exact storage costs"] R --> B{"Feasible budget?"} B -->|No| E B -->|Yes| O["Assignment verified against exhaustive oracle"] style E fill:#fee,stroke:#c33quantizer.py:232,gptq.py:452: affine quantizer metadataawq_processor.py:3675: affine pseudo-quantizationgsq_training.py:30,rco.pymodels/auto.py:1242,quantization/protocol.py:31: export API/fieldsReview Requirements
Kernel Accuracy Requirements
A CPU MXFP4 correctness kernel is added, with at most 128 output rows of temporary decode and no persistent expanded weights. Independent FP32/FP64 scalar-decoded Torch oracles, exact blocked-GPTQ codes and repeated packed-state/forward transitions pass. CPU codec tests cover every finite code, every rounding midpoint and adjacent FP64 inputs, saturation, signed zero, scale boundaries, and independent packed-word decoding. Native Torch FP8 casts agree in the finite range. No GPU, native FP4 instruction, swizzle, or broad model-quality qualification is claimed; the bounded 0.5B CPU smoke metrics are above.
Notes
Canonical proof packing is not a vendor/checkpoint layout. AWQ transform overhead counts unless safely folded upstream. GSQ scales are frozen; RCO uses an additive reconstruction objective, not full-model KL training. GIL=0/concurrent execution, generalized model/format coverage and removing
exportremain follow-ups. The new Qwen2 CPU path includes calibration and versioned safetensors checkpoints. The proof has bounded small fixtures but is not a memory-scalable production solver.Link to Devin session: https://app.devin.ai/sessions/87000f2a80ad4de69b7daf41c9100d28
Open in Devin Desktop: https://app.devin.ai/desktop/session/87000f2a80ad4de69b7daf41c9100d28?variant=devin
Requested by: @Qubitium