Skip to content

Unify backend selection and tuning with typed BackendConfig - #4375

Merged
Qubitium merged 3 commits into
mainfrom
backend-config-api
Nov 16, 2026
Merged

Qubitium merged 3 commits into
mainfrom
backend-config-api

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

backend= now accepts either an existing BACKEND/string selector or an immutable BackendConfig instance that selects and configures its own backend:

from gptqmodel import GPTQModel
from gptqmodel.backend import BACKEND, MarlinConfig

GPTQModel.load("org/model", backend=BACKEND.MARLIN)       # Existing defaults
GPTQModel.load("org/model", backend=MarlinConfig(fp32=False))

BackendConfig is abstract; concrete configurations declare fixed identities and validate backend-specific fields. Quantized modules own execution-policy snapshots so later loads do not retune them.

What Changed

  • Resolve typed selection at load, pretrained-load, quantized-load and quantization boundaries. Retain a dense model's typed choice through quantize() and allow an explicit quantization-time override.
  • Add RuntimeConfig for shared worker, quantizer and host settings on loaders and QuantizeConfig.runtime.
  • Preserve enum/string aliases, legacy kernel=KernelConfig(...)/mappings, and the existing root GGUFConfig quantization export. The backend-specific GGUF type is GGUFTorchConfig.
  • Reject competing typed/legacy policies. Keep all runtime settings out of checkpoint metadata.
  • Pass module-owned options to AWQ, Swordfish, block-float and GGUF CPU native wrappers; retain existing backend compatibility checks and hardware declarations.
  • Document the API and ownership rules in docs/backend-selection.md, update the legacy field guide and link both from README.
  • A separate commit clears nine pre-existing Ruff import violations required by the repository-wide CI gate.

Tests

  • Unit tests have been executed and passed.
  • Added simple, fast regression coverage for abstractness, fixed identities, defaults, validation, compatibility, policy conflicts, loader forwarding, quantization retention/override, export compatibility and policy isolation.

Python 3.14.6 free-threading build, Torch 2.15.0+cpu, Triton 3.9.0. Triton's native import enables the GIL; these results do not qualify GIL=0 accelerator concurrency.

Exact commands, run from tests/:

PYTHONPATH=/home/ubuntu/repos/GPTQModel /home/ubuntu/.venvs/model-dsl215-repro/bin/python -m pytest test_backend_config.py test_kernel_config.py test_backend_naming.py test_torch_weight_storage.py test_loader.py test_awq_rank_and_empty.py test_awq_fp32_output.py test_tt_blockfloat_cuda_dispatch.py kernels/test_gguf_cpp_path_selection.py test_module_looper_disk_probe.py test_weight_only_looper.py::test_weight_only_looper_unset_policy_resets_previous_run -x -q -ra
# 342 passed, 7 skipped in 9.80s

PYTHONPATH=/home/ubuntu/repos/GPTQModel /home/ubuntu/.venvs/model-dsl215-repro/bin/python -m pytest test_tt_blockfloat_out_axis.py test_tt_blockfloat_precision.py test_tt_blockfloat_sequential.py -x -q -ra
# 28 passed, 4 skipped in 6.44s

From the repository root:

ruff check gptqmodel docs/eora tests setup.py
# All checks passed
/home/ubuntu/.venvs/model-dsl215-repro/bin/python -m compileall -q gptqmodel tests/test_backend_config.py
git diff --check
# Both passed

Model Support / Module Plan

Existing failures outside the focused checks

The latest AWQ CPU (unit) job terminates during native pcre import with Illegal instruction (exit 132), before test collection completes. The other six checks pass. A retry through gh run rerun --failed was denied with Resource not accessible by integration; a maintainer needs to rerun that check. This native-import failure is not reproduced locally and is not claimed as a verified baseline failure.

The previous AWQ CPU (unit) CI run completed with five test failures. The identical five reproduce in a detached checkout of the unchanged base 9b11fb3b0: stale test doubles reject sym (one case) and syms (three cases); the nemotron_h scaling-group test measures output drift 0.2822258174419403 on both revisions. Those implementation/test files are unchanged. Reproduction on base: 5 failed, 1 passed, 4 skipped in 6.76s; on this branch: 5 failed, 1 passed, 4 skipped in 5.58s.

python -m pytest tests/test_awq_weight_mean.py tests/test_awq_scaling_groups.py \
  -k 'weight_mean_matches_legacy_impl or nan_grid_keeps_unclipped_bound or nemotron_h' \
  -q -o addopts='' -o log_cli=false

An expanded run also reached an existing test_weight_only_looper_quantizes_input_and_lm_head_embeddings_only assertion about offload_to_disk; that same assertion fails on the unchanged base (1 failed in 2.93s). The new run-boundary regression in that file passes. These failures are documented rather than changing unrelated AWQ folding or offload behavior here.

Applicability

Not applicable: no model definitions, module plans, fusion qualifications or new hardware support.

AWQ onboarding safety

Not applicable: no model onboarding or grouping/search/replay/folding changes.

Logic Flow Documentation

  • Required diagrams and documentation are included.
  • New-flow diagram uses shipped symbol names.
  • Replaced mechanisms are tabulated with original file:line evidence.
  • Failure and ambiguity paths are visually distinct.
  • docs/backend-selection.md contains the same flow and is linked from README.
