使用Transformers來(lái)使用模型
如希望使用Qwen-chat進(jìn)行推理,所需要寫的只是如下所示的數(shù)行代碼。請(qǐng)確保你使用的是最新代碼,并指定正確的模型名稱和路徑,如Qwen/Qwen-7B-Chat
和Qwen/Qwen-14B-Chat
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-718572.html
這里給出了一段代碼
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-718572.html
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig
# 可選的模型包括: "Qwen/Qwen-7B-Chat", "Qwen/Qwen-14B-Chat"
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-7B-Chat", trust_remote_code=True)
# 打開(kāi)bf16精度,A100、H100、RTX3060、RTX3070等顯卡建議啟用以節(jié)省顯存
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-7B-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()
# 打開(kāi)fp16精度,V100、P100、T4等顯卡建議啟用以節(jié)省顯存
# model = AutoModelForCausalLM.from_pret
到了這里,關(guān)于【通義千問(wèn)】大模型Qwen GitHub開(kāi)源工程學(xué)習(xí)筆記(2)--使用Qwen進(jìn)行推理的示例代碼解析,及transformers的使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!