Skip to content

Commit 0527b46

Browse files
Amir Sadoughifacebook-github-bot
authored andcommitted
Update __init__.py (facebookresearch#4086)
Summary: X-link: meta-pytorch/torchrec#2628 Fix erroneous logging `Failed to load GPU Faiss: No module named 'swigfaiss_gpu'. Will not load constructor refs for GPU indexes.` when I was running on a GPU-based index just fine. `GpuIndex...` is loaded via loader.py. Pull Request resolved: facebookresearch#4086 Test Plan: before ``` (faiss_gpu_cuvs_nightly) [[email protected] ~]$ python3 script.py Failed to load GPU Faiss: No module named 'swigfaiss_gpu'. Will not load constructor refs for GPU indexes. ``` after ``` (faiss_gpu_cuvs_nightly) [[email protected] ~]$ python3 Python 3.12.8 | packaged by conda-forge | (main, Dec 5 2024, 14:24:40) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import faiss >>> ``` Reviewed By: mnorris11 Differential Revision: D67118292 Pulled By: asadoughi fbshipit-source-id: aa05aa20fe61e4ad75d4234f52e3b0d6a673a0b9
1 parent 55bab92 commit 0527b46

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

faiss/python/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# causes a ton of useless warnings.
1010

1111
import numpy as np
12+
import logging
1213
import sys
1314
import inspect
1415

@@ -30,6 +31,8 @@
3031
FAISS_VERSION_MINOR,
3132
FAISS_VERSION_PATCH)
3233

34+
logger = logging.getLogger(__name__)
35+
3336
class_wrappers.handle_Clustering(Clustering)
3437
class_wrappers.handle_Clustering1D(Clustering1D)
3538
class_wrappers.handle_MatrixStats(MatrixStats)
@@ -161,14 +164,13 @@ def replacement_function(*args):
161164

162165

163166
try:
164-
from swigfaiss_gpu import GpuIndexIVFFlat, GpuIndexBinaryFlat, GpuIndexFlat, GpuIndexIVFPQ, GpuIndexIVFScalarQuantizer
165167
add_ref_in_constructor(GpuIndexIVFFlat, 1)
166168
add_ref_in_constructor(GpuIndexBinaryFlat, 1)
167169
add_ref_in_constructor(GpuIndexFlat, 1)
168170
add_ref_in_constructor(GpuIndexIVFPQ, 1)
169171
add_ref_in_constructor(GpuIndexIVFScalarQuantizer, 1)
170-
except ImportError as e:
171-
print("Failed to load GPU Faiss: %s. Will not load constructor refs for GPU indexes." % e.args[0])
172+
except NameError as e:
173+
logger.info("Failed to load GPU Faiss: %s. Will not load constructor refs for GPU indexes." % e.args[0])
172174

173175
add_ref_in_constructor(IndexIVFFlat, 0)
174176
add_ref_in_constructor(IndexIVFFlatDedup, 0)

0 commit comments

Comments
 (0)