Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用Fastdeploy之后就无法导入Taskflow?另外同一进程无法加载两个Fastdeploy模型? #2506

Open
Strepsiades opened this issue Aug 15, 2024 · 2 comments

Comments

@Strepsiades
Copy link

环境windows, x86, cpu, paddle2.6.1, paddlenlp2.6.1, fastdeploy-python 1.07

我想在本地部署三个模型脚本,其中两个只依赖fastdeploy,第三个fastdeploy示例里没有因此用的是paddlenlp的Taskflow。

首先感谢fastdeploy团队,大大加速我的模型在cpu上的推理速度。但是现在遇到三个问题,其中前两个已经避开了,第三个有点麻烦:

第一,我的两个fastdeploy脚本就是使用example里的ocr和uie python脚本进行简单封装,创建模型对象,调用预测函数。这两个单独都能正常运行工作,但是两个不能运行在一个进程,否则第一个预测时会失效,表现为无返回结果不报错。这个我通过多进程调用解决了,两个都能正常工作。请问这是正常现象嘛,还是是bug?虽然我知道可能服务化部署多进程调用才是正确的,但是小规模使用还是希望一个进程直接调用比较方便。

第二,fastdeploy加载的模型内存对象如果出了作用域,即使用python默认的复制、return把赋值给别的变量,fastdeploy的模型也会失效,表现为无返回结果不报错。这个我通过创建对象,把模型保存在对象成员变量里把这个问题解决了。不过感觉这个行为和一般的python绑定cpp对象行为不一致,比如numpy的对象不管怎么复制还是在一个函数里创建,返回到函数外面也能用,不会失效。不知道会不会改进。

def create_model():
    uie_model = UIEModel(...)
    uie_model.predict(...) # 这里predict有效
    return uie_mode
uie_model = create_model()
uie_model.predict(...) # 这里predict失效,无报错,不返回结果  

第三,导入fastdeploy相关库后,无法导入Taskflow。反之,导入Taskflow后,无法导入fastdeploy。这个问题也没办法通过单个python解释器开启多进程脚本解决。我再wsl里测试也是类似效果。

import fastdeploy
from paddlenlp import Taskflow

报错

Error: Can not import paddle core while this file exists: d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\libpaddle.pyd
Traceback (most recent call last):
  File "d:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py", line 2, in <module>
    from paddlenlp import Taskflow
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddlenlp\__init__.py", line 33, in <module>
    import paddle
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\__init__.py", line 28, in <module>
    from .base import core  # noqa: F401
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\__init__.py", line 36, in <module>
    from . import core
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 380, in <module>
    raise e
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 268, in <module>
    from . import libpaddle
ImportError: DLL load failed while importing libpaddle: 找不到指定的程序。
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton> ^C
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton>
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton>  d:; cd 'd:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton'; & 'd:\miniconda\envs\fastdeploy\python.exe' 'c:\Users\zhaoy\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '56080' '--' 'd:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py' 
Error: Can not import paddle core while this file exists: d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\libpaddle.pyd
Traceback (most recent call last):
  File "d:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py", line 2, in <module>
    from paddlenlp import Taskflow
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddlenlp\__init__.py", line 33, in <module>
    import paddle
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\__init__.py", line 28, in <module>
    from .base import core  # noqa: F401
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\__init__.py", line 36, in <module>
    from . import core
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 380, in <module>
    raise e
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 268, in <module>
    from . import libpaddle
ImportError: DLL load failed while importing libpaddle: 找不到指定的程序。

如果反过来,如下:

from paddlenlp import Taskflow
import fastdeploy

报错

Error: Can not import paddle core while this file exists: d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\libpaddle.pyd
Traceback (most recent call last):
  File "d:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py", line 2, in <module>
    from paddlenlp import Taskflow
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddlenlp\__init__.py", line 33, in <module>
    import paddle
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\__init__.py", line 28, in <module>
    from .base import core  # noqa: F401
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\__init__.py", line 36, in <module>
    from . import core
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 380, in <module>
    raise e
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\paddle\base\core.py", line 268, in <module>
    from . import libpaddle
ImportError: DLL load failed while importing libpaddle: 找不到指定的程序。
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton> ^C
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton>
(fastdeploy) PS D:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton>  d:; cd 'd:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton'; & 'd:\miniconda\envs\fastdeploy\python.exe' 'c:\Users\zhaoy\.vscode\extensions\ms-python.debugpy-2024.10.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '56160' '--' 'd:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py' 
d:\miniconda\envs\fastdeploy\lib\site-packages\_distutils_hack\__init__.py:32: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml
  warnings.warn(
Traceback (most recent call last):
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\c_lib_wrap.py", line 164, in <module>
    from .libs.fastdeploy_main import *
ImportError: DLL load failed while importing fastdeploy_main: 找不到指定的程序。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py", line 3, in <module>
    import fastdeploy
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\__init__.py", line 122, in <module>
    from .c_lib_wrap import (
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\c_lib_wrap.py", line 166, in <module>
    raise RuntimeError(f"FastDeploy initalized failed! Error: {e}")
RuntimeError: FastDeploy initalized failed! Error: DLL load failed while importing fastdeploy_main: 找不到指定的程序。
@Jiang-Jia-Jun
Copy link
Collaborator

Jiang-Jia-Jun commented Aug 15, 2024

你看下将paddle从2.6.1降级到2.3.x 或者 2.4.x 是否能解决

@Strepsiades
Copy link
Author

Strepsiades commented Aug 16, 2024

你看下将paddle从2.6.1降级到2.3.x 或者 2.4.x 是否能解决

没有解决,报错

环境:
Python 3.10.14
paddlenlp 2.4.9
paddlepaddle 2.3.2
fastdeploy-python 1.0.7

运行

from paddlenlp import Taskflow
import fastdeploy

报错

d:\miniconda\envs\fastdeploy\lib\site-packages\setuptools\sandbox.py:15: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
d:\miniconda\envs\fastdeploy\lib\site-packages\pkg_resources\__init__.py:3144: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
d:\miniconda\envs\fastdeploy\lib\site-packages\_distutils_hack\__init__.py:32: UserWarning: Setuptools is replacing distutils. Support for replacing an already imported distutils is deprecated. In the future, this condition will fail. Register concerns at https://github.com/pypa/setuptools/issues/new?template=distutils-deprecation.yml
  warnings.warn(
d:\miniconda\envs\fastdeploy\lib\site-packages\paddlenlp\ops\ext_utils.py:24: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.dep_util import newer_group
d:\miniconda\envs\fastdeploy\lib\site-packages\paddlenlp\server\http_router\router.py:30: PydanticDeprecatedSince20: `pydantic.config.Extra` is deprecated, use literal values instead (e.g. `extra='allow'`). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/
  class RequestBase(BaseModel, extra=Extra.forbid):
Traceback (most recent call last):
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\c_lib_wrap.py", line 164, in <module>
    from .libs.fastdeploy_main import *
ImportError: DLL load failed while importing fastdeploy_main: 找不到指定的程序。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\SeafileData\rush1993\My Libraries\OneDrive\CodeLearning\Paddle\general_card_uie_singleton\test_scripts\test_import.py", line 2, in <module>
    import fastdeploy
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\__init__.py", line 122, in <module>
    from .c_lib_wrap import (
  File "d:\miniconda\envs\fastdeploy\lib\site-packages\fastdeploy\c_lib_wrap.py", line 166, in <module>
    raise RuntimeError(f"FastDeploy initalized failed! Error: {e}")
RuntimeError: FastDeploy initalized failed! Error: DLL load failed while importing fastdeploy_main: 找不到指定的程序。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants