Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

安装了faiss-gpu==1.7.2库包,如何使用faiss-gpu库对知识库训练加速,需要修改哪些代码?

Open liaoqingjian opened this issue 1 year ago • 3 comments

liaoqingjian avatar Apr 16 '24 07:04 liaoqingjian

To use faiss-gpu 1.7.2 for accelerating knowledge base training, follow these steps:

  1. Ensure FAISS and PyTorch GPU Support: Verify that both faiss-gpu and PyTorch with GPU support are installed in your environment, along with a compatible CUDA version.

  2. Code Modifications for GPU Usage: In your code, specifically within the FaissKBService class or similar, modify the method responsible for initializing the FAISS index to utilize GPU. For example, if you have a method like load_vector_store, you can adapt it to move the FAISS index to the GPU using faiss.index_cpu_to_gpu. Here's a snippet:

import faiss
import torch

class FaissKBService(KBService):
    def load_vector_store(self) -> ThreadSafeFaiss:
        vector_store = kb_faiss_pool.load_vector_store(self.kb_name, self.vector_name, self.embed_model)
        if torch.cuda.is_available():
            gpu_index = faiss.index_cpu_to_gpu(faiss.StandardGpuResources(), 0, vector_store.index)
            vector_store.index = gpu_index
        return vector_store

This assumes your vector store object has an .index attribute with the FAISS index. Adjust based on your implementation.

  1. Review Other Methods: Ensure other methods interacting with the FAISS index, like adding or searching vectors, are compatible with GPU indices.

  2. Testing: After implementing these changes, thoroughly test your application for correct behavior and performance improvements.

This approach assumes familiarity with your existing codebase and may require adjustments based on your specific setup and the objects you're working with.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 16 '24 07:04 dosubot[bot]

兄弟,修改代码了吗?解决了没?

zmwstu avatar Apr 18 '24 04:04 zmwstu

这不是训练啊,从来都没有训练,这是召回,要快就只能推理加速了

zRzRzRzRzRzRzR avatar May 05 '24 14:05 zRzRzRzRzRzRzR

这个问题已经被标记为 stale ,因为它已经超过 30 天没有任何活动。

github-actions[bot] avatar Jun 04 '24 21:06 github-actions[bot]