chatchat-space / Langchain-Chatchat

Langchain-Chatchat(原Langchain-ChatGLM)基于 Langchain 与 ChatGLM, Qwen 与 Llama 等语言模型的 RAG 与 Agent 应用 | Langchain-Chatchat (formerly langchain-ChatGLM), local knowledge based LLM (like ChatGLM, Qwen and Llama) RAG and Agent app with langchain
Apache License 2.0
31.66k stars 5.52k forks source link

[BUG] 切换本地模型chatglm2-6b #911

Closed oranges-deliverance closed 1 year ago

oranges-deliverance commented 1 year ago

问题描述 / Problem Description 在调用cli_demo.py文件测试时出现本地路径检验重复问题,有关trust_remote_code参数的错误。

复现问题的步骤 / Steps to Reproduce 执行 cli_demo.py

预期的结果 / Expected Result 提示输入本地知识文件路径

实际结果 / Actual Result WARNING 2023-07-20 11:44:30,433-1d: No sentence-transformers model found with name /jinx/GPT/langchain-ChatGLM/chatglm2-6b. Creating a new one with MEAN pooling. Traceback (most recent call last): File "/jinx/GPT/langchain-ChatGLM/cli_demo.py", line 66, in main() File "/jinx/GPT/langchain-ChatGLM/cli_demo.py", line 20, in main local_doc_qa.init_cfg(llm_model=llm_model_ins, File "/jinx/GPT/langchain-ChatGLM/chains/local_doc_qa.py", line 136, in init_cfg self.embeddings = HuggingFaceEmbeddings(model_name=embedding_model_dict[embedding_model], File "/jinx/tools/yes/envs/langchain-ChatGLM/lib/python3.9/site-packages/langchain/embeddings/huggingface.py", line 54, in init self.client = sentence_transformers.SentenceTransformer( File "/jinx/tools/yes/envs/langchain-ChatGLM/lib/python3.9/site-packages/sentence_transformers/SentenceTransformer.py", line 97, in init modules = self._load_auto_model(model_path) File "/jinx/tools/yes/envs/langchain-ChatGLM/lib/python3.9/site-packages/sentence_transformers/SentenceTransformer.py", line 806, in _load_auto_model transformer_model = Transformer(model_name_or_path) File "/jinx/tools/yes/envs/langchain-ChatGLM/lib/python3.9/site-packages/sentence_transformers/models/Transformer.py", line 28, in init config = AutoConfig.from_pretrained(model_name_or_path, **model_args, cache_dir=cache_dir) File "/jinx/tools/yes/envs/langchain-ChatGLM/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py", line 931, in from_pretrained raise ValueError( ValueError: Loading /jinx/GPT/langchain-ChatGLM/chatglm2-6b requires you to execute the configuration file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option trust_remote_code=True to remove this error.

环境信息 / Environment Information

hzg0601 commented 1 year ago

这个问题应该是setence transformers的版本问题,应可以在local_doc_qa.py", line 136中在HuggingFaceEmbeddings加入关键词参数trust_remote_code=True来解决,如果问题仍存在请重开issue

wizardforcel commented 1 year ago

setence transformers

GLM2应该没有适配setence transformers,我看程序是用的 MEAN 池化。不过默认不加trust_remote_code=True就有点过分了。

INFO  2023-08-10 18:05:55,127-1d: Load pretrained SentenceTransformer: D:/src/chatglm2-6b-int4
WARNING 2023-08-10 18:05:55,135-1d: No sentence-transformers model found with name D:/src/chatglm2-6b-int4. Creating a new one with MEAN pooling.
ERROR 2023-08-10 18:05:55,139-1d: Loading D:/src/chatglm2-6b-int4 requires you to execute the configuration file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option `trust_remote_code=True` to remove this error.
yuanzilin commented 1 month ago

这个问题应该是setence transformers的版本问题,应可以在local_doc_qa.py", line 136中在HuggingFaceEmbeddings加入关键词参数trust_remote_code=True来解决,如果问题仍存在请重开issue

以防小白不知道怎么加关键词参数,我对层主的回答作个补充 关键词参数就是要传给HuggingfaceEmbeddings的model_kwargs参数,可以用这样的方式传入trust_remote_code参数: model_kwargs = {"device": "cpu", "trust_remote_code":"True"} encode_kwargs = {"normalize_embeddings": True} bgeEmbeddings = HuggingFaceEmbeddings( model_name=model_name, model_kwargs=model_kwargs, encode_kwargs=encode_kwargs )