自己的网站发文章怎么做外链,金水郑州网站建设,深圳创业板,公司系统软件langchian 使用已经下载到本地的模型#xff0c;我们使用通义千问
显存#xff1a;24G
模型#xff1a;qwen1.5-7B-Chat#xff0c;qwen-7B-Chat 先使用 qwen-7B-Chat#xff0c;会报错用不了#xff1a; 看了下是不支持这中模型#xff0c;但看列表中有一个 Qwen 字样…langchian 使用已经下载到本地的模型我们使用通义千问
显存24G
模型qwen1.5-7B-Chatqwen-7B-Chat 先使用 qwen-7B-Chat会报错用不了 看了下是不支持这中模型但看列表中有一个 Qwen 字样想着应该是支持的就去 hugging face 搜了下这个东西 “Qwen2”找到了对应的 qwen1.5-7B-Chat 模型
https://huggingface.co/Qwen/Qwen1.5-7B-Chat
其实也就是一种公测版本所以总结来说目前直接导入本地 通义千问 langchaing 支持不是很好可以使用 ollama但这个下载非常慢还会失败 qwen1.5-7B-Chat 我们用这个模型是可以加载成功的并输出的但是非常非常慢
from transformers import AutoTokenizer, AutoModelForCausalLM
from transformers import pipeline
from langchain import HuggingFacePipeline
from langchain_core.prompts import ChatPromptTemplatemodel_path /root/autodl-tmp/Qwen1___5-7B-Chat
tokenizer AutoTokenizer.from_pretrained(model_path, trust_remote_codeTrue)
model AutoModelForCausalLM.from_pretrained(model_path,device_mapauto,trust_remote_codeTrue).eval()
pipe pipeline(text-generation,modelmodel,tokenizertokenizer,# max_length4096,# max_tokens4096,max_new_tokens512,top_p1,repetition_penalty1.15
)
llama_model HuggingFacePipeline(pipelinepipe)prompt ChatPromptTemplate.from_template(请编写一篇关于{topic}的中文小故事不超过100字)
chain prompt | llama_model
res chain.invoke({topic: 小白兔})
print(res)