Skip to content

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

Open
JalinWang wants to merge 4 commits into
alibaba:mainfrom
JalinWang:feat/turbo-int8
Open

feat(turbo): add int8/int4/fp16 record quantizers with scalar kernels, rework kernel dispatch#624
JalinWang wants to merge 4 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

// Cache the distance dispatch for the new Quantizer interface.
auto kernels =
get_distance_kernels(metric_from_name(metric_name), DataType::kInt8,

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.

这里应该需要校验get_distance_kernels是否成功了。
如果失败的话dp_query_func_/dp_query_batch_func_应该全是nullptr,是否符合预期?

// monotonically equivalent distance (same convention as Fp32Quantizer).
distance_offset_ = 1.0f;
extra_meta_size_ += EXTRA_META_SIZE_COSINE;
}

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.

else的情况下,distance_offset_和extra_meta_size_是否需要初始化?


// Aggregate lookup: resolves dist/batch/preprocess in one pass so callers
// cannot pair functions from different kernel families.
DistanceKernels get_distance_kernels(

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.

这里为何不定义ZVEC_TURBO_API?

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.

2 participants