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

std::bad_alloc #758

Closed
2 tasks
linghuang opened this issue Mar 29, 2019 · 3 comments
Closed
2 tasks

std::bad_alloc #758

linghuang opened this issue Mar 29, 2019 · 3 comments

Comments

@linghuang
Copy link

linghuang commented Mar 29, 2019

Summary

Platform

OS: Ubuntu Server 16.04

Faiss version: GPU version

Faiss compilation options: conda install faiss-gpu -c pytorch

Running on:

  • GPU

Interface:

  • Python

minimal code to reproduce the issue:

import faiss
import numpy as np

d = 2048
index = faiss.IndexFlatIP(d)

#img_feature_list is a numpy array with dimension of 30000 * 2048
img_feature_list = np.load("feature.npy")

for i in range(40): index.add(img_feature_list)

Reproduction instructions

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 ?

@mdouze
Copy link
Contributor

mdouze commented Mar 29, 2019

@mdouze
Copy link
Contributor

mdouze commented Apr 4, 2019

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.

@mdouze mdouze removed the cant-repro label Apr 4, 2019
@mdouze mdouze assigned mdouze and unassigned wickedfoo Apr 4, 2019
beauby pushed a commit that referenced this issue Jun 19, 2019
Bugfixes:
- slow scanning of inverted lists (#836).

Features:
- add basic support for 6 new metrics in CPU `IndexFlat` and `IndexHNSW` (#848);
- add support for `IndexIDMap`/`IndexIDMap2` with binary indexes (#780).

Misc:
- throw python exception for OOM (#758);
- make `DistanceComputer` available for all random access indexes;
- gradually moving from `long` to `int64_t` for portability.
@mdouze
Copy link
Contributor

mdouze commented Jun 25, 2019

Implemented in 1.5.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants