收藏文章 楼主

LLM InternLM-Chat-7B书生模型、Baichuan-13B-Chat百川模型简单使用

版块:AIGC   类型:普通   作者:AI绘图   查看:112   回复:0   获赞:0   时间:2023-11-01 11:00:15

指定GPU运行:

#方式一 (两行必须放在import  torch前面)
#import os
# os.environ['CUDA_VISIBLE_DEVICES'] = '5'

#方式二(第一种不生效用这种,我这边这种可以生效)
#import torch
#torch.cuda.set_device(5)

1、InternLM-Chat-7B书生模型

参考:
https://huggingface.co/internlm/internlm-chat-7b ##模型下载
https://github.com/InternLM/InternLM ## web demo使用代码参考下载

gpu测试需求:大于15g(正常15g对话对轮后也会显存不够)
streamlit demo代码写得效果挺不错

 from transformers import AutoTokenizer, AutoModelForCausalLM
 tokenizer = AutoTokenizer.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm-chat-7b", trust_remote_code=True).cuda()
 model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
>>> print(response)
你好!有什么我可以帮助你的吗?
response, history = model.chat(tokenizer, "请提供三个管理时间的建议。", history=history)
>>> print(response)

在这里插入图片描述

在这里插入图片描述

2、Baichuan-13B-Chat百川模型简单使用

参考:
https://huggingface.co/baichuan-inc/Baichuan-13B-Chat ##模型下载
https://github.com/baichuan-inc/Baichuan-13B ## web demo使用代码参考下载

gpu测试需求:大于20g(这里 device_map="auto"是默认多显卡)

(羡慕是在线量化截图,前面所需加载到cpu,资源要求也很高,还是等待官方提供量化好的int8,int4再测试)
在这里插入图片描述

在代码中,模型加载指定 device_map=‘auto’,会使用所有可用显卡。如需指定使用的设备,可以使用类似 export CUDA_VISIBLE_DEVICES=0,1(使用了0、1号显卡)的方式控制。

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation.utils import GenerationConfig
tokenizer = AutoTokenizer.from_pretrained("baichuan-inc/Baichuan-13B-Chat", use_fast=False, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("baichuan-inc/Baichuan-13B-Chat", device_map="auto", torch_dtype=torch.float16, trust_remote_code=True)
model.generation_config = GenerationConfig.from_pretrained("baichuan-inc/Baichuan-13B-Chat")
messages = []
messages.append({"role": "user", "content": "Which moutain is the second highest one in the world?"})
response = model.chat(tokenizer, messages)
print(response)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

 
回复列表
默认   热门   正序   倒序

回复:LLM InternLM-Chat-7B书生模型、Baichuan-13B-Chat百川模型简单使用

Powered by 7.12.10

©2015 - 2025 90Link

90link品牌推广 网站地图

您的IP:10.3.167.80,2025-06-24 00:56:08,Processed in 0.21234 second(s).

豫ICP备2023005541号

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息
免责声明
  • 1、本网站所刊载的文章,不代表本网站赞同其观点和对其真实性负责,仅供参考和借鉴。
  • 2、文章中的图片和文字版权归原作者所有,如有侵权请及时联系我们,我们将尽快处理。
  • 3、文章中提到的任何产品或服务,本网站不对其性能、质量、适用性、可靠性、安全性、法律合规性等方面做出任何保证或承诺,仅供读者参考,使用者自行承担风险。
  • 4、本网站不承担任何因使用本站提供的信息、服务或产品而产生的直接、间接、附带或衍生的损失或责任,使用者应自行承担一切风险。

侵权删除请致信 E-Mail:3454251265@qq.com