Repository navigation
feat(humming): port the Humming CUDA GEMM backend - #5966
Merged
Merged
Conversation
Port the vLLM/SGLang Humming integration as an optional GPT-QModel backend. Humming owns the packed layouts, so post_init() converts the checkpoint tensors through Humming's own schema objects and forward() calls humming_forward(); no CUDA source is vendored into gptqmodel_ext. - BACKEND.HUMMING with gptq_humming/awq_humming legacy aliases - HummingLinear (GPTQ W2/W4/W8) and AwqHummingLinear (AWQ W4) - import-guarded, SM75+ CUDA-only, opt-in via format priority 0 - 27 registration/numeric tests, docs page, CREDITS entry
Qubitium
marked this pull request as ready for review
November 21, 2026 04:34
Extend the shared Humming backend beyond GPTQ/AWQ integer weight-only kernels with two float sub-kernels, and generalize the mixin so each sub-kernel names its own checkpoint operands. * `HummingFP8Linear` (METHOD.FP8, FORMAT.FP8): E4M3 `weight` + float32 `weight_scale_inv`, supporting tensor / row / block scale layouts and both inverse and multiplier scale semantics. Rejects per-token activation scaling (weight-only A16 path). * `HummingMXFP4Linear` (METHOD.MACAQ, FORMAT.MXFP4): zero-copy handoff of MACaQ's nibble-packed E2M1 weights and E8M0 block scales, whose layout is byte-identical to humming's. Rejects MACaQ-rotated checkpoints. * `prepare_humming_fp8_tensors` / `prepare_humming_mxfp4_tensors` in `gptqmodel/utils/humming.py`. * `_HummingKernelMixin` gains `HUMMING_WEIGHT_ATTR` / `HUMMING_SCALE_ATTR` / `HUMMING_ZERO_POINT_ATTR` so GPTQ/AWQ keep `qweight`/`scales`/`qzeros` while FP8 and MXFP4 reuse their native checkpoint buffers. Both kernels register with priority 0, i.e. explicit selection only; humming JIT-compiles one kernel per layer shape so it never silently displaces the default kernel. Neither is a repack source. Validated on RTX 4090 (SM89) and RTX 5090 (SM120); see docs/humming.md for the measured error tables.
Both humming modules assigned `log = setup_logger()` without ever using it. Remove the assignment and the now-unused import, as flagged by the code-quality review on #5966.
Qubitium
added a commit
that referenced
this pull request
Nov 22, 2026
…rip, PARO/offload, LFM3 tests) (#5980) * fix(awq): restore scale search for PanGu, Bailing-MoE, Nemotron-H, Inkling2 #5978 deferred AWQ scaling for four families by returning empty fold groups. Restore every group that measures output-neutral on the real forward and keep only the folds that are provably non-neutral: - gpt_pangu: generic planner, minus the top block's `attn.q_proj` in the `ln_1` group (it consumes `custom_query`, not the norm). `ln_1 -> k/v`, `attn.v_proj -> attn.c_proj`, `ln_2 -> mlp.c_fc` are neutral; the `c_fc -> c_proj` source stays `nosrc`. - bailing_moe: drop the `isinstance(BailingConfig): return []` override and use the generic planner. All groups are neutral on dense/mla/hybrid/ legacy_gqa (worst 1.9e-07). - nemotron_h: generic planner for dense Mamba/attention/MLP mixers. Only the native `NemotronHMoE` mixer stays plain (one norm feeds shared and routed experts; shared-only fold 2.4e-2). Also move `A_log`/`D`/`dt_bias` out of the `mixer` tuple: as Parameters they closed the q/k/v subset and folded `o_proj` from the block norm (8.1e-2). - inkling2_loop: keep the per-expert `up_proj -> down_proj` folds (1.9e-07..3.5e-06). Drop the tree-order `post_attention_layernorm` and `o_proj.linear -> gate_proj` groups, which follow module order rather than data flow and change the layer output by 8e-2..4e-1. Tests pin neutrality on production configs and pin the dropped folds as non-neutral, so a future planner change cannot silently reintroduce them. * fix(quantize): honor the quantization device dtype and leave the model in eval Three independent round-trip bugs that made an in-session model disagree with the checkpoint it just saved: - loader: auto dtype only followed `quantize_config.device` for MiMo sources. On an MPS/CUDA host a CPU quantization therefore loaded and re-saved the dense source in the host dtype (fp16) while a CPU reload resolved bf16, so the round trip was not dtype-preserving. Honor the quantization device for every `BaseQuantizeConfig`. - torch qlinear: wide `_decode_248_weight` cast fp16 scales to bf16 before the multiply while the fused/compiled path multiplies in fp32 and rounds once. Compute wide decodes in fp32 (fp64 when requested) and cast the product once, so eager and compiled decode are bitwise equal (#5740). - base: the quantize loop installs fresh kernel modules that start in training mode; their `train` transition also restores the checkpoint zero-point layout. Call `model.eval()` at the end of `quantize()` so an in-session forward decodes through the same path as the saved checkpoint. * fix: stop a PARO placeholder rotation and a cached import traceback from failing runs - paro_processor: `pack_module()` treated the minimal placeholder triple `pairs=(1,)`, `theta=(1,)`, `channel_scales=(1,)` used by packing-only callers as real rotation state and raised the #5659 `(8,128)` vs `(1,)` shape error. Keep the freshly built layer's identity rotation for that exact placeholder; a real krot mismatch still raises. - humming: the optional-import `ModuleNotFoundError` was cached with its traceback. Kernel discovery imports every qlinear module from inside `quantize()`, so the retained stack pinned the model and its run-exit state; `del model` could never run the offload finalizer and left `offload/run-*` behind (#4595). Clear `__traceback__`/`__context__`/ `__cause__`; type and message are unchanged. * test: record Humming as fusion-excluded and fix the PARO looper stub - test_fusion_kernel_backends: `HummingLinear`/`AwqHummingLinear` were added by #5966 without a fusion spec or an `EXCLUDED` entry, so the registry contract failed. Humming's `post_init()` replaces checkpoint tensors with shape-padded JIT operands and a per-layer `LayerConfig`; there is no concatenable native layout, so list both as excluded with that rationale. - test_paro: `_replay_layer_outputs()` now always passes `consume_inputs=` (since #5928) but the first `_DummyLooper` stub kept the old signature. Accept and discard the keyword; test semantics are unchanged. * test(lfm3): match the shipped AWQ fold contract #5978 suppresses the `operator_norm -> q/k/v` fold on LFM3 attention layers because the sigmoid gate consumer is left on the divided norm (uncompensated delta 5.5e-2; compensating it rewrites non-quantized gate weights). The conv layer still folds both input norms. Update the LFM3 tests to that contract instead of the pre-#5978 expectation, and pin the suppression plus its measured error so the decision is explicit. * test(fusion): skip the TorchInt8Linear cache-race pair on darwin `TorchInt8Linear` has no darwin implementation, so the two race tests failed with a backend-availability error rather than exercising the cache. Gate the module on the platform the kernel supports.
3 tasks done
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
Ports the Humming weight-only CUDA GEMM into GPT-QModel as the opt-in
BACKEND.HUMMING.Humming is the Apache-2.0 JIT-compiled W1–W8 kernel library both projects consume through the optional
humming-kernelsPyPI package, so nothing is vendored intogptqmodel_ext:gptqmodel/utils/humming.pyis the only module that imports it, and a missing package degrades into a normal kernel-selection
rejection instead of an import error.
The same backend also serves two float sub-kernels — FP8 (E4M3) and OCP MXFP4 — so
BACKEND.HUMMINGis a single opt-in target for GPTQ, AWQ, FP8 and MXFP4 checkpoints.What Changed
gptqmodel/utils/backend.py:BACKEND.HUMMING, plusgptq_humming/awq_humminglegacy aliases.gptqmodel/utils/humming.py(new): import guard, SM75+/CUDA-only device gates,humming-kernelsschema conversion, per-layer Stream-K
locks, and the explicit compute policy.gptqmodel/nn_modules/qlinear/humming.py(new):HummingLinear(GPTQ W2/W4/W8),AwqHummingLinear(AWQ W4),HummingFP8Linear(FP8 E4M3) andHummingMXFP4Linear(OCP MXFP4).post_init()converts the checkpoint tensors once through Humming's ownGPTQWeightSchema/AWQWeightSchema/Fp8WeightSchema/Mxfp4WeightSchema;forward()callshumming_forward().A shared
_HummingKernelMixinlets each sub-kernel name its own checkpoint operands(
HUMMING_WEIGHT_ATTR/HUMMING_SCALE_ATTR/HUMMING_ZERO_POINT_ATTR), so GPTQ/AWQ keepqweight/scales/qzeroswhile FP8 and MXFP4 reuse their native buffers.prepare_humming_fp8_tensorscovers the three FP8 scale layouts (tensor,row,block) andnormalizes
weight_scale_invinto Humming's multiplier convention;prepare_humming_mxfp4_tensorsis a zero-copy handoff because MACaQ's nibble-packed E2M1 weightsand E8M0 block scales are already byte-identical to Humming's layout.
gptqmodel/utils/packing.py: both kernels are ABI-transforming afterpost_init(), so they arerejected as repack sources (same rule as Marlin/Machete/Swordfish/BitBLAS).
tests/kernels/test_humming.py(new): 35 registration and numeric tests.docs/humming.md(new),docs/support-matrix.md,docs/hf_packing_api.md,CREDITS.md,tests/test_backend_naming.py,tests/test_rocm_kernel_contracts.py(CUDA-only inventory).Behavior notes:
SUPPORTS_FORMATSpriority0registers the kernels for explicit selection whileleaving
BACKEND.AUTOon the existing default kernels (Humming JIT-compiles one image per shape).post_init()replaces the checkpoint tensors with Humming's transformed operands, so a loaded layeris inference-only, exactly like Marlin/Swordfish.
(
humming_compute_config(batch_invariant=..., f16_accum=...)), and layers always run thedeterministic dense/fp32-accumulate default.
(different word packing), GPTQ
desc_act=True, ROCm, CPU, non-SM75 devices.Tests
Hardware/runtime: 1× RTX 4090 (SM89), CUDA 13.2, torch 2.15.0+cu132, Python 3.14,
humming-kernels==0.1.20. No mocks were used for the numeric cases.pytest tests/kernels/test_humming.py tests/test_backend_naming.py tests/test_rocm_kernel_contracts.py \ tests/kernels/test_selection.py tests/kernels/test_qlinear_hierarchy.py \ tests/test_hf_packing_api.py tests/test_packing_numeric_boundaries.py -q ruff check gptqmodel docs/eora tests setup.py # ruff 0.14.2 (CI pin)tests/kernels/test_humming.pytests/test_backend_naming.pytests/test_rocm_kernel_contracts.pytests/kernels/test_selection.pytests/kernels/test_qlinear_hierarchy.pytests/test_hf_packing_api.pytests/test_packing_numeric_boundaries.pyruff check(repo-wide, 0.14.2)The 3 failures are pre-existing on pristine
origin/main(d4712ee1) and unrelated to this branch;each was reproduced in a clean detached worktree at the same base revision:
tests/test_rocm_kernel_contracts.py::test_hip_shims_provide_every_cuda_only_intrinsic_used_under_hiptests/test_hf_packing_api.py::test_hf_repack_layer_between_compatible_kernelstests/test_hf_packing_api.py::test_gpu_feasibility_and_best_formatKernel numerics vs an independent Torch FP32 oracle
fp16 weights/activations, K=512 / N=256 unless noted, batch 13 (GPTQ) or 9 (AWQ). The oracle
dequantizes the packed codes in FP32 and rounds the dequantized weight to the kernel's compute dtype
before an FP32 matmul; the visible output is compared after its mandatory output-dtype rounding.
Normalizedis||got - ref|| / ||ref||(Frobenius), the repository's 2e-3 inference gate.refmean absThe bf16 tile-misaligned case (
in=384, out=200, gs=128, output shape3×7×200) stays within onebf16 output ulp elementwise and 2.81e-3 normalized against the fp32 oracle (bound 4e-3 for bf16's
8-bit weight-dequantization mantissa; the fp16 cases use 2e-3).
End-to-end logits (Qwen2.5-0.5B, 168 converted layers)
Fixed 2×16 token IDs, fp16,
device="cuda:0". Each backend loaded the same checkpoint in a separateprocess.
Normalizedis||a - b|| / ||b||.Humming's distance from the Torch reference is the same order as Marlin's own distance from it
(GPTQ 3.81e-3 vs 3.16e-3; AWQ 4.65e-3 vs 6.21e-3), and the large AWQ max-abs outliers are shared by
Marlin. The model-level drift accumulates over 24 layers; the per-layer kernel error is the 3e-4
normalized value in the table above.
Determinism
humming_compute_config(batch_invariant=True)Humming's Stream-K reduction may reorder partial tiles; the batch-invariant policy pins that order and
is available through an explicit argument, never an environment variable.
Coverage and limits
FORMAT.GPTQ,FORMAT.GPTQ_V2), AWQ (FORMAT.GEMM), FP8 (FORMAT.FP8), MACaQ (FORMAT.MXFP4)sym=Trueandsym=False(GPTQ v1 qzeros corrected before packing); N/A for FP8/MXFP4torch.float16,torch.bfloat16in_features/out_features; operands padded to 128×256 tiles internallySUPPORTS_SHARDS/SUPPORTS_SHARDED_LOADSUPPORTS_TRAINING = False)desc_act=True, FP8 per-token activation scaling, MACaQ-rotated MXFP4 (rotation/pre_mode!=none)Measured Impact
This is a new backend, so the comparison is Humming against the existing Marlin and Torch kernels on
the same checkpoint, hardware and settings; there is no "before" revision that shipped Humming.
Conditions: Qwen2.5-0.5B (24 layers, 168 converted linears), batch 1, fp16,
device="cuda:0",RTX 4090 (SM89), CUDA 13.2, torch 2.15.0+cu132,
humming-kernels==0.1.20. Latencies are medians ofsynchronized iterations after warmup: 8× prefill-512, 5× prefill-2048, 20× decode-M=1;
generateis32 prompt + 32 greedy new tokens, median of 5. Each backend was loaded in a separate process.
for AWQ, while running ~2× the Torch kernels.
larger M, and model-level M=1 is dominated by fixed per-step overhead rather than the GEMM.
Cold 1st forward; steady-state numbers exclude it. This is why the backend is opt-in and not inBACKEND.AUTO.dense weight copy is retained.
Additional Formats (FP8 / MXFP4)
Two float sub-kernels extend the same backend. Both are weight-only (A16) and register with
SUPPORTS_FORMATSpriority0, so they are explicit-selection only, exactly like the GPTQ/AWQsub-kernels.
HummingFP8LinearMETHOD.FP8FORMAT.FP8weight(E4M3),weight_scale_inv(fp32)HummingMXFP4LinearMETHOD.MACAQFORMAT.MXFP4W_packed(uint8 E2M1),W_scales(uint8 E8M0)Weight-only numerics (A16), fp16 compute
relL2 = ||kernel - oracle|| / ||oracle||against a torch FP32 dequantized oracle,Min{1, 4, 16, 64, 128}, N=256, K=512.
relL2is dominated by the mandatory fp16 output rounding, so~2e-4 is the floor rather than an error budget. Worst case over
Mis shown; all 26 cells passed.mma.syncmma.syncmma.syncmma.syncmma.syncmma.syncOn SM89 the float rows run
MmaType.MMAwith register dequant; on SM120 they takeuse_native_dequant=True.Block-scaled MMA (needs quantized activations)
These recipes additionally quantize the input, so they are documented as library capability rather
than exposed through GPT-QModel today:
scale_vec::2X, E8M0)scale_vec::4X, E4M3)scale_vec::1X, E8M0)Wiring decisions
FORMAT.FP8checkpoint layout, so an FP8 checkpoint can be served byeither
TorchFP8LinearorHummingFP8Linear.post_init()normalizesweight_scale_invintoHumming's multiplier convention; both
inverseandmultipliersemantics are accepted.activation_quant_method="per_token"is rejected at construction with an actionable error.(
rotation/pre_modeother thannone) and block sizes other than 32 are rejected.modelopt/compressed-tensorsin Humming). It would need a new schema plus loader, which is out of scope here.only by a future activation-quantizing backend.
hf_check_packing_feasibility(..., repack=True)returnsFalse), becausepost_init()replaces the checkpoint tensors in place.Host coverage
End-to-end checkpoint loads (real production checkpoints)
The rows above are layer-level. These load real saved checkpoints through
GPTQModel.load(..., backend=BACKEND.HUMMING)and compare model logits against the backend thatnormally serves the same file. Fixed 1x16 token IDs, fp16/fp32 logits.
Qwen/Qwen3-0.6B-FP8(block 128x128)BACKEND.TORCHrotation="none")BACKEND.MACAQ_TORCHThose deltas are dominated by each checkpoint's own quantization error, not by the kernel. Measured
against the unquantized original:
Humming is at or slightly closer to the unquantized model than the incumbent backend on both formats,
so the inter-backend numbers above are two approximations of a lossy checkpoint, not a regression.
Per-projection agreement on identical inputs (layer 0, same checkpoint, same activation tensor):
q_projk_projv_projo_projgate_projup_projdown_projBoth backends sit ~2e-3 from an exact FP32 dequant oracle on the FP8 shapes, which is the bf16
output-rounding floor; the larger
o_proj/down_projdeltas are tiling differences onN < Kshapes, not scale-handling errors (a full-mantissa block-scale stress test produced bit-identical
output whether the scales were kept in FP32 or cast to the compute dtype).
Note that plain MXFP4 (
rotation="none",pre_mode="none") is intentionally the low-accuracy export:~0.49 normalized from the original on Qwen2.5-0.5B. The rotated default (
FORMAT.MXFP4_MACAQ) keepsthe Hadamard transform and is not served by this backend.
Model Support / Module Plan
Not applicable: no
MODEL_MAP, model definition, alias or module-plan change. The new classes areinference kernels selected by
BACKEND.HUMMING;tests/kernels/test_selection.pyandtests/kernels/test_qlinear_hierarchy.pypass unchanged.AWQ onboarding safety
Not applicable: no new model or AWQ grouping/search/replay/fold change.
AwqHummingLinearconsumes theexisting classic interleaved
FORMAT.GEMMlayout through Humming'sAWQWeightSchema.Logic Flow Documentation
Not applicable: the change adds an opt-in backend with format priority
0, soBACKEND.AUTOselection order is unchanged.
docs/humming.mddocuments the new conversion and forward path,including the failure paths (missing package, ROCm, CPU, unsupported bits/desc_act).
Review Requirements
SwordfishLinear/MarlinLinearconventions:post_init()conversion,SUPPORTS_*declarations,validate_once).BACKENDenum,SUPPORTS_FORMATS, importerdiscovery) with no monkeypatching in the implementation.
gptqmodel_exttarget, one import-guardedfacade module.
Kernel Accuracy Requirements
test_rocm_kernel_contracts.py(
HummingLinear/AwqHummingLinearare in the CUDA-only audit set).Notes
humming-kernelsis an optional runtime dependency; CI without it still importsgptqmodel, andthe numeric tests skip with a precise reason.
validate_once()reports the install hint.checkpoint-format kernel first.