赞
踩
之前体验过了ChatGLM3-6B环境自带的各种Demo,包括base_demo、composite_demo等。如何自己开发代码调用LLM?官方给的教程很少,只能通过阅读有限的demo代码来了解。
本文主要熟悉以下内容:
transformers
- AutoTokenizer
- AutoModel
model.chat()
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True)
model = AutoModel.from_pretrained("THUDM/chatglm3-6b", trust_remote_code=True, device='cuda')
model = model.eval()
/opt/conda/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
Loading checkpoint shards: 100%|██████████| 7/7 [01:09<00:00, 9.88s/it]
注意。如果GPU显存32G以下,在初始化时,请选择合适的初始化方式。
response, history = model.chat(tokenizer, "你好", history=[])
print(response)
你好声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。