Repository navigation
perf(cpu): tune and validate optimized quantized kernels - #3430
Merged
Merged
Conversation
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
64 <= M <= 256window for512x512BF16 layers. The path uses bounded feature tiles and never retains a dense weight.2e-3.int4_qzero_group_scaled_cpukernel for group sizes 32, 64, 128, 256, and 512.Storage Guarantee
Inference retains only native packed quantized weights, scales, zero points, and bias. No dense, dequantized, expanded, or INT4-to-INT8 weight cache is retained after a forward, including in repeated calls, warmup, fallback paths, and compiled/JIT paths. BnB INT8 and GGUF fused CPU forward use temporary bounded chunks/tiles released after the consuming operation.
Regression coverage checks repeated forwards and verifies that the persistent buffers remain the packed
qweight/biasrepresentation. No additional dense weight bytes are retained.Accuracy
Environment: AMD EPYC 9V33X, AVX512-BF16, 8 Torch intra-op threads, Torch
2.16.0.dev20261021+cpu, torchao0.18.0+cpu, Python 3.14.4. Shape is512x512; errors are normalized L2 against an independent FP32 Torch matmul of the same dequantized weight. Values are the maximum observed overM = 1, 7, 32, 128, 512.ATen is an external comparison and is shown for context; its observed error is not the acceptance gate for this kernel. ATen supports group sizes 32/64/128/256, so group 512 has no ATen comparison.
BnB INT8 uses an independent A8W8 oracle for the native path and an A16 dequantize-and-matmul oracle for the tiled path:
BnB packed 4-bit CPU remains opt-in: its measured normalized error is
3.3e-3to3.8e-3, above the2e-3gate, so it is rejected rather than silently used.Speed
GPTQ and AWQ vs ATen
Median per-call wall time, milliseconds,
512x512, 8 threads, 5 warmup, 20 iterations.ours/ATenshows the speedup.Other CPU paths at group 128, M=7/128/512
int4_qzero_group_scaled_cpuint4packInt4OpaqueTensor)torchao A16W4 uses a different affine quantizer and calls ATen's
_weight_int4pack_mm_for_cpu; its error is not GPTQ kernel error. oneDNN W8A8 is also a different precision/quantizer. Both are included as context, not as byte-identical implementations.GGUF fused CPU,
512x512, M=7The per-shape autotuner selects the dense path for Q4_0 where fused loses.
HF Kernels Compatibility
0.17.2is the latest PyPI stable release as of 2026-10-23; the validation environment also tested0.18.0.dev0.2.10through2.15. There is no build variant for2.16.0.dev20261021+cpu, sokernels.get_kernelcannot load a prebuilt CPU binary.mslkis not installed. PyPI currently exposes only the placeholdermslk 0.0.0, not a usable kernel package. torchao DA8W4 therefore remains unavailable; torchao A16W4 works without mslk.Validation
78 passed, 40 skipped, 1 failed; the single failure is the unrelated pre-existingtest_gguf_triton_kernel_rejects_unsupported_formats, which raisesModuleNotFoundError: tritonbefore reaching the format assertion.80 passed, including group sizes 256 and 512.2.14.1+cpu:55 passed, 63 skipped, 1 failedwith the same unrelated missing-Triton failure.ruff,py_compile, andgit diff --checkpass.64..256gate and repeated-forward packed-storage retention.Notes
int4_qzero_group_scaled_cpuis intentionally format-specific: it describes the affine zero-point/group-scale format shared by GPTQ and AWQ, rather than all INT4 quantization algorithms.