Add fake_quantize_per_channel_affine operator with Triton kernel - #5450
Open
xuanzhengdu-eng wants to merge 3 commits into
Open
Add fake_quantize_per_channel_affine operator with Triton kernel#5450xuanzhengdu-eng wants to merge 3 commits into
xuanzhengdu-eng wants to merge 3 commits into
Conversation
- Implement Triton kernel for per-channel fake quantization - Add accuracy tests with multiple shapes and axis configurations - Add performance benchmark - Register in operators.yaml All tests passed (14/14).
xuanzhengdu-eng
requested review from
0x45f,
103yiran,
Caeruleann,
bin913,
douxetpur,
hellojack163,
huangyiqun,
tengqm and
w1120029931-bit
as code owners
August 13, 2026 09:20
Signed-off-by: xuanzhengdu-eng <xuanzhengdu@gmail.com>
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 a Triton implementation of
aten.fake_quantize_per_channel_affinefor per-channel affine fake quantization.The implementation adds the required ATen-compatible behavior:
scaleandzero_pointto every channel along the selected axis.[quant_min, quant_max]range before dequantization.conf/operators.yaml.The kernel was generated and iteratively corrected with KernelGen.
Testing
Tested on an NVIDIA H20-3e with PyTorch reference results.
Accuracy tests:
Result:
Coverage includes:
[0, 255]and signed[-128, 127]quantization rangesComprehensive benchmark:
Result:
Pre-commit checks:
Result:
git diff --check upstream/master...HEADalso passed.Performance
Performance was measured on an NVIDIA H20-3e using the standard FlagGems benchmark framework in kernel mode. All 42 dtype/shape/axis cases completed successfully.
FP16
[4, 4][4, 4][64, 64][64, 64][128, 256][128, 256][512, 512][512, 512][1024, 1024][1024, 1024][2, 3, 128, 128][2, 3, 128, 128][8, 16, 64, 64][8, 16, 64, 64]Average FP16 speedup across these cases: 8.981x.
FP32
[4, 4][4, 4][64, 64][64, 64][128, 256][128, 256][512, 512][512, 512][1024, 1024][1024, 1024][2, 3, 128, 128][2, 3, 128, 128][8, 16, 64, 64][8, 16, 64, 64]Average FP32 speedup across these cases: 8.283x.
BF16
[4, 4][4, 4][64, 64][64, 64][128, 256][128, 256][512, 512][512, 512][1024, 1024][1024, 1024][2, 3, 128, 128][2, 3, 128, 128][8, 16, 64, 64][8, 16, 64, 64]Average BF16 speedup across these cases: 8.998x.
Combined arithmetic average speedup across all 42 cases: 8.754x. Every measured case is faster than the PyTorch reference, with speedups ranging from 7.286x to 10.079x.
Files changed
src/flag_gems/ops/fake_quantize_per_channel_affine.pytests/test_fake_quantize_per_channel_affine.pybenchmark/test_fake_quantize_per_channel_affine.pysrc/flag_gems/ops/__init__.pysrc/flag_gems/__init__.pyfake_quantize_per_channel_affinein_FULL_CONFIG.conf/operators.yamlKernelGenlabel andalpha: '5.4'stage.