Skip to content

Add quantize operator (bfloat16 → int8) - #98

Closed
albiol2004 wants to merge 2 commits into
amd:develfrom
albiol2004:quantize-bf16-i8
Closed

albiol2004 wants to merge 2 commits into
amd:develfrom
albiol2004:quantize-bf16-i8

Conversation

@albiol2004

@albiol2004 albiol2004 commented Apr 9, 2026 •

Copy link
Copy Markdown
Contributor

Added

  • aie_kernels/generic/quantize_bf16_i8.cc : C++ AIE kernel that quantizes bfloat16 values to int8 with per-group symmetric scaling. Two-pass: find max absolute value per group, then scale/round/saturate.
  • iron/operators/quantize/ : Python operator (op.py, design.py, reference.py, test.py) following the existing dequant/ pattern.

Changed

Nothing. This is a new operator with no modifications to existing code.

Removed

Nothing.

Motivation

Completes the W8A8 quantized inference pipeline for the NPU:

  1. Quantize (bf16 → i8) — this PR
  2. INT8 GEMM (i8 × i8 → i32) — INT8 GEMM support #93
  3. Dequant (i32 → bf16) — Add dequantize operator (int32 → bfloat16) #95

Together these three operators enable end-to-end quantized matrix multiplication on the NPU without CPU roundtrips, leveraging the NPU's ~50 TOPs INT8 throughput.

Test results

  • 32/32 parametrized tests pass (input lengths 1K–8K, 1–8 columns, 1–2 channels)
  • int8 output matches CPU reference exactly (matched rounding mode: half-away-from-zero)
  • Scale factors match within 1 ULP bf16 (AIE vs x86 division precision difference)

Notes

  • The inner round+saturate loop uses scalar operations. A future optimization could vectorize this with aie::to_fixed<int8> if supported on AIE2/AIE2P targets (marked with TODO).

Checklist

  Add a per-group symmetric quantization operator that converts bfloat16
  tensors to int8 with per-group scale factors. Completes the W8A8
  quantized inference pipeline alongside INT8 GEMM (amd#93) and dequant
  i32→bf16 (amd#95).

  - C++ kernel: two-pass (find max abs, then scale+round+saturate)
  - Python operator following existing dequant/ pattern
  - 32 parametrized tests (1-8 columns, 1-2 channels, 1K-8K elements)
Align operator directory name with the kernel file convention
(quantize_bf16_i8.cc). This establishes a consistent full
input_output type naming pattern for quantization operators.
@albiol2004 albiol2004 closed this Apr 10, 2026
@albiol2004

Copy link
Copy Markdown
Contributor Author

Very very suboptimal against fused kernels

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.

Add quantize operator (bf16->int8)

1 participant