环境搭建
#安装Mindnlp
pip install git+https://github.com/mindspore-lab/mindnlp.git
requirement
pip install "mindspore>=2.2"
#模型下载
from modelscope import snapshot_download
model_dir = snapshot_download('mindnlp/falcon-rw-1b')
Git下载
#Git模型下载
git clone https://www.modelscope.cn/mindnlp/falcon-rw-1b.git
quickly start
repo = "Rocketknight1/falcon-rw-1b"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo)
model.set_train(False)
pipeline = mindnlp.transformers.pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
torch_dtype=ms.bfloat16,
trust_remote_code=True,
)
sequences = pipeline(
"Girafatron is obsessed with giraffes, the most glorious animal on the face of this Earth. Giraftron believes all other animals are irrelevant when compared to the glorious majesty of the giraffe.\nDaniel: Hello, Girafatron!\nGirafatron:",
max_length=200,
do_sample=True,
top_k=10,
num_return_sequences=1,
eos_token_id=tokenizer.eos_token_id,
)
for seq in sequences:
print(f"Result: {seq['generated_text']}")
评论