flowchart TD
    A["GPTQModel.load / from_pretrained / from_quantized<br/>BaseQModel.quantize"] --> B["resolve_backend_config(backend, kernel, runtime)"]
    A -- "quantization config present" --> R["resolve_quantize_backend<br/>retain typed choice and generated policy"]
    R --> B
    B --> C{"BackendConfig instance?"}
    C -- yes --> D{"Legacy kernel supplied?"}
    D -- yes --> E["ValueError: ambiguous policy"]
    D -- no --> F["backend.backend + backend.kernel_options()<br/>merge RuntimeConfig.kernel_options()"]
    C -- no --> G["normalize_backend(enum or string)<br/>legacy kernel or RuntimeConfig adapter"]
    B -- "runtime + legacy kernel" --> E
    F --> H["BACKEND + validated KernelConfig"]
    G --> H
    H --> I["Existing backend compatibility / selection"]
    I -- "unsupported method / device / shape" --> J["Existing selection error"]
    I --> K["QuantizeConfig.kernel<br/>make_quant / quant_linear_init_kwargs"]
    K --> L["BaseQuantLinear.__init__<br/>snapshot_kernel_config"]
    L --> M["module.kernel<br/>constructor settings and native op arguments"]
    H --> N["configure_kernel<br/>shared quantizer / host fallback"]
    classDef failure fill:#ffe0e0,stroke:#b00,color:#600
    class E,J failure
Loading

Before locations refer to the original gptqmodel/ tree:

Mechanism Before After
Selection models/auto.py:872,1005,1129: enum/string normalization resolve_backend_config extracts a typed config's fixed backend identity
Tuning models/auto.py:839: separate mixed kernel= policy Typed backend= for execution options; runtime= for shared controls; legacy adapter preserved
Module ownership nn_modules/qlinear/__init__.py:288, utils/model.py:623: selector and qcfg kwargs BaseQuantLinear owns a snapshot, also forwarded by make_quant
Fallback utils/kernel.py:404-414: owner or process policy Direct policy objects are honored; modules keep snapshots; shared utilities keep the process fallback

Review Requirements

  • Reviewed the code and existing call sites before opening this PR.
  • Checked structure, APIs and conventions.
  • Used real configuration objects and Torch layers; mocks are limited to external checkpoint/native-op boundaries.
  • Centralized quantization-policy resolution and kept the kernel math unchanged.
  • Added regression coverage for compatibility and ownership hazards.

Kernel Accuracy Requirements

  • Measured applicable CPU inference against independent Torch references; the new two-model isolation test matches its FP32-sum oracle exactly. Existing packed-weight storage tests passed for repeated forwards and mutation. No new persistent weight representation or dequantized cache is introduced.
  • Fusion support requirements: not applicable; AUTO selection and hardware admission are unchanged.
  • Coverage limits are listed below; skips do not qualify native execution.
Changed configuration consumer Validation / gap
Torch GPTQ CPU storage/oracle suite passed, including FP16/BF16 cases; NVIDIA streaming tests skipped (2)
AWQ CUDA/Triton and ParoQuant API and empty/training/argument propagation checks passed; native CUDA oracle skipped (1); GPU execution unverified
Marlin and Swordfish Typed defaults/identity and compatible API selection tested; native NVIDIA kernels unverified
GGUF Torch / native GGUF CPU/CUDA Configuration validation covered; GGML CPU bridge tests skipped (3), missing llama-cpp-python; native CUDA unverified
BitsAndBytes Typed defaults and option validation covered; optional native runtime unverified
TT block-float CPU out-axis/precision/sequential suites passed; two-NVIDIA-device check skipped (1), native CUDA/HIP precision cases skipped (4)

Notes

Legacy kernel= remains supported with enum/string selectors. Combining it with a typed backend or runtime= raises ValueError, including a caller-supplied policy on QuantizeConfig.

Calling configure_kernel now changes the fallback for future modules/shared utilities; constructed quantized modules retain their own execution settings. Shared quantization/host controls remain process-wide, so concurrent quantization runs with different shared settings are not isolated by this API. All policies are runtime-only and must be supplied again on reload.

Link to Devin session: https://app.devin.ai/sessions/c7274b2371174a98b4f2ca4761abcbcd
Open in Devin Desktop: https://app.devin.ai/desktop/session/c7274b2371174a98b4f2ca4761abcbcd?variant=devin
Requested by: @Qubitium

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access that start with 'Devin'.

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Devin Review

🟢 Devin Review found nothing to fix · View findings

Comment thread tests/test_backend_config.py Resolved
@devin-ai-integration

devin-ai-integration Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Latest CI: six checks pass. AWQ CPU (unit) terminates during native pcre import with Illegal instruction (exit 132), before test collection completes. The native-import crash is not reproduced locally. Retrying with gh run rerun --failed was denied: Resource not accessible by integration. A maintainer needs to rerun this check.

The previous completed AWQ unit run reported five test failures. All five reproduce on the unchanged base revision 9b11fb3b0, using a detached baseline checkout and the same local interpreter/dependencies as this branch:

python -m pytest tests/test_awq_weight_mean.py tests/test_awq_scaling_groups.py \
  -k 'weight_mean_matches_legacy_impl or nan_grid_keeps_unclipped_bound or nemotron_h' \
  -q -o addopts='' -o log_cli=false

Both revisions produce one stale sym test-double signature, three stale syms test-double signatures, and nemotron_h AWQ scaling output drift of 0.2822258174419403. Local results: base 5 failed / 1 passed / 4 skipped in 6.76s; PR 5 failed / 1 passed / 4 skipped in 5.58s. Those AWQ implementation and test files are unchanged by this PR.

Focused API/storage/dispatch/looper checks plus CPU block-float checks: 370 passed, 11 hardware/dependency skips; repository Ruff passed. Native GPU execution remains unqualified on this CPU-only environment.

@Qubitium
Qubitium merged commit e44bb70 into main Nov 16, 2026
8 of 9 checks passed
@Qubitium
Qubitium deleted the backend-config-api branch November 16, 2026 10:36
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