大模型部署手记(24)Ubuntu+Yi
【摘要】 大模型部署手记(24)Ubuntu+Yi
1.简介:
组织机构:零一万物(李开复团队)
代码仓:
模型:01ai/Yi-6B
modelscope下载:https://www.modelscope.cn/models/01ai/Yi-6B/summary
硬件环境:暗影精灵7Plus
Ubuntu版本:18.04
内存 32G
GPU显卡:Nvidia GTX 3080 Laptop (16G)
2.模型下载:
浏览器打开modelscope: www.modelscope.cn/models/01ai/Yi-6B/summary
登录Ubuntu,拿Skywork的模型下载脚本:model_download.py
from modelscope import (
AutoModelForCausalLM, AutoTokenizer, GenerationConfig, snapshot_download
)
model_dir = snapshot_download('01ai/Yi-6B', 'master')
先将模型下载下来:
conda activate model310
python model_download.py
下载好的模型放到了 ~/.cache/modelscope/hub/01ai/Yi-6B:
将其移动到 ~/models/01Yi目录下:
3.安装依赖
conda activate model310
cd Yi-6B
pip install accelerate
pip install sentencepiece
4.部署验证
编辑 model_test.py
from modelscope import AutoModelForCausalLM, AutoTokenizer,snapshot_download
import torch
model_dir = "/home/zhanghui/models/01ai/Yi-6B"
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
inputs = tokenizer("There's a place where time stands still. A place of breath taking wonder, but also", return_tensors="pt")
outputs = model.generate(inputs.input_ids.cuda(), max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
python model_test.py
换成中文试试:
from modelscope import AutoModelForCausalLM, AutoTokenizer,snapshot_download
import torch
model_dir = "/home/zhanghui/models/01ai/Yi-6B"
model = AutoModelForCausalLM.from_pretrained(model_dir, device_map="auto", torch_dtype="auto", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
#inputs = tokenizer("There's a place where time stands still. A place of breath taking wonder, but also", return_tensors="pt")
inputs = tokenizer("讲一个英雄的故事吧!", return_tensors="pt")
outputs = model.generate(inputs.input_ids.cuda(), max_new_tokens=256)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
python model_test.py
inputs = tokenizer("I have a dream", return_tensors="pt")
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)