Skip to content

fix fit memory test #461

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

Merged
merged 4 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .github/workflows/event-merge-to-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ jobs:
uses: ./.github/workflows/task-unit-test.yml
with:
container: ubuntu:bionic
xenial:
needs: [check-if-docs-only]
if: ${{ needs.check-if-docs-only.outputs.only-docs-changed == 'false' }}
uses: ./.github/workflows/task-unit-test.yml
with:
container: ubuntu:xenial
bullseye:
needs: [check-if-docs-only]
if: ${{ needs.check-if-docs-only.outputs.only-docs-changed == 'false' }}
Expand Down Expand Up @@ -88,7 +82,6 @@ jobs:
- jammy
- focal
- bionic
- xenial
- bullseye
- centos7
- amazonlinux2
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/event-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ jobs:
with:
container: ubuntu:bionic
run-valgrind: false
xenial:
uses: ./.github/workflows/task-unit-test.yml
with:
container: ubuntu:xenial
run-valgrind: false
bullseye:
uses: ./.github/workflows/task-unit-test.yml
with:
Expand Down
1 change: 1 addition & 0 deletions src/VecSim/algorithms/hnsw/hnsw_tiered_tests_friends.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ INDEX_TEST_FRIEND_CLASS(HNSWTieredIndexTestBasic_overwriteVectorBasic_Test)
INDEX_TEST_FRIEND_CLASS(HNSWTieredIndexTestBasic_overwriteVectorAsync_Test)
INDEX_TEST_FRIEND_CLASS(HNSWTieredIndexTestBasic_preferAdHocOptimization_Test)
INDEX_TEST_FRIEND_CLASS(HNSWTieredIndexTestBasic_runGCAPI_Test)
INDEX_TEST_FRIEND_CLASS(HNSWTieredIndexTestBasic_FitMemoryTest_Test)

friend class BF16TieredTest;

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_bf16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ class BF16HNSWTest : public BF16Test {
dim = params.dim;
}

virtual const void *GetDataByInternalId(idType id) {
virtual const void *GetDataByInternalId(idType id) override {
return CastIndex<HNSWIndex_Single<bfloat16, float>>()->getDataByInternalId(id);
}

HNSWIndex<bfloat16, float> *CastToHNSW(VecSimIndex *new_index) {
return CastIndex<HNSWIndex<bfloat16, float>>(new_index);
}

virtual HNSWIndex<bfloat16, float> *CastToHNSW() {
virtual HNSWIndex<bfloat16, float> *CastToHNSW() override {
return CastIndex<HNSWIndex<bfloat16, float>>(index);
}

Expand All @@ -126,11 +126,11 @@ class BF16BruteForceTest : public BF16Test {
dim = params.dim;
}

virtual const void *GetDataByInternalId(idType id) {
virtual const void *GetDataByInternalId(idType id) override {
return CastIndex<BruteForceIndex_Single<bfloat16, float>>()->getDataByInternalId(id);
}

virtual HNSWIndex<bfloat16, float> *CastToHNSW() {
virtual HNSWIndex<bfloat16, float> *CastToHNSW() override {
ADD_FAILURE() << "BF16BruteForceTest::CastToHNSW() this method should not be called";
return nullptr;
}
Expand Down Expand Up @@ -170,12 +170,12 @@ class BF16TieredTest : public BF16Test {

virtual void TearDown() override {}

virtual const void *GetDataByInternalId(idType id) {
virtual const void *GetDataByInternalId(idType id) override {
return CastIndex<BruteForceIndex<bfloat16, float>>(CastToBruteForce())
->getDataByInternalId(id);
}

virtual HNSWIndex<bfloat16, float> *CastToHNSW() {
virtual HNSWIndex<bfloat16, float> *CastToHNSW() override {
auto tiered_index = dynamic_cast<TieredHNSWIndex<bfloat16, float> *>(index);
return tiered_index->getHNSWIndex();
}
Expand Down
15 changes: 11 additions & 4 deletions tests/unit/test_bruteforce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1590,15 +1590,22 @@ TYPED_TEST(BruteForceTest, rangeQueryCosine) {

TYPED_TEST(BruteForceTest, FitMemoryTest) {
size_t dim = 4;
BFParams params = {.dim = dim, .initialCapacity = 1, .blockSize = 5};
BFParams params = {.dim = dim, .initialCapacity = 100, .blockSize = DEFAULT_BLOCK_SIZE};
VecSimIndex *index = this->CreateNewIndex(params);

GenerateAndAddVector<TEST_DATA_T>(index, dim, 0);
size_t initial_memory = index->getAllocationSize();
index->fitMemory();
// TODO: change to ASSERT_EQ once the bf ctor initializes the label2id size to the initial
// capacity.
ASSERT_GT(index->getAllocationSize(), initial_memory);

size_t initial_size = index->getAllocationSize();
// Add vector
GenerateAndAddVector<TEST_DATA_T>(index, dim, 0);
initial_memory = index->getAllocationSize();
index->fitMemory();
size_t final_size = index->getAllocationSize();
// Due to the initial capacity, the memory for the vector was already allocated
ASSERT_EQ(final_size, initial_memory);

ASSERT_LE(final_size, initial_size);
VecSimIndex_Free(index);
}
16 changes: 11 additions & 5 deletions tests/unit/test_hnsw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,15 +2190,21 @@ TYPED_TEST(HNSWTest, getElementNeighbors) {

TYPED_TEST(HNSWTest, FitMemoryTest) {
size_t dim = 4;
HNSWParams params = {.dim = dim, .initialCapacity = 1, .blockSize = 5};
HNSWParams params = {.dim = dim, .initialCapacity = 100, .blockSize = DEFAULT_BLOCK_SIZE};
VecSimIndex *index = this->CreateNewIndex(params);

GenerateAndAddVector<TEST_DATA_T>(index, dim, 0);
// Fit memory to initial capacity shouldn't have any affect since the ctor initializes label2id
// size to the initial capacity.
size_t initial_memory = index->getAllocationSize();
index->fitMemory();
ASSERT_EQ(index->getAllocationSize(), initial_memory);

size_t initial_size = index->getAllocationSize();
// Add vector
GenerateAndAddVector<TEST_DATA_T>(index, dim, 0);
initial_memory = index->getAllocationSize();
index->fitMemory();
size_t final_size = index->getAllocationSize();
// Due to the initial capacity, the memory for the vector was already allocated
ASSERT_EQ(index->getAllocationSize(), initial_memory);

ASSERT_LE(final_size, initial_size);
VecSimIndex_Free(index);
}
19 changes: 10 additions & 9 deletions tests/unit/test_hnsw_tiered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3512,17 +3512,18 @@ TYPED_TEST(HNSWTieredIndexTestBasic, getElementNeighbors) {

TYPED_TEST(HNSWTieredIndexTestBasic, FitMemoryTest) {
size_t dim = 4;
HNSWParams params = {.dim = dim, .initialCapacity = 1, .blockSize = 5};
HNSWParams params = {.dim = dim, .blockSize = DEFAULT_BLOCK_SIZE};
VecSimParams hnsw_params = CreateParams(params);
auto mock_thread_pool = tieredIndexMock();

auto *tiered_index = this->CreateTieredHNSWIndex(hnsw_params, mock_thread_pool);

GenerateAndAddVector<TEST_DATA_T>(tiered_index, dim, 0);

size_t initial_size = tiered_index->getAllocationSize();
tiered_index->fitMemory();
size_t final_size = tiered_index->getAllocationSize();
auto *index = this->CreateTieredHNSWIndex(hnsw_params, mock_thread_pool);

ASSERT_LE(final_size, initial_size);
// Add vector
GenerateAndAddVector<TEST_DATA_T>(index->frontendIndex, dim, 0);
GenerateAndAddVector<TEST_DATA_T>(index->backendIndex, dim, 0);
size_t initial_memory = index->getAllocationSize();
index->fitMemory();
// Tired backendIndex index doesn't have initial capacity, so adding the first vector triggers
// allocation.
ASSERT_EQ(index->getAllocationSize(), initial_memory) << "fitMemory() after adding 1 vector";
}
Loading