[MOD-17916] Bound native FP16 dispatch without hot-path overhead - #1021
[MOD-17916] Bound native FP16 dispatch without hot-path overhead#1021dor-forer wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1021 +/- ##
=======================================
Coverage 97.28% 97.28%
=======================================
Files 141 141
Lines 8624 8630 +6
=======================================
+ Hits 8390 8396 +6
Misses 234 234 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
4788e5d to
bd65260
Compare
bd65260 to
04aa990
Compare
04aa990 to
37c7c04
Compare
37c7c04 to
fd9ebd9
Compare
fd9ebd9 to
930bc73
Compare
930bc73 to
9702a42
Compare
9702a42 to
597daff
Compare
597daff to
604a1de
Compare
f78f556 to
c1e2643
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c1ef771. Configure here.
| mandatory = {label for label, distance in exact_distances.items() | ||
| if distance < cutoff * (1 - FLOAT16_NATIVE_RTOL)} | ||
| allowed = {label for label, distance in exact_distances.items() | ||
| if distance <= cutoff * (1 + FLOAT16_NATIVE_RTOL)} |
There was a problem hiding this comment.
KNN tolerance bands ignore two-sided error
Low Severity
assert_float16_l2_knn builds mandatory and allowed with one-sided factors 1 ± rtol around the exact k-th distance. KNN ranking compares two noisy scores, so both the candidate and the cutoff neighbor can each move by rtol. Guaranteed members need a tighter band near (1 - rtol) / (1 + rtol), and the allowed set needs a wider one near (1 + rtol) / (1 - rtol). As written, the helper can fail on label sets that still satisfy the 1% native-FP16 contract.
Reviewed by Cursor Bugbot for commit c1ef771. Configure here.


Describe the changes
This PR adds conservative dimension guardrails around native-FP16 distance functions without
adding work to their hot loops.
conservative dispatch heuristic, not as an input-range contract.
1.0fin FP32, avoidingan additional half-precision rounding near 1.
The cap is checked once when the distance function is selected. AVX512FP16, NEON_HP, SVE, and SVE2
kernels below the cap retain their native-FP16 accumulation and reduction loops, with no added
branch, conversion, or fallback cost per distance calculation.
Correctness boundary
IP and L2 inputs are not required to be in
[-1, 1]. There is no universally safe positivedimension for arbitrary native-FP16 arithmetic: a single product or squared difference can
overflow. These caps are guardrails against dimension-driven overflow for unit-scale data; they
are not a general overflow guarantee, and sufficiently large values can overflow below the caps.
Native-FP16 arithmetic is also approximate by design. Subtraction, lane FMAs, and final reduction
can round ordinary finite L2 scores differently from scalar FP32 accumulation. FLOAT16 L2 flow tests
therefore validate the existing 1% native-kernel accuracy contract, including score ties and labels
near a KNN or range boundary, rather than requiring bitwise-equivalent rankings across runner CPUs.
Other data types and metrics retain their existing strict checks.
Performance decision
is worth the implementation-tier change.
common-path cost and do not repair rounding that already occurred in native-FP16 lane arithmetic.
Tests
the documented 1% tolerance.
accuracy contract.
Local verification:
test_spacespassed.test_spaces: 1,587 tests passed (one hardware-dependent case skipped locally).git diff --checkpassed.enabled.
Which issue this PR fixes
Related performance work: MOD-16688 / PR #984.
Files modified
src/VecSim/spaces/spaces.hsrc/VecSim/spaces/IP_space.cppsrc/VecSim/spaces/L2_space.cppsrc/VecSim/spaces/IP/IP_AVX512FP16_VL_FP16.htests/unit/test_spaces.cpptests/flow/common.pytests/flow/test_bruteforce.pytests/flow/test_hnsw.pyMark if applicable
Note
Medium Risk
Changes which distance kernel runs for large FP16 dimensions and alters AVX512 FP16 IP numerics near 1.0; behavior is guarded and heavily tested but affects core search scoring.
Overview
Adds one-time dimension caps so native half-precision IP/L2 SIMD is only chosen below conservative limits (IP through 65,504, L2 through 16,376); larger dimensions fall back to existing wider-accumulator/scalar paths with no per-distance overhead.
On AVX512 FP16+VL inner product, the kernel now uses dual FMA accumulators and a 64-element specialization loop, and computes
1.0f − dotin FP32 after reduction to avoid extra rounding near distance 1.Tests pin dispatch at/above the caps, verify high-dimension overflow guardrails, and relax FLOAT16 L2 flow/HNSW checks to the documented 1% native-kernel tolerance (including ties and range boundaries) instead of exact FP32 equality.
Reviewed by Cursor Bugbot for commit 92452fb. Bugbot is set up for automated code reviews on this repo. Configure here.