我再modelscope环境下,使用https://modelscope.cn/models/codefuse-ai/CodeFuse-StarCoder-15B/summary 里面的quickstart代码,然后部署到4个T4卡的机器上,结果出来特别慢,要10分钟以上(不包括下载和加载模型这些时间)
import torch
from modelscope import (
AutoTokenizer,
AutoModelForCausalLM,
snapshot_download
)
model_dir = snapshot_download('codefuse-ai/CodeFuse-StarCoder-15B',revision = 'v1.0.0')
tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True, use_fast=False, legacy=False)
tokenizer.padding_side = "left"
tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids("<fim_pad>")
tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids("<|endoftext|>")
tokenizer.pad_token = "<fim_pad>"
tokenizer.eos_token = "<|endoftext|>"
# try 4bit loading if cuda memory not enough
model = AutoModelForCausalLM.from_pretrained(model_dir,
trust_remote_code=True,
load_in_4bit=False,
device_map="auto",
torch_dtype=torch.bfloat16)
model.eval()
HUMAN_ROLE_START_TAG = "<|role_start|>human<|role_end|>"
BOT_ROLE_START_TAG = "<|role_start|>bot<|role_end|>"
text = f"{HUMAN_ROLE_START_TAG}write a python function of quick sort.{BOT_ROLE_START_TAG}"
inputs = tokenizer(text, return_tensors='pt', padding=True, add_special_tokens=False).to("cuda")
outputs = model.generate(
inputs=inputs["input_ids"],
attention_mask=inputs["attention_mask"],
max_new_tokens=512,
top_p=0.95,
temperature=0.1,
do_sample=True,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id
)
gen_text = tokenizer.batch_decode(outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(gen_text)
这个问题可能有以下几种原因:
为了解决这个问题,可以尝试以下几种方法:
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。