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

build_index is very slow #140

Open
xiongqiangcs opened this issue Nov 18, 2022 · 5 comments
Open

build_index is very slow #140

xiongqiangcs opened this issue Nov 18, 2022 · 5 comments

Comments

@xiongqiangcs
Copy link

machine:

  • cpu-machine:Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz
  • mem: 32G
  • cpu-cores: 16

code:

from autofaiss import build_index
import numpy as np

embeddings = np.float32(np.random.rand(1000000, 512))
index, index_infos = build_index(embeddings, save_on_disk=False)

log:
image

@rom1504
Copy link
Contributor

rom1504 commented Nov 18, 2022

Building an hnsw is indeed one of the slowest adding method, especially with random vectors.
This is calling faiss index.add

If you want to optimize for speed of building an index you can force the index key to not use hnsw

@xiongqiangcs
Copy link
Author

Building an hnsw is indeed one of the slowest adding method, especially with random vectors. This is calling faiss index.add

If you want to optimize for speed of building an index you can force the index key to not use hnsw

autofaiss build_index cost time 49min,faiss index add cost time 34 min

from autofaiss import setup_logging, build_index
from autofaiss import Timeit
import numpy as np
import faiss
import logging
import logging.config
import multiprocessing

setup_logging(logging.INFO)
faiss.omp_set_num_threads(multiprocessing.cpu_count())


embeddings = np.float32(np.random.rand(1000000, 512))
with Timeit("build index"):
    index = faiss.index_factory(512, "HNSW32", faiss.METRIC_L2)
    index.add(embeddings)

image

@xiongqiangcs
Copy link
Author

embedding_reader parameter max_piece_size and parallel_pieces need optimize?

for batch_id, (vec_batch, ids_batch) in enumerate(embedding_reader(batch_size=batch_size)):
if add_embeddings_with_ids:
trained_index.add_with_ids(vec_batch, ids_batch["i"].to_numpy())
else:
trained_index.add(vec_batch)

@rom1504
Copy link
Contributor

rom1504 commented Nov 20, 2022

What kind of local disk do you have ?

@xiongqiangcs
Copy link
Author

What kind of local disk do you have ?

SSD

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

No branches or pull requests

2 participants