Skip to content
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

add timers to dyanmic apps #337

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions python/apps/in-mem-dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import utils


def insert_and_search(
dtype_str,
indexdata_file,
Expand Down Expand Up @@ -44,25 +43,26 @@ def insert_and_search(
raise ValueError("data_type must be float, int8 or uint8")

tags = np.zeros(npts, dtype=int)
timer = utils.timer()
for i in range(npts):
tags[i] = i + 1
index.batch_insert(data, tags, num_insert_threads)
print("batch_insert complete")
print('batch_insert complete in', timer.elapsed(), 's')

delete_tags = np.random.choice(
range(1, npts + 1, 1), size=int(0.5 * npts), replace=False
)
for tag in delete_tags:
index.mark_deleted(tag)
print("mark deletion completed")
print('mark deletion completed in', timer.elapsed(), 's')

index.consolidate_delete()
print("consolidation completed")
print('consolidation completed in', timer.elapsed(), 's')

deleted_data = data[delete_tags - 1, :]

index.batch_insert(deleted_data, delete_tags, num_insert_threads)
print("re-insertion completed")
print('re-insertion completed in', timer.elapsed(), 's')

tags, dists = index.batch_search(queries, K, Ls, num_search_threads)
res_ids = tags - 1
Expand Down
16 changes: 9 additions & 7 deletions python/apps/insert-in-clustered-order.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def insert_and_search(
)

i = 0
timer = utils.timer()
for c in range(num_clusters):
cluster_index_range = range(offsets[c], offsets[c + 1])
cluster_indices = permutation[cluster_index_range]
cluster_data = data[cluster_indices, :]
index.insert(cluster_data, cluster_indices + 1, num_insert_threads)
print('Inserted cluster', c, ' in ', timer.elapsed(), 's')
tags, dists = index.batch_search(queries, K, Ls, num_search_threads)
res_ids = tags - 1

Expand All @@ -71,13 +73,13 @@ def insert_and_search(
parser.add_argument("-d", "--data_type", required=True)
parser.add_argument("-i", "--indexdata_file", required=True)
parser.add_argument("-q", "--querydata_file", required=True)
parser.add_argument("-Lb", "--Lbuild", default=50)
parser.add_argument("-Ls", "--Lsearch", default=50)
parser.add_argument("-R", "--graph_degree", default=32)
parser.add_argument("-TI", "--num_insert_threads", default=8)
parser.add_argument("-TS", "--num_search_threads", default=8)
parser.add_argument("-C", "--num_clusters", default=32)
parser.add_argument("-K", default=10)
parser.add_argument("-Lb", "--Lbuild", default=50, type=int)
parser.add_argument("-Ls", "--Lsearch", default=50, type=int)
parser.add_argument("-R", "--graph_degree", default=32, type=int)
parser.add_argument("-TI", "--num_insert_threads", default=8, type=int)
parser.add_argument("-TS", "--num_search_threads", default=8, type=int)
parser.add_argument("-C", "--num_clusters", default=32, type=int)
parser.add_argument("-K", default=10, type=int)
parser.add_argument("--gt_file", default="")
args = parser.parse_args()

Expand Down
10 changes: 10 additions & 0 deletions python/apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import numpy as np
from scipy.cluster.vq import vq, kmeans2
from typing import Tuple
from time import perf_counter


def get_bin_metadata(bin_file) -> Tuple[int, int]:
Expand All @@ -15,6 +16,15 @@ def bin_to_numpy(dtype, bin_file) -> np.ndarray:
npts, ndims = get_bin_metadata(bin_file)
return np.fromfile(file=bin_file, dtype=dtype, offset=8).reshape(npts, ndims)

class timer:
last = perf_counter()

def elapsed(self):
new = perf_counter()
elapsed_time = new - self.last
self.last = new
return elapsed_time


def numpy_to_bin(array, out_file):
shape = np.shape(array)
Expand Down
4 changes: 2 additions & 2 deletions python/src/diskann_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ void build_in_memory_index(const diskann::Metric &metric, const std::string &vec
.build();
size_t data_num, data_dim;
diskann::get_bin_metadata(vector_bin_path, data_num, data_dim);
diskann::Index<T, TagT, LabelT> index(metric, data_dim, data_num, false, use_tags, false, use_pq_build, num_pq_bytes,
use_opq);
diskann::Index<T, TagT, LabelT> index(metric, data_dim, data_num, false, use_tags, false, use_pq_build,
num_pq_bytes, use_opq);
if (label_file == "")
{
index.build(vector_bin_path.c_str(), data_num, index_build_params);
Expand Down