diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index d12af3ad0084316a9b99c44d4daf7d4d3cc2b53e..16bdbbbe8e9f573b8f153e118ff7bea34daea7c5 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -7,6 +7,12 @@ if (CLIENT) endif() if (SERVER) + if (WITH_GPU) + set(SERVER_PACKAGE_NAME "paddle-serving-server-gpu") + elseif(WITH_XPU) + set(SERVER_PACKAGE_NAME "paddle-serving-server-xpu") + endif() + elseif(WITH_XPU) file(INSTALL pipeline DESTINATION paddle_serving_server) file(GLOB_RECURSE SERVING_SERVER_PY_FILES paddle_serving_server/*.py) set(PY_FILES ${SERVING_SERVER_PY_FILES}) @@ -74,7 +80,7 @@ if (SERVER) endif() if(WITH_LITE) - set(VERSION_SUFFIX xpu) + set(VERSION_SUFFIX 2) endif() add_custom_command( diff --git a/python/gen_version.py b/python/gen_version.py index ed812a924189afbbfbe9dd1410df48ad2658aab1..6a266dd20eacd21093eeb34a5469cd48c9f7d036 100644 --- a/python/gen_version.py +++ b/python/gen_version.py @@ -34,10 +34,16 @@ def update_info(file_name, feature, info): f.write(new_str) -if len(sys.argv) > 2: +if len(sys.argv) > 2 and len(sys.argv[2]) > 0: update_info("paddle_serving_server/version.py", "version_suffix", sys.argv[2]) +package_name = '${SERVER_PACKAGE_NAME}' +if package_name.endswith('gpu'): + update_info("paddle_serving_server/version.py", "device_type", "1") +elif package_name.endswith('xpu'): + update_info("paddle_serving_server/version.py", "device_type", "2") + path = "paddle_serving_" + sys.argv[1] commit_id = subprocess.check_output(['git', 'rev-parse', 'HEAD']) update_info(path + "/version.py", "commit_id", commit_id) diff --git a/python/paddle_serving_client/__init__.py b/python/paddle_serving_client/__init__.py index f46f435badc5fc11bc67b0a629d2b1d5ea61e5d9..23745bce5237db721eb4734ab2ee115416268b90 100644 --- a/python/paddle_serving_client/__init__.py +++ b/python/paddle_serving_client/__init__.py @@ -15,4 +15,7 @@ from . import version +from . import client +from .client import * + __version__ = version.serving_client_version diff --git a/python/paddle_serving_server/__init__.py b/python/paddle_serving_server/__init__.py index 6a900ebec9919ff5d367f42ef5963376ea7b9f66..b74caf7d64e8c42f9d56310381aa5b1a001ac63d 100644 --- a/python/paddle_serving_server/__init__.py +++ b/python/paddle_serving_server/__init__.py @@ -26,7 +26,9 @@ from paddle_serving_server import ( serve, monitor, rpc_service, - dag, -) + dag, ) + +from .dag import * +from .server import * __version__ = version.serving_server_version diff --git a/python/paddle_serving_server/serve.py b/python/paddle_serving_server/serve.py index 257f19ddcb28c06c229c3b6ad7b90ea6207cf68e..3f7ea5c7557bb3c30167392bbe18c634bfae2386 100644 --- a/python/paddle_serving_server/serve.py +++ b/python/paddle_serving_server/serve.py @@ -30,6 +30,7 @@ if sys.version_info.major == 2: elif sys.version_info.major == 3: from http.server import BaseHTTPRequestHandler, HTTPServer + def serve_args(): parser = argparse.ArgumentParser("serve") parser.add_argument( @@ -90,6 +91,7 @@ def serve_args(): help="container_id for authentication") return parser.parse_args() + def start_standard_model(serving_port): # pylint: disable=doc-string-missing args = parse_args() thread_num = args.thread @@ -141,6 +143,7 @@ def start_standard_model(serving_port): # pylint: disable=doc-string-missing server.prepare_server(workdir=workdir, port=port, device=device) server.run_server() + def start_gpu_card_model(index, gpuid, port, args): # pylint: disable=doc-string-missing workdir = args.workdir gpuid = int(gpuid) @@ -189,7 +192,6 @@ def start_gpu_card_model(index, gpuid, port, args): # pylint: disable=doc-strin if args.use_lite: server.set_lite() - device = "arm" server.set_device(device) if args.use_xpu: @@ -230,7 +232,7 @@ def start_multi_card(args, serving_port=None): # pylint: disable=doc-string-mis else: env_gpus = [] if args.use_lite: - print("run arm server.") + print("run using paddle-lite.") start_gpu_card_model(-1, -1, args) elif len(gpus) <= 0: print("gpu_ids not set, going to run cpu service.") diff --git a/python/paddle_serving_server/server.py b/python/paddle_serving_server/server.py index e0686662f674973ac13594536c23067a7b5745f7..bd33bfdccc905f5839e28e5ddefed10abda40761 100644 --- a/python/paddle_serving_server/server.py +++ b/python/paddle_serving_server/server.py @@ -1,10 +1,26 @@ +# Copyright (c) 2021 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 os import tarfile import socket import paddle_serving_server as paddle_serving_server +from .proto import server_configure_pb2 as server_sdk +from .proto import general_model_config_pb2 as m_config +import google.protobuf.text_format import time -from .version import serving_server_version +from .version import serving_server_version, version_suffix, device_type from contextlib import closing import argparse @@ -12,6 +28,7 @@ import sys if sys.platform.startswith('win') is False: import fcntl import shutil +import platform import numpy as np import grpc import sys @@ -19,6 +36,7 @@ import sys from multiprocessing import Pool, Process from concurrent import futures + class Server(object): def __init__(self): self.server_handle_ = None @@ -144,32 +162,18 @@ class Server(object): engine.runtime_thread_num = 0 engine.batch_infer_size = 0 engine.enable_batch_align = 0 - engine.model_data_path = model_config_path + engine.model_dir = model_config_path engine.enable_memory_optimization = self.memory_optimization engine.enable_ir_optimization = self.ir_optimization - engine.static_optimization = False - engine.force_update_static_cache = False engine.use_trt = self.use_trt - if os.path.exists('{}/__params__'.format(model_config_path)): - suffix = "" - else: - suffix = "_DIR" - if device == "arm": - engine.use_lite = self.use_lite - engine.use_xpu = self.use_xpu - engine.type = "PaddleInferenceEngine" - # if device == "cpu": - # if use_encryption_model: - # engine.type = "FLUID_CPU_ANALYSIS_ENCRPT" - # else: - # engine.type = "FLUID_CPU_ANALYSIS" + suffix - # elif device == "gpu": - # if use_encryption_model: - # engine.type = "FLUID_GPU_ANALYSIS_ENCRPT" - # else: - # engine.type = "FLUID_GPU_ANALYSIS" + suffix - # elif device == "arm": - # engine.type = "FLUID_ARM_ANALYSIS" + suffix + engine.use_lite = self.use_lite + engine.use_xpu = self.use_xpu + if not os.path.exists('{}/__params__'.format(model_config_path)): + engine.combined_model = True + if use_encryption_model: + engine.encrypted_model = True + engine.type = "PaddleInfer" + self.model_toolkit_conf.engines.extend([engine]) def _prepare_infer_service(self, port): @@ -259,7 +263,7 @@ class Server(object): str(f.read()), self.model_conf) # check config here # print config here - + def use_mkl(self, flag): self.mkl_flag = flag @@ -272,15 +276,27 @@ class Server(object): avx_flag = True if avx_flag: if mkl_flag: - device_version = "serving-cpu-avx-mkl-" + device_version = "cpu-avx-mkl" else: - device_version = "serving-cpu-avx-openblas-" + device_version = "cpu-avx-openblas" else: if mkl_flag: print( "Your CPU does not support AVX, server will running with noavx-openblas mode." ) - device_version = "serving-cpu-noavx-openblas-" + device_version = "cpu-noavx-openblas" + return device_version + + def get_serving_bin_name(self): + if device_type == "0": + device_version = self.get_device_version() + elif device_type == "1": + if version_suffix == "101" or version_suffix == "102": + device_version = "gpu-" + version_suffix + else: + device_version = "gpu-cuda" + version_suffix + elif device_type == "2": + device_version = "xpu-" + platform.machine() return device_version def download_bin(self): @@ -289,21 +305,10 @@ class Server(object): #acquire lock version_file = open("{}/version.py".format(self.module_path), "r") - import re - for line in version_file.readlines(): - # to add, version_suffix - if re.match("cuda_version", line): - cuda_version = line.split("\"")[1] - if cuda_version == "101" or cuda_version == "102": - device_version = "serving-gpu-" + cuda_version + "-" - elif cuda_version == "arm" or cuda_version == "arm-xpu": - device_version = "serving-" + cuda_version + "-" - else: - device_version = "serving-gpu-cuda" + cuda_version + "-" - - folder_name = device_version + serving_server_version - tar_name = folder_name + ".tar.gz" - bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name + + tar_name = self.get_serving_bin_name() + ".tar.gz" + bin_url = "https://paddle-serving.bj.bcebos.com/bin/serving-%s-%s.tar.gz" % ( + self.get_serving_bin_name(), serving_server_version) self.server_path = os.path.join(self.module_path, folder_name) download_flag = "{}/{}.is_download".format(self.module_path, @@ -346,8 +351,7 @@ class Server(object): version_file.close() os.chdir(self.cur_path) self.bin_path = self.server_path + "/serving" - - + def prepare_server(self, workdir=None, port=9292, @@ -466,6 +470,7 @@ class Server(object): os.system(command) + class MultiLangServer(object): def __init__(self): self.bserver_ = Server() @@ -508,10 +513,10 @@ class MultiLangServer(object): def set_op_graph(self, op_graph): self.bserver_.set_op_graph(op_graph) - + def use_mkl(self, flag): self.bserver_.use_mkl(flag) - + def set_memory_optimize(self, flag=False): self.bserver_.set_memory_optimize(flag) diff --git a/python/paddle_serving_server/version.py b/python/paddle_serving_server/version.py index b774c2237242cc488ee14ef85b1142929a3879d7..ea643ee24d6d4eb8df3b1711ed46fa1657b547f1 100644 --- a/python/paddle_serving_server/version.py +++ b/python/paddle_serving_server/version.py @@ -11,9 +11,11 @@ # 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. -""" Paddle Serving Client version string """ +""" Paddle Serving Server version string """ serving_client_version = "0.0.0" serving_server_version = "0.0.0" module_proto_version = "0.0.0" +version_suffix = "" +device_type = "0" cuda_version = "9" commit_id = "" diff --git a/python/requirements.txt b/python/requirements.txt index 6771d1adea85c0fd7ac32c26fcfd7dfe3f2cbdd4..bfe418f5d26f43c92fc64197ea7163c7c2ef61a2 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -2,14 +2,15 @@ numpy>=1.12, <=1.16.4 ; python_version<"3.5" shapely==1.7.0 wheel>=0.34.0, <0.35.0 setuptools>=44.1.0 -opencv-python==4.2.0.32 google>=2.0.3 -opencv-python==4.2.0.32 protobuf>=3.12.2 grpcio-tools>=1.28.1 grpcio>=1.28.1 func-timeout>=4.3.5 pyyaml>=1.3.0 -sentencepiece==0.1.92 flask>=1.1.2 ujson>=2.0.3 +sentencepiece==0.1.92; platform_machine != "aarch64" +sentencepiece; platform_machine == "aarch64" +opencv-python==4.2.0.32; platform_machine != "aarch64" +opencv-python; platform_machine == "aarch64" diff --git a/python/requirements_mac.txt b/python/requirements_mac.txt index df05a2908fb9d76decf716d6a523783a118bdb20..09a32ed0f20ee51c1b06ee9fba7abec5120ee0c6 100644 --- a/python/requirements_mac.txt +++ b/python/requirements_mac.txt @@ -2,14 +2,13 @@ numpy>=1.12, <=1.16.4 ; python_version<"3.5" shapely==1.7.0 wheel>=0.34.0, <0.35.0 setuptools>=44.1.0 -opencv-python==4.2.0.32 google>=2.0.3 opencv-python==4.2.0.32 protobuf>=3.12.2 -grpcio-tools>=1.33.2 -grpcio>=1.33.2 func-timeout>=4.3.5 pyyaml>=1.3.0 -sentencepiece==0.1.83 flask>=1.1.2 ujson>=2.0.3 +grpcio-tools>=1.33.2 +grpcio>=1.33.2 +sentencepiece==0.1.83 diff --git a/python/setup.py.server.in b/python/setup.py.server.in index 07e8dc380f7788adea599ce827da01d5583808b2..b9bc1c1e7f7394f1ae0c8fec3f172d4d249e3d42 100644 --- a/python/setup.py.server.in +++ b/python/setup.py.server.in @@ -19,11 +19,15 @@ from __future__ import print_function from setuptools import setup, Distribution, Extension from setuptools import find_packages from setuptools import setup -from paddle_serving_server.version import serving_server_version +from paddle_serving_server.version import serving_server_version, version_suffix import util -max_version, mid_version, min_version = util.python_version() +package_version = serving_server_version.replace('-', '') +if version_suffix != "": + version_suffix = "post" + version_suffix + package_version = package_version + "." + version_suffix +max_version, mid_version, min_version = util.python_version() # gen pipeline proto code util.gen_pipeline_code("paddle_serving_server") @@ -55,8 +59,8 @@ package_dir={'paddle_serving_server': package_data={'paddle_serving_server': ['pipeline/gateway/libproxy_server.so'],} setup( - name='paddle-serving-server', - version=serving_server_version.replace('-', ''), + name='${SERVER_PACKAGE_NAME}', + version= package_version, description= ('Paddle Serving Package for saved model with PaddlePaddle'), url='https://github.com/PaddlePaddle/Serving', diff --git a/python/setup.py.server_gpu.in b/python/setup.py.server_gpu.in deleted file mode 100644 index 7e10da1dfe76dab40803413d3b1e1f5d762ff512..0000000000000000000000000000000000000000 --- a/python/setup.py.server_gpu.in +++ /dev/null @@ -1,91 +0,0 @@ -# Copyright (c) 2020 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. -"""Setup for pip package.""" -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - -from setuptools import setup, Distribution, Extension -from setuptools import find_packages -from setuptools import setup -from paddle_serving_server.version import serving_server_version, cuda_version -import util - -if cuda_version != "trt": - cuda_version = "post" + cuda_version - -max_version, mid_version, min_version = util.python_version() -# gen pipeline proto code -util.gen_pipeline_code("paddle_serving_server") - -REQUIRED_PACKAGES = [ - 'six >= 1.10.0', 'protobuf >= 3.11.0', 'grpcio <= 1.33.2', 'grpcio-tools <= 1.33.2', - 'flask >= 1.1.1', 'func_timeout', 'pyyaml' -] - -packages=['paddle_serving_server', - 'paddle_serving_server.proto', - 'paddle_serving_server.pipeline', - 'paddle_serving_server.pipeline.proto', - 'paddle_serving_server.pipeline.gateway', - 'paddle_serving_server.pipeline.gateway.proto'] - -package_dir={'paddle_serving_server': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server', - 'paddle_serving_server.proto': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/proto', - 'paddle_serving_server.pipeline': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/pipeline', - 'paddle_serving_server.pipeline.proto': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/pipeline/proto', - 'paddle_serving_server.pipeline.gateway': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/pipeline/gateway', - 'paddle_serving_server.pipeline.gateway.proto': - '${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/pipeline/gateway/proto'} - -package_data={'paddle_serving_server': ['pipeline/gateway/libproxy_server.so'],} - -setup( - name='paddle-serving-server-gpu', - version=serving_server_version.replace('-', '') + "." + cuda_version, - description= - ('Paddle Serving Package for saved model with PaddlePaddle'), - url='https://github.com/PaddlePaddle/Serving', - author='PaddlePaddle Author', - author_email='guru4elephant@gmail.com', - install_requires=REQUIRED_PACKAGES, - packages=packages, - package_data=package_data, - package_dir=package_dir, - # PyPI package information. - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'Intended Audience :: Education', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: Apache Software License', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Topic :: Scientific/Engineering', - 'Topic :: Scientific/Engineering :: Mathematics', - 'Topic :: Scientific/Engineering :: Artificial Intelligence', - 'Topic :: Software Development', - 'Topic :: Software Development :: Libraries', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - license='Apache 2.0', - keywords=('paddle-serving serving-server deployment industrial easy-to-use'))