Comments (8)
You need to re-convert the index back to CPU with index_gpu_to_cpu
before storing it.
from faiss.
@mdouze , a new error happens when converting the index after reading from the saved index:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): an illegal memory access was encountered
Aborted (core dumped)
Here is the code:
if os.path.exists(INDEX_FILE):
index = faiss.read_index(INDEX_FILE)
else:
index = faiss.index_factory(VEC_SIZE, "OPQ16_512,IVF1024,PQ16")
co = faiss.GpuClonerOptions()
co.useFloat16 = False
co.usePrecomputed = False
co.indicesOptions = faiss.INDICES_CPU
res = faiss.StandardGpuResources()
index = faiss.index_cpu_to_gpu(res, 0, index, co) # error happens here
from faiss.
Hi
Could you try to narrow down the problem?
from faiss.
How large is your index? That error usually happens when you run out of GPU memory.
from faiss.
@wickedfoo οΌIt is about 470MB on the disk. I created the index with index = faiss.index_factory(d, "OPQ16_512,IVF1024,PQ16")
and added 20M 1000-dimension vectors, so in my understanding it should be 20M * 512 * 4 (float) = 40GB
when fully added to the memory. But it is strange that the compression rate is so big. Sorry, I will read the paper to get more details behind it. Is there any workaround to avoid the issue?
from faiss.
Just tried reading from the trained index (4.7MB, not populated), then index_cpu_to_gpu and then adding the base vectors and then the Segmentation fault
error happens again.
from faiss.
Hi, @mdouze @wickedfoo ,
Let me make things clearer in case of any confusion.
I tried to save the index (trained and populated with base data) for future use (as the search base). But when loading the index with read_index, this error occurs:
terminate called after throwing an instance of 'thrust::system::system_error'
what(): an illegal memory access was encountered
Aborted (core dumped)
I modified the bench code bench_gpu_sift1m.py to test the read_index operation. My GPU is Titan X. Below is my code. When it is first run, everything is OK and an index file "index" is created. But when running the code again, it will try to read the saved index file with read_index and then error happens.
import faiss
#################################################################
# I/O functions
#################################################################
def ivecs_read(fname):
a = np.fromfile(fname, dtype='int32')
d = a[0]
return a.reshape(-1, d + 1)[:, 1:].copy()
def fvecs_read(fname):
return ivecs_read(fname).view('float32')
#################################################################
# Main program
#################################################################
print "load data"
xt = fvecs_read("sift1M/sift_learn.fvecs")
xb = fvecs_read("sift1M/sift_base.fvecs")
xq = fvecs_read("sift1M/sift_query.fvecs")
nq, d = xq.shape
print "load GT"
gt = ivecs_read("/data/personal/aihu/projects/faiss/benchs/sift1M/sift_groundtruth.ivecs")
# we need only a StandardGpuResources per GPU
res = faiss.StandardGpuResources()
#################################################################
# Approximate search experiment
#################################################################
print "============ Approximate search"
co = faiss.GpuClonerOptions()
# here we are using a 64-byte PQ, so we must set the lookup tables to
# 16 bit float (this is due to the limited temporary memory).
co.useFloat16 = True
co.usePrecomputed = False
populated_index_path = 'index'
if os.path.exists(populated_index_path):
index = faiss.read_index(populated_index_path) # error happens here
index = faiss.index_cpu_to_gpu(res, 0, index, co)
else:
index = faiss.index_factory(d, "IVF4096,PQ64")
# faster, uses more memory
# index = faiss.index_factory(d, "IVF16384,Flat")
index = faiss.index_cpu_to_gpu(res, 0, index, co)
print "train"
index.train(xt)
print "add vectors to index"
index.add(xb)
print "save index"
index_cpu = faiss.index_gpu_to_cpu(index)
faiss.write_index(index_cpu, populated_index_path)
print "warmup"
index.search(xq, 123)
print "benchmark"
for lnprobe in range(10):
nprobe = 1 << lnprobe
index.setNumProbes(nprobe)
t0 = time.time()
D, I = index.search(xq, 100)
t1 = time.time()
print "nprobe=%4d %.3f s recalls=" % (nprobe, t1 - t0),
for rank in 1, 10, 100:
n_ok = (I[:, :rank] == gt[:, :1]).sum()
print "%.4f" % (n_ok / float(nq)),
print
from faiss.
Sorry @hellolovetiger, I can't repro the issue with the code https://gist.github.com/mdouze/7390d6f6fdc00a6a9f75e361b841d13e (yours is incomplete).
Please get a gdb stacktrace.
from faiss.
Related Issues (20)
- Is it possible to lazy load index from disk? HOT 1
- Binary embeddings score normalization HOT 1
- No conda package for faiss-cpu 1.8.0 for osx-64 on pytorch channel HOT 5
- Static library libfaiss_gpu.a not installed HOT 1
- faiss_gpu object is not linked to static library libfaiss.a HOT 3
- Error when building static library for AVX2 and GPU HOT 2
- Cannot debug similarity search HOT 1
- Add a tutorial for IndexHNSW HOT 3
- Segfault error on faiss.IndexIVFFlat().train HOT 1
- knn_gpu should use raft when raft is compiled in HOT 2
- ImportError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found HOT 1
- Remove lapack dependency? HOT 1
- Faiss imported after Torch leads to segfault HOT 2
- Suggestions on implementing multi-scale quantization HOT 3
- The similarity results obtained from the index.faiss file are significantly different from those obtained from previous versions HOT 1
- inquiry related to DistanceComputer HOT 2
- Failed to install via poetry HOT 1
- Update the raft handle through StandardGpuResourcesImpl::setDefaultStream
- [Feature Request] GPU indices Provide Interface to Access Resource HOT 2
- faiss index and retriever not able to save HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faiss.