在魔塔中复现Qwen模型

1、魔塔的链接:https://www.modelscope.cn/
2、在环境中要用到git clone需要和github账号ssh密钥绑定

配置git config
git config --global user.name "这里换上你的用户名"
git config --global user.email "这里换上你的邮箱"
生成密钥文件
ssh-keygen -t rsa -C "useremail"   
默认回车后,提取密钥
vim /root/.ssh/id_rsa.pub
1、用记事本打开id_rsa.pub,并复制里面全部内容
2、打开github,登录自己的账户,进入settings,找到:

在这里插入图片描述

配置git config
git config --global user.name "Zheng-LinXiao"
git config --global user.email "951310862@qq.com"
生成密钥文件
ssh-keygen -t rsa -C "951310862@qq.com"   
默认回车后,提取密钥
vim /root/.ssh/id_rsa.pub

3、在jupyterlab中使用终端:

git clone git@github.com:QwenLM/Qwen.git
cd Qwen
pip install -r requirements.txt

4、创建test.py文件,我使用的是qwen里面modelscope的代码,可以复制别的demo,这个链接下面是有别的demo

touch test.py

打开test.py的文件

from modelscope import AutoModelForCausalLM, AutoTokenizer
from modelscope import GenerationConfig

# Model names: "qwen/Qwen-7B-Chat", "qwen/Qwen-14B-Chat"
tokenizer = AutoTokenizer.from_pretrained("qwen/Qwen-7B-Chat", revision='v1.0.5', trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("qwen/Qwen-7B-Chat", revision='v1.0.5', device_map="auto", trust_remote_code=True, fp16=True).eval()
model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-7B-Chat", revision='v1.0.5', trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参

response, history = model.chat(tokenizer, "你好", history=None)
print("你好")
print("回答:\n",response)
response, history = model.chat(tokenizer, "种植水稻时天气炎热怎么办?", history=history) 
print("\n种植水稻时天气炎热怎么办??")
print("回答:\n",response)
response, history = model.chat(tokenizer, "根据我在浙江省,在选择合适的品种问题上,有推荐的品种吗?", history=history)
print("\n盐碱是什么?")
print("回答:\n",response)

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值