langchain HuggingFacePipeline无法从本地存储库加载模型,

06odsfpq  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(38)

检查其他资源

  • 我为这个问题添加了一个非常描述性的标题。
  • 我在集成搜索中搜索了LangChain文档。
  • 我使用GitHub搜索找到了一个类似的问题,但没有找到。
  • 我确信这是LangChain中的一个bug,而不是我的代码。
  • 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决这个bug。

示例代码

from langchain_huggingface import HuggingFacePipeline

llm = HuggingFacePipeline.from_model_id(
    model_id="my_path/MiniCPM-2B-dpo-bf16",
    task="text-generation",
    pipeline_kwargs=dict(
        max_new_tokens=512,
        do_sample=False,
        repetition_penalty=1.03,
    ),
)

错误信息和堆栈跟踪(如果适用)

ValueError:加载 my_path/MiniCPM-2B-dpo-bf16 需要您在本地计算机上执行该仓库中的配置文件。确保您在那里阅读了代码以避免恶意使用,然后设置选项 trust_remote_code=True 以消除此错误。

描述

我按照官方示例 https://python.langchain.com/v0.2/docs/integrations/chat/huggingface/ 进行操作,只是将路径更改为我在Huggyingface下载模型文件的本地仓库。当我尝试运行上面的代码时,终端显示:
The repository for my_path/MiniCPM-2B-dpo-bf16 contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/my_path/MiniCPM-2B-dpo-bf16. You can avoid this prompt in future by passing the argument trust remote code=True Do you wish to run the custom code? y/N] (Press 'Enter' to confirm or 'Escape' to cancel)
无论你选择什么,最终的错误都是告诉你 execute the config file in that repo ,而这个错误在仓库中并不存在。

系统信息

langchain==0.2.1
langchain-community==0.2.1
langchain-core==0.2.3
langchain-huggingface==0.0.1
langchain-openai==0.1.8
langchain-text-splitters==0.2.0
langchainhub==0.1.17
平台:Ubuntu 20.04.1
python==3.9

kh212irz

kh212irz1#

seems that the HuggingFacePipeline.from_model_id() method is raising an error because the model ID you're trying to load requires execution of a configuration file on your local machine.for rectifying try changing the model,try executing the configuration fil locally.from langchain_huggingface import HuggingFacePipeline
If these doesnt work try changing the code in this manner.
llm = HuggingFacePipeline.from_model_id(
model_id="my_path/MiniCPM-2B-dpo-bf16",
task="text-generation",
pipeline_kwargs=dict(
max_new_tokens=512,
do_sample=False,
repetition_penalty=1.03,
),
trust_remote_code=True
)

fhity93d

fhity93d2#

在设置trust_remote_code=True后,同样出现了错误。

相关问题