⚡️An Easy-to-use and Fast Deep Learning Model Deployment Toolkit for ☁️Cloud 📱Mobile and 📹Edge. Including Image, Video, Text and Audio 20+ main stream scenarios and 150+ SOTA models with end-to-end optimization, multi-platform and multi-framework support.
环境
【FastDeploy版本】: 按照官方编译步骤编译的昇腾版本
【编译命令】官网给出的命令
【系统平台】: Linux aarch64(Ubuntu 18.04)
【硬件】: 说明具体硬件型号,Ascend910
【编译语言】: Python3.9
【补充】所需要的paddle npu环境以及paddlelite环境以及FastDeploy环境已经参照官方的代码编译安装成功
examples
下的代码可以运行,但自己的代码不能运行-自己修改的是paddlenlp中无样本分类中的deploy中infer.py代码
-命令行命令 :python deploy/python/infer.py --model_dir ./checkpoint/model_best --device ascend --backend paddle_lite
-自己修改的infer.py代码如下:
Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
#
http://www.apache.org/licenses/LICENSE-2.0
#
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
import distutils.util import os from typing import Any, Dict, List, Union
import fastdeploy as fd import numpy as np
from paddlenlp.prompt import PromptDataCollatorWithPadding, UTCTemplate from paddlenlp.transformers import AutoTokenizer
def parse_arguments(): import argparse
class Predictor(object): def init(self, args, schema: list = None): self.set_schema(schema) self.tokenizer = AutoTokenizer.from_pretrained(args.model_dir) self.runtime = self.create_fd_runtime(args) self.batch_size = args.batch_size self.max_length = args.max_length self.template = UTCTemplate(self.tokenizer, self.max_length) self.collator = PromptDataCollatorWithPadding(self.tokenizer, return_tensors="np") self.pred_threshold = args.pred_threshold
if name == "main": args = parse_arguments() predictor = Predictor(args, schema=["这是一条差评", "这是一条好评"]) results = predictor.predict("房间干净明亮,非常不错") print(results)
--命令行输出的错误: (paddle-npu) [ma-user zero_shot_text_classification]$python deploy/python/infer.py --model_dir ./checkpoint/model_best --device ascend --backend paddle_lite I0823 15:27:01.683387 6783 init.cc:239] ENV [CUSTOM_DEVICE_ROOT]=/home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/paddle_custom_device I0823 15:27:01.683435 6783 init.cc:145] Try loading custom device libs from: [/home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/paddle_custom_device] I0823 15:27:02.237061 6783 custom_device.cc:1112] Successed in loading custom runtime in lib: /home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/paddle_custom_device/libpaddle-custom-npu.so I0823 15:27:02.243542 6783 custom_kernel.cc:76] Successed in loading 325 custom kernel(s) from loaded lib(s), will be used like native ones. I0823 15:27:02.243674 6783 init.cc:157] Finished in LoadCustomDevice with libs_path: [/home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/paddle_custom_device] I0823 15:27:02.243705 6783 init.cc:245] CustomDevice: npu, visible devices count: 1 /home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/_distutils_hack/init.py:33: UserWarning: Setuptools is replacing distutils. warnings.warn("Setuptools is replacing distutils.") [2023-08-23 15:27:05,892] [ INFO] - We are using <class 'paddlenlp.transformers.ernie.tokenizer.ErnieTokenizer'> to load './checkpoint/model_best'. Loading topology data from ./checkpoint/model_best Traceback (most recent call last): File "/home/ma-user/work/PaddleNLP/applications/zero_shot_text_classification/deploy/python/infer.py", line 263, in
predictor = Predictor(args, schema=["这是一条差评", "这是一条好评"])
File "/home/ma-user/work/PaddleNLP/applications/zero_shot_text_classification/deploy/python/infer.py", line 73, in init
self.runtime = self.create_fd_runtime(args)
File "/home/ma-user/work/PaddleNLP/applications/zero_shot_text_classification/deploy/python/infer.py", line 191, in create_fd_runtime
return fd.Runtime(option)
File "/home/ma-user/.conda/envs/paddle-npu/lib/python3.9/site-packages/fastdeploy/runtime.py", line 33, in init
assert self._runtime.init(
MemoryError: std::bad_alloc