running out of ram even though i delete the index every time I created it
Summary
I was trying to use the flat index for the training task and use the threadpool to process each batch. I delete the index immediately after I use it. But it still runs out of ram and kills the program.
Platform
OS: ubuntu 18.04
Faiss version: faiss-cpu
Faiss compilation options: general compilation
Running on:
- [ *] CPU
- [ ] GPU
Interface:
- [ ] C++
- [* ] Python
Reproduction instructions
def search(kkk):
# build index for every sample in the batch
index = faiss.IndexFlatL2(3) # build the index
pc3_c = np.ascontiguousarray(pc3_np[kkk], dtype=np.float32)
index.add(pc3_c)
D, I = index.search(np.ascontiguousarray(pc3_pred_np[kkk].transpose(1, 0)), 1)
del index
return I
pool = ThreadPool(32)
results = pool.map(search, range(batch_size))
pool.close()
pool.join()
I was using this piece of code to process each batch, basically, I created index for each sample and delete it after I got the vector I. But still as training progressed, the ram memory kept going up and eventually kill the program. And even after the process was killed, the memory was still occupied and not released. Any insight about this?

finish searching ...... search time: 1.5417819023132324 86%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 714/835 [40:26<07:15, 3.60s/it] start searching ...... finish searching ...... search time: 132.72269582748413 86%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████▋ | 715/835 [42:43<4:07:10, 123.58s/it] start searching ...... finish searching ...... search time: 347.96712255477905 86%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 716/835 [48:36<10:54:43, 330.11s/it] start searching ...... finish searching ...... search time: 1.521345853805542 86%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████▉ | 717/835 [48:38<1:08:29, 34.83s/it] start searching ...... finish searching ...... search time: 100.22169756889343 86%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████ | 718/835 [50:23<3:10:50, 97.87s/it] start searching ...... finish searching ...... search time: 251.63037157058716 86%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 719/835 [54:39<7:45:20, 240.69s/it] start searching ...... finish searching ...... search time: 1.518728256225586 86%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████▏ | 720/835 [54:42<49:55, 26.05s/it] start searching ...... finish searching ...... search time: 1556.6987295150757 86%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████▍ | 721/835 [2:17:39<141:56:07, 4482.17s/it] start searching ...... Killed
I got a similar error when using multiprocessing.Pool, After I use ThreadPool, the error disappears. In addition, I only use multiple threads for searching.
I try to build the index ahead, but the memory ran out again.
I don't understand the purpose of the thread / process pool. Faiss searches are already multithreaded internally, so adding a threading layer on top will slow them down.
Cause I want to build around 40k indexes, each with size (3, 8172), I thought using Threadpool will speed up the process.
I try to store all the indexes in the RAM, but it seems like that index search also takes up memory.
no activity, closing.
Hi, I have the same issue during searching with 10M database.