-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
conda-forge有针对win编译好的faiss-gpu库,可以直接用conda安装,应该是要提前卸载掉faiss-cpu和python环境里的faiss相关库,再用conda装出来就可以。
我实测了faiss-gpu 1.7.4版本正常使用(1.8 1.9也许可以,刚开始报错以为是版本问题就换回以前用过的老版本了)。
只改动了两个地方(大概)
一是加载的地方
SVCFusion/SoVITS/inference/infer_tool.py
Lines 245 to 250 in 65ad0a9
| if os.path.exists(cluster_model_path): | |
| if self.feature_retrieval: | |
| with open(cluster_model_path, "rb") as f: | |
| self.cluster_model = pickle.load(f) | |
| self.big_npy = None | |
| self.now_spk_id = -1 |
class Svc加个属性
self.gpu_res = faiss.StandardGpuResources()
self.cluster_model = {}
for spk_id, index_cpu in cluster_model_cpu.items():
index_gpu = faiss.index_cpu_to_gpu(self.gpu_res, 0, index_cpu)
self.cluster_model[spk_id] = index_gpu然后是重建这块,gpu上不支持重建,还得转回cpu重建
SVCFusion/SoVITS/inference/infer_tool.py
Lines 338 to 340 in 65ad0a9
| if self.big_npy is None or self.now_spk_id != speaker_id: | |
| self.big_npy = feature_index.reconstruct_n(0, feature_index.ntotal) | |
| self.now_spk_id = speaker_id |
if self.big_npy is None or self.now_spk_id != speaker_id:
cpu_index = faiss.index_gpu_to_cpu(feature_index)
dim = cpu_index.d
ntotal = cpu_index.ntotal
self.big_npy = np.zeros((ntotal, dim), dtype="float32")
chunk_size = 10000 # 可根据显存调整
cpu_index.make_direct_map()
for i in range(0, ntotal, chunk_size):
end = min(i + chunk_size, ntotal)
cpu_index.reconstruct_batch(np.arange(i, end), self.big_npy[i:end])
feature_index = faiss.index_cpu_to_gpu(self.gpu_res, 0, cpu_index)
del cpu_index
self.now_spk_id = speaker_id这块分块应该是没必要,可以去掉。
然后好像还有个缺失mkl_intel_thread.2.dll的报错,因为没法改整合包.conda环境的路径,我是覆盖着改环境的,完整conda环境装依赖的时候是有这个dll的,直接复制补上也行。
以供参考,希望能让特征检索不再是个残废功能。😂
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels