Skip to content

Fix SVS factory issue on non-SVS and non-LVQ platforms [MOD-9413] #664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

rfsaliev
Copy link
Collaborator

@rfsaliev rfsaliev commented Apr 17, 2025

Address issue with non-SVS and non-LVQ platforms

Which issues this PR fixes

Goal:
Ensure that the index creation process fails gracefully on unsupported platforms, avoiding any runtime crashes due to incompatible hardware or toolchain.
Currently, the index factory allows creating an LVQ index even on unsupported platforms. However, SVS performs a runtime CPU check, and if the platform doesn’t meet the requirements, it calls exit(1), abruptly terminating the process. This behavior should be avoided by preventing unsupported configurations earlier in the flow.
Proposed Solution:

  1. Add an early CPU check in the index factory. If the platform is not supported, the factory should fail the index creation with a clear error (return NULL), avoiding any SVS code paths that might fail the runtime check.
  2. Following that, implement tests to simulate and verify the behavior under different scenarios:
    Different build paths:
    a. What happens if a user tries to create an index on a platform that doesn’t meet the build requirements (GCC version, non X86, non intel…))
    b. What happens if the binary runs on a CPU that passes the build but fails the runtime check (e.g. AMD processors)?

Implemented Solution:
1. SVS Index Factory returns NULL in following cases:
- Platform does not meet SVS build requirements (macos, arm)
- Platform meets SVS build requirements but does not meet runtime requirements (LVQ on non-Intel CPU)

  1. Upon discussion with VecSim project maintainers, SVS Index Factory returns:
    • NULL if platform does not meet SVS integration requirements (MacOS, ARM, GCC<11.0)
    • The "fallback" non-quantized SVSIndex if LVQ is requested, but CPU does not meet requirements (e.g. non-Intel CPU).
    • SVSIndex with requested parameters if all SVS requirements are met.
  2. Tests to cover both cases:
    • Non-built platforms: just 1 tests expects NULL from SVS Index factory.
    • Other platforms: skip tests on runtime depending on index configuration and platform capabilities.

Main objects this PR modified

This pull request refactors and enhances the integration of Scalable Vector Search (SVS) within the project. The changes include simplifying build configurations, improving SVS feature support checks, and enhancing test coverage. The most notable updates ensure better compatibility and maintainability by removing conditional compilation in certain areas and adding runtime checks for SVS capabilities.

Build System Changes:

  • Removed the conditional svs_factory_file variable in cmake/svs.cmake and directly referenced index_factories/svs_factory.cpp in the build configuration (src/VecSim/CMakeLists.txt). This simplifies the build process by removing unnecessary indirection. [1] [2]

SVS Feature Support Enhancements:

  • Introduced a check_cpuid function and isSVSQuantBitsSupported utility in src/VecSim/algorithms/svs/svs_utils.h to verify CPU compatibility and supported quantization modes at runtime. This replaces compile-time checks for SVS features. [1] [2]
  • Updated svs_factory.cpp to use isSVSQuantBitsSupported for runtime validation of quantization modes and fallback handling. [1] [2]

Codebase Simplification:

  • Removed conditional compilation (#if HAVE_SVS) in index_factory.cpp to streamline the code and ensure SVS-related logic is always compiled, with runtime checks determining availability. [1] [2] [3] [4]

Testing Improvements:

  • Added a new test_svs executable in tests/unit/CMakeLists.txt without conditional compilation, ensuring tests are always built. [1] [2] [3]
  • Updated test_svs.cpp to use runtime checks (ASSERT_INDEX) for SVS feature support, replacing compile-time checks and skipping tests gracefully when unsupported. [1] [2] [3] [4]

Other Changes:

  • Added missing standard library includes in svs_utils.h to ensure compatibility and avoid potential build issues.

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

@rfsaliev rfsaliev requested a review from meiravgri April 17, 2025 15:16
@rfsaliev rfsaliev changed the title Rfsaliev/svs checks Fix SVS factory issue on non-SVS and non-LVQ platforms Apr 17, 2025
@rfsaliev rfsaliev force-pushed the rfsaliev/svs-checks branch from f21b91e to 7ddcc11 Compare April 17, 2025 15:22
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.34%. Comparing base (ed35da4) to head (6d567ba).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #664   +/-   ##
=======================================
  Coverage   96.33%   96.34%           
=======================================
  Files         112      112           
  Lines        6225     6239   +14     
=======================================
+ Hits         5997     6011   +14     
  Misses        228      228           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rfsaliev rfsaliev force-pushed the rfsaliev/svs-checks branch 3 times, most recently from d842254 to cbde213 Compare April 25, 2025 15:56
Base automatically changed from rfsaliev/install-mkl to main April 28, 2025 15:36
@rfsaliev rfsaliev force-pushed the rfsaliev/svs-checks branch from cbde213 to 1eb1cbf Compare April 28, 2025 17:05
@rfsaliev rfsaliev requested a review from alonre24 April 29, 2025 07:49
@alonre24 alonre24 changed the title Fix SVS factory issue on non-SVS and non-LVQ platforms Fix SVS factory issue on non-SVS and non-LVQ platforms [MOD-9413] Apr 29, 2025
Copy link
Collaborator

@alonre24 alonre24 left a comment

Choose a reason for hiding this comment

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

Looks good, few questions and requests for documentation

// If the quantization mode is not supported, we fallback to non-quantized mode
auto fallBack = supported ? quant_bits : VecSimSvsQuant_NONE;

// And always return true, as far as non-quantized mode is always supported
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please comment that this is temporary, and mark in TODO that the actual fallback should be the basic quantisation if check_cpuid() == false && quant_bits != VecSimSvsQuant_NONE once it is available in svs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comments

@@ -169,3 +180,11 @@ size_t EstimateInitialSize(const SVSParams *params, bool is_normalized) {
}

} // namespace SVSFactory

#else // HAVE_SVS
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please comment that this is temporary, and we should never get here - once svs public repo will allow building for all platforms and we address platforms with GCC < 11

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comment


#define ASSERT_INDEX(index) \
if (index == nullptr) { \
if (std::get<1>(svs_details::isSVSQuantBitsSupported(TypeParam::get_quant_bits()))) { \
Copy link
Collaborator

Choose a reason for hiding this comment

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

std::get<1>(svs_details::isSVSQuantBitsSupported(TypeParam::get_quant_bits())) always returns true currenly right? Can you explain the purpose of this assertion (now and in the future)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added comment

@rfsaliev rfsaliev force-pushed the rfsaliev/svs-checks branch from 472465b to 6d567ba Compare April 30, 2025 12:46
@rfsaliev rfsaliev requested a review from alonre24 April 30, 2025 13:13
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