faiss/tests/test_oom_exception.py
Matthijs Douze 3dd7ba8ff9 Add range search accuracy evaluation
Summary:
Added a few functions in contrib to:
- run range searches by batches on the query or the database side
- emulate range search on GPU: search on GPU with k=1024, if the farthest neighbor is still within range, re-perform search on CPU
- as reference implementations for precision-recall on range search datasets
- optimized code to plot precision-recall plots (ie. sweep over thresholds)

The new functions are mainly in a new `evaluation.py`

Reviewed By: wickedfoo

Differential Revision: D25627619

fbshipit-source-id: 58f90654c32c925557d7bbf8083efbb710712e03
2020-12-17 17:17:09 -08:00

35 lines
1.1 KiB
Python

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import sys
import faiss
import unittest
import platform
class TestOOMException(unittest.TestCase):
@unittest.skipIf(platform.system() != 'Linux',
'Test is Linux only.')
def test_outrageous_alloc(self):
import resource
# https://github.com/facebookresearch/faiss/issues/758
soft_as, hard_as = resource.getrlimit(resource.RLIMIT_AS)
# make sure that allocing more than 10G will fail
resource.setrlimit(resource.RLIMIT_AS, (10 * 1024 * 1024, hard_as))
try:
x = faiss.IntVector()
try:
x.resize(10**11) # 400 G of RAM
except MemoryError:
pass # good, that's what we expect
else:
assert False, "should raise exception"
finally:
resource.setrlimit(resource.RLIMIT_AS, (soft_as, hard_as))
if __name__ == '__main__':
unittest.main()