Skip to content

Commit f67be31

Browse files
committed
change threads num selection
1 parent 208f84a commit f67be31

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/flow/test_hnswlib.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_recall_for_hnsw_multi_value():
357357

358358
num_elements = num_labels * num_per_label
359359

360-
hnsw_index = create_hnsw_index(dim, num_elements, VecSimMetric_L2, VecSimType_FLOAT32, efConstruction, M,
360+
hnsw_index = create_hnsw_index(dim, num_elements, VecSimMetric_Cosine, VecSimType_FLOAT32, efConstruction, M,
361361
efRuntime, is_multi=True)
362362

363363
data = np.float32(np.random.random((num_labels, dim)))
@@ -465,7 +465,7 @@ def test_parallel_insert_search():
465465
num_elements = 100000
466466
num_queries = 10000
467467
k = 10
468-
n_threads = int(os.cpu_count() / 2)
468+
n_threads = min(os.cpu_count(), 8)
469469
expected_parallel_rate = 0.9 # we expect that at least 90% of the insert/search time will be executed in parallel
470470
expected_speedup = 1 / ((1-expected_parallel_rate) + expected_parallel_rate/n_threads) # by Amdahl's law
471471

@@ -534,7 +534,7 @@ def test_parallel_insert_search():
534534

535535
print(f"Running parallel search, got {total_correct_parallel / (k * num_queries)} recall on {num_queries} queries,"
536536
f" average query time is {total_search_time_parallel / num_queries} seconds")
537-
print(f"Got {total_search_time / total_search_time_parallel} times improvement un runtime using {n_threads} threads\n")
537+
print(f"Got {total_search_time / total_search_time_parallel} times improvement in runtime using {n_threads} threads\n")
538538

539539
# Validate that the recall of the parallel search recall is the same as the sequential search recall.
540540
assert total_correct_parallel == total_correct
@@ -601,7 +601,7 @@ def test_parallel_with_range():
601601
num_elements = 100000
602602
num_queries = 10000
603603
radius = 3.0
604-
n_threads = int(os.cpu_count() / 2)
604+
n_threads = min(os.cpu_count(), 8)
605605
PADDING_LABEL = -1 # used for padding empty labels entries in a single query results
606606
expected_parallel_rate = 0.9 # we expect that at least 90% of the insert/search time will be executed in parallel
607607
expected_speedup = 1 / ((1-expected_parallel_rate) + expected_parallel_rate/n_threads) # by Amdahl's law
@@ -675,7 +675,7 @@ def test_parallel_with_multi():
675675
metric = VecSimMetric_L2
676676
data_type = VecSimType_FLOAT64
677677
num_queries = 10000
678-
n_threads = int(os.cpu_count() / 2)
678+
n_threads = min(os.cpu_count(), 8)
679679
expected_parallel_rate = 0.9 # we expect that at least 90% of the insert/search time will be executed in parallel
680680
expected_speedup = 1 / ((1-expected_parallel_rate) + expected_parallel_rate/n_threads) # by Amdahl's law
681681

@@ -757,7 +757,7 @@ def test_parallel_with_multi():
757757

758758
print(f"Running parallel search, got {total_correct_parallel / (k * num_queries)} recall on {num_queries} queries,"
759759
f" average query time is {total_search_time_parallel / num_queries} seconds")
760-
print(f"Got {total_search_time / total_search_time_parallel} times improvement un runtime using"
760+
print(f"Got {total_search_time / total_search_time_parallel} times improvement in runtime using"
761761
f" {n_threads} threads\n")
762762
assert total_correct_parallel >= total_correct*0.95
763763
assert total_search_time/total_search_time_parallel >= expected_speedup
@@ -811,7 +811,7 @@ def test_parallel_batch_search():
811811
num_queries = 5000
812812
batch_size = 100
813813
n_batches = 5
814-
n_threads = int(os.cpu_count() / 2)
814+
n_threads = min(os.cpu_count(), 8)
815815
expected_parallel_rate = 0.85 # we expect that at least 85% of the insert/search time will be executed in parallel
816816
expected_speedup = 1 / ((1-expected_parallel_rate) + expected_parallel_rate/n_threads) # by Amdahl's law
817817

0 commit comments

Comments
 (0)