Replies: 1 comment
-
看起来涉及到飞桨框架动转静功能与打包工具的机制冲突,建议到飞桨框架仓库提问~ |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🔎 Search before asking
🐛 Bug (问题描述)
采用nuitka打包paddleocr后,进行推理任务执行,报错如下:OSError: could not get source code
转换原因分析:
直接原因:inspect.getsourcelines/inspect.findsource 这类 Python 标准库的源码检查工具,只能获取有源码文件的函数/类的源代码。如果你的代码是:
被 Nuitka、PyInstaller 等工具打包成了二进制(.exe/.pyd/.so),
或者是交互式环境、Jupyter、某些 Cython/Numba 编译的函数,
或者是 zipimport、egg、wheel 等非源码分发方式,
那么 inspect 就无法找到源码文件,自然会报 OSError: could not get source code。
PaddlePaddle 的 dy2static/jit 问题
PaddlePaddle 的动态图转静态(dy2static)和 JIT 导出模型时,会尝试用 inspect 获取模型的 forward 函数源码,做 AST 分析和转换。这在源码环境下没问题,但在打包环境下(如 Nuitka、PyInstaller)会100%失败。
但由于实际需要必须采用nuitka打包模式运行推理,应该如何修改可以让训练动态图模型导出为推理静态图模型,当前发现导出onnx模型也需要先转为静态图。
🏃♂️ Environment (运行环境)
paddlepaddle-gpu 2.4.2.post117(使用此版本原因是没有torch导入冲突且没有_dtype的paddle.tensor报错)
paddleocr 2.10.0
cuda 11.8
paddle2onnx 1.3.1
🌰 Minimal Reproducible Example (最小可复现问题的Demo)
python -m nuitka --standalone --include-package=paddleocr --include-package=utils --include-package=numpy --include-package=PIL --include-package=scipy --include-package=skimage --include-package=yaml --include-package=dicttoxml --include-package=xml --include-package=threading --include-package=queue --include-package=socket --include-package=logging --include-package=tempfile --include-package=platform --include-package=ctypes --include-package=glob --follow-imports --enable-plugin=numpy server.py
Beta Was this translation helpful? Give feedback.
All reactions