mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-24 17:10:35 +08:00
[Serving]ppcls preprocessor support gpu (#615)
* serving ppcls support gpu * serving ppcls preprocessor use cpu
This commit is contained in:
@@ -54,3 +54,4 @@ PaddleClas模型导出,请参考其文档说明[模型导出](https://github.c
|
|||||||
|
|
||||||
- [Python部署](python)
|
- [Python部署](python)
|
||||||
- [C++部署](cpp)
|
- [C++部署](cpp)
|
||||||
|
- [服务化部署](serving)
|
||||||
|
|||||||
@@ -68,6 +68,9 @@ class TritonPythonModel:
|
|||||||
__file__)) + "/inference_cls.yaml"
|
__file__)) + "/inference_cls.yaml"
|
||||||
self.preprocess_ = fd.vision.classification.PaddleClasPreprocessor(
|
self.preprocess_ = fd.vision.classification.PaddleClasPreprocessor(
|
||||||
yaml_path)
|
yaml_path)
|
||||||
|
if args['model_instance_kind'] == 'GPU':
|
||||||
|
device_id = int(args['model_instance_device_id'])
|
||||||
|
self.preprocess_.use_gpu(device_id)
|
||||||
|
|
||||||
def execute(self, requests):
|
def execute(self, requests):
|
||||||
"""`execute` must be implemented in every Python model. `execute`
|
"""`execute` must be implemented in every Python model. `execute`
|
||||||
|
|||||||
@@ -20,7 +20,11 @@ output [
|
|||||||
|
|
||||||
instance_group [
|
instance_group [
|
||||||
{
|
{
|
||||||
count: 1
|
# The number of instances is 1
|
||||||
kind: KIND_CPU
|
count: 1
|
||||||
|
# Use CPU, GPU inference option is:KIND_GPU
|
||||||
|
kind: KIND_CPU
|
||||||
|
# The instance is deployed on the 0th GPU card
|
||||||
|
# gpus: [0]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -151,8 +151,7 @@ pybind11::capsule FDTensorToDLPack(FDTensor& fd_tensor) {
|
|||||||
|
|
||||||
dlpack_tensor->dl_tensor.dtype = FDToDlpackType(fd_tensor.dtype);
|
dlpack_tensor->dl_tensor.dtype = FDToDlpackType(fd_tensor.dtype);
|
||||||
|
|
||||||
// TODO(liqi): FDTensor add device_id
|
dlpack_tensor->dl_tensor.device.device_id = fd_tensor.device_id;
|
||||||
dlpack_tensor->dl_tensor.device.device_id = 0;
|
|
||||||
if(fd_tensor.device == Device::GPU) {
|
if(fd_tensor.device == Device::GPU) {
|
||||||
if (fd_tensor.is_pinned_memory) {
|
if (fd_tensor.is_pinned_memory) {
|
||||||
dlpack_tensor->dl_tensor.device.device_type = DLDeviceType::kDLCUDAHost;
|
dlpack_tensor->dl_tensor.device.device_type = DLDeviceType::kDLCUDAHost;
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ void BindPaddleClas(pybind11::module& m) {
|
|||||||
if (!self.Run(&images, &outputs)) {
|
if (!self.Run(&images, &outputs)) {
|
||||||
pybind11::eval("raise Exception('Failed to preprocess the input data in PaddleClasPreprocessor.')");
|
pybind11::eval("raise Exception('Failed to preprocess the input data in PaddleClasPreprocessor.')");
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < outputs.size(); ++i) {
|
if (!self.WithGpu()) {
|
||||||
outputs[i].StopSharing();
|
for (size_t i = 0; i < outputs.size(); ++i) {
|
||||||
|
outputs[i].StopSharing();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return outputs;
|
return outputs;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ class FASTDEPLOY_DECL PaddleClasPreprocessor {
|
|||||||
*/
|
*/
|
||||||
void UseGpu(int gpu_id = -1);
|
void UseGpu(int gpu_id = -1);
|
||||||
|
|
||||||
|
bool WithGpu() { return use_cuda_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool BuildPreprocessPipelineFromConfig(const std::string& config_file);
|
bool BuildPreprocessPipelineFromConfig(const std::string& config_file);
|
||||||
std::vector<std::shared_ptr<Processor>> processors_;
|
std::vector<std::shared_ptr<Processor>> processors_;
|
||||||
|
|||||||
Reference in New Issue
Block a user