1、适配昇腾处理器:Ascend310、Ascend910系列 2、开发环境:Ascend-cann-toolkit_xxx、Ascend-cann-kernels-xxx(可选)、python3.8 3、下载代码:git clone https://modelers.cn/ShanXi/llama-160m.git 4、安装依赖:pip install -r examples/requirements.txt 5、推理测试:python examples/inference.py 6、推理脚本:
import argparse import torch from openmind import pipeline, is_torch_npu_available
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--model_name_or_path",type=str,help="模型路径",default="./",)
args = parser.parse_args()
return args if is_torch_npu_available(): device = "npu:0" else: device = "cpu"
args = parse_args() model_path = args.model_name_or_path generator = pipeline('text-generation', model=model_path, device=device, top_k=4, penalty_alpha=0.5) output = generator("My name is Clara and I am", max_length=300, num_return_sequences=1) print(output)