OS: Ubuntu Server 16.04
Faiss version: GPU version
Faiss compilation options: conda install faiss-gpu -c pytorch
Running on:
Interface:
import faiss
import numpy as np
d = 2048
index = faiss.IndexFlatIP(d)
img_feature_list = np.load("feature.npy")
for i in range(40): index.add(img_feature_list)
RAM size is 32G
Run this code, It throws the following error:
“terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped)”
But the memory hasn't ran out. The memory is only occupied about 67%.
what to do with this ?
@linghuang please provide a proper bug report
https://github.com/facebookresearch/faiss/wiki/Troubleshooting#reporting-bugs
Sorry, I missed the "minimal code" section.
Memory allocation is done with the std::vector insert function
https://github.com/facebookresearch/faiss/blob/master/IndexFlat.cpp#L32
the memory reallocation policy of std::vector is to increment by powers of 2. So if you already use 67% RAM, it will go to 2*67% > 100% RAM.
There is no clear workaround here unfortunately. Giving up the geometric reallocation would have an impact on performance.
One thing we should look at is catching bad_alloc and translating it into a Python exception.
Implemented in 1.5.3
Most helpful comment
Sorry, I missed the "minimal code" section.
Memory allocation is done with the
std::vectorinsertfunctionhttps://github.com/facebookresearch/faiss/blob/master/IndexFlat.cpp#L32
the memory reallocation policy of
std::vectoris to increment by powers of 2. So if you already use 67% RAM, it will go to 2*67% > 100% RAM.There is no clear workaround here unfortunately. Giving up the geometric reallocation would have an impact on performance.
One thing we should look at is catching bad_alloc and translating it into a Python exception.