[Bug Fix] fix extra version info error (#1959)

This commit is contained in:
DefTruth
2023-05-18 13:25:04 +08:00
committed by GitHub
parent b080b90f80
commit 04ef882ee1

View File

@@ -43,7 +43,6 @@ if os.name != "nt" and os.path.exists(trt_directory):
break break
logging.basicConfig(level=logging.NOTSET) logging.basicConfig(level=logging.NOTSET)
from .code_version import version, git_version, extra_version_info from .code_version import version, git_version, extra_version_info
from .code_version import enable_trt_backend, enable_paddle_backend, with_gpu from .code_version import enable_trt_backend, enable_paddle_backend, with_gpu
@@ -56,68 +55,69 @@ sys_platform = platform.platform().lower()
def get_paddle_version(): def get_paddle_version():
paddle_version = "" paddle_version = ""
try:
import pkg_resources
paddle_version = pkg_resources.require(
"paddlepaddle-gpu")[0].version.split(".post")[0]
except:
try: try:
paddle_version = pkg_resources.require( import pkg_resources
"paddlepaddle")[0].version.split(".post")[0] paddle_version = pkg_resources.require("paddlepaddle-gpu")[
0].version.split(".post")[0]
except: except:
pass try:
return paddle_version paddle_version = pkg_resources.require("paddlepaddle")[
0].version.split(".post")[0]
except:
pass
return paddle_version
def should_import_paddle(): def should_import_paddle():
if "paddle2.4" in extra_version_info: if ("paddle2.4" in extra_version_info) or ("post24" in extra_version_info):
paddle_version = get_paddle_version() paddle_version = get_paddle_version()
if paddle_version != "" and paddle_version <= '2.4.2' and paddle_version != "0.0.0": if paddle_version != "" and paddle_version <= '2.4.2' and paddle_version != "0.0.0":
return True return True
return False return False
def should_set_tensorrt(): def should_set_tensorrt():
if with_gpu == 'ON' and enable_paddle_backend == 'ON' and enable_trt_backend == 'ON': if with_gpu == 'ON' and enable_paddle_backend == 'ON' and enable_trt_backend == 'ON':
return True return True
return False return False
def tensorrt_is_avaliable(): def tensorrt_is_avaliable():
# Note(qiuyanjun): Only support linux now. # Note(qiuyanjun): Only support linux now.
found_trt_lib = False found_trt_lib = False
if ('linux' in sys_platform) and ('LD_LIBRARY_PATH' in os.environ.keys()): if ('linux' in sys_platform) and ('LD_LIBRARY_PATH' in os.environ.keys()):
for lib_path in os.environ['LD_LIBRARY_PATH'].split(':'): for lib_path in os.environ['LD_LIBRARY_PATH'].split(':'):
if os.path.exists(os.path.join(lib_path, 'libnvinfer.so')): if os.path.exists(os.path.join(lib_path, 'libnvinfer.so')):
found_trt_lib = True found_trt_lib = True
break break
return found_trt_lib return found_trt_lib
try: try:
# windows: no conflict between fastdeploy and paddle. # windows: no conflict between fastdeploy and paddle.
# linux: must import paddle first to solve the conflict. # linux: must import paddle first to solve the conflict.
# macos: still can not solve the conflict between fastdeploy and paddle, # macos: still can not solve the conflict between fastdeploy and paddle,
# due to the global flags redefined in paddle/paddle_inference so. # due to the global flags redefined in paddle/paddle_inference so.
# we got the error (ERROR: flag 'xxx' was defined more than once). # we got the error (ERROR: flag 'xxx' was defined more than once).
if "linux" in sys_platform: if "linux" in sys_platform:
if should_import_paddle(): if should_import_paddle():
import paddle # need import paddle first for paddle2.4.x import paddle # need import paddle first for paddle2.4.x
# check whether tensorrt in LD_LIBRARY_PATH for fastdeploy # check whether tensorrt in LD_LIBRARY_PATH for fastdeploy
if should_set_tensorrt() and (not tensorrt_is_avaliable()): if should_set_tensorrt() and (not tensorrt_is_avaliable()):
if os.path.exists(trt_directory): if os.path.exists(trt_directory):
logging.info( logging.info(
"\n[WARNING] Can not find TensorRT lib in LD_LIBRARY_PATH for FastDeploy! \ "\n[WARNING] Can not find TensorRT lib in LD_LIBRARY_PATH for FastDeploy! \
\n[WARNING] Please export [ YOUR CUSTOM TensorRT ] lib path to LD_LIBRARY_PATH first, or run the command: \ \n[WARNING] Please export [ YOUR CUSTOM TensorRT ] lib path to LD_LIBRARY_PATH first, or run the command: \
\n[WARNING] Linux: 'export LD_LIBRARY_PATH=$(python -c 'from fastdeploy import trt_directory; print(trt_directory)'):$LD_LIBRARY_PATH'") \n[WARNING] Linux: 'export LD_LIBRARY_PATH=$(python -c 'from fastdeploy import trt_directory; print(trt_directory)'):$LD_LIBRARY_PATH'"
else: )
logging.info( else:
"\n[WARNING] Can not find TensorRT lib in LD_LIBRARY_PATH for FastDeploy! \ logging.info(
\n[WARNING] Please export [YOUR CUSTOM TensorRT] lib path to LD_LIBRARY_PATH first.") "\n[WARNING] Can not find TensorRT lib in LD_LIBRARY_PATH for FastDeploy! \
\n[WARNING] Please export [YOUR CUSTOM TensorRT] lib path to LD_LIBRARY_PATH first."
)
except: except:
pass pass
from .c_lib_wrap import ( from .c_lib_wrap import (
ModelFormat, ModelFormat,