Skip to content

feat(turbo): add int8/int4/fp16 record quantizers with scalar kernels, rework kernel dispatch - #624

Merged
JalinWang merged 8 commits into
alibaba:mainfrom
JalinWang:feat/turbo-int8
Aug 13, 2026
Merged

feat(turbo): add int8/int4/fp16 record quantizers with scalar kernels, rework kernel dispatch#624
JalinWang merged 8 commits into
alibaba:mainfrom
JalinWang:feat/turbo-int8

Conversation

@JalinWang

@JalinWang JalinWang commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Migrates the int8/int4 (record-quantized) and fp16 quantizers to the turbo framework, adds portable scalar distance kernels for them, and reworks the kernel dispatch registry so every row serves exactly one explicit QuantizeType. QuantizeType::kDefault is now deprecated.

What's Changed

Kernel dispatch rework (turbo.cc)

  • FindKernel arch semantics tightened: scalar rows only match kAuto/kScalar requests. An explicit SIMD arch request returns null when that ISA is unavailable, so callers keep their own (possibly SIMD-enabled) fallbacks instead of silently degrading to turbo scalar.
  • kDefault retirement:QuantizedIntegerMetric now requests kRecord + CpuArchType::kAVX512VNNI explicitly. Behavior is unchanged: VNNI machines get the same VNNI kernels as before; non-VNNI machines get null and keep the legacy ailego AVX2-dispatched fallback path.

New turbo quantizers

  • Int8Quantizer / Int4Quantizer (QuantizeType::kRecord): per-record scale/bias tail encoding, distance dispatch cached at init().
  • Fp16Quantizer (QuantizeType::kFp16).
  • Quantizer base: ctor now requires an explicit QuantizeType (explicit Quantizer(QuantizeType)); no more implicit kDefault.

New scalar distance kernels (universal fallback for non-VNNI targets)

  • scalar/fp16: cosine / inner-product / squared-euclidean.
  • scalar/record_quantized_int8: same three metrics, dim-20 (l2/ip) and dim-24 (cosine) record tail layout, formula-identical to the AVX512-VNNI kernels.
  • scalar/record_quantized_int4: same three metrics.

Testing

  • New: turbo_int8_quantizer_test, turbo_int4_quantizer_test, turbo_fp16_quantizer_test.
  • Passing: quantized_integer_metric_test (20), turbo_int8/int4/fp32/fp16_quantizer_test (3/4/2/3), built and run on an AVX512-VNNI machine (covers the VNNI dispatch path).

@JalinWang JalinWang changed the title feat(turbo): add int4/int8/fp16 quantizer & distance kernel table [Preview] feat(turbo): add int4/int8/fp16 quantizer & distance kernel table Jul 28, 2026
@JalinWang JalinWang changed the title feat(turbo): add int4/int8/fp16 quantizer & distance kernel table feat(turbo): add int8/int4/fp16 record quantizers with scalar kernels, rework kernel dispatch Jul 28, 2026
Comment thread src/turbo/quantizer/int8_quantizer/int8_quantizer.cc
Comment thread src/turbo/quantizer/int8_quantizer/int8_quantizer.cc
Comment thread src/include/zvec/turbo/turbo.h Outdated
Comment thread src/include/zvec/turbo/turbo.h Outdated
Per review: if get_distance_kernels returns an incomplete kernel set
(dist or batch missing, e.g. Euclidean/MipsSquaredEuclidean have no
dispatch rows), init() now logs an error and returns kErrUnsupported
instead of leaving the cached distance functions null and silently
returning 0 distances.
Per review:
- Remove the deprecated kDefault enumerator (no references remain);
  remaining enumerators keep their numeric values (kUniform = 1) since
  QuantizerSerHeader.quant_type reserves them for serialization.
- Add missing ZVEC_TURBO_API to get_distance_kernels and
  get_rotator_kernels for consistent symbol export.
# Conflicts:
#	src/include/zvec/turbo/turbo.h
#	src/turbo/distance/scalar/fp16/cosine.cc
#	src/turbo/distance/scalar/fp16/cosine.h
#	src/turbo/distance/scalar/fp16/inner_product.cc
#	src/turbo/distance/scalar/fp16/inner_product.h
#	src/turbo/distance/scalar/fp16/squared_euclidean.cc
#	src/turbo/distance/scalar/fp16/squared_euclidean.h
#	src/turbo/turbo.cc
@JalinWang
JalinWang requested a review from egolearner as a code owner August 13, 2026 07:46

@richyreachy richyreachy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@JalinWang
JalinWang merged commit ba31087 into alibaba:main Aug 13, 2026
15 checks passed
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.

3 participants