赞
踩
之前体验过了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博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/272796
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。