Closed wangzy0327 closed 2 months ago
to_cinn_net 函数期望接收一个函数作为输入,但是在 StructureSystem 类的初始化过程中,你将 self.layout_predictor 作为一个类实例传递给了 to_cinn_net,可以尝试
def to_cinn_net(net, **kwargs):
build_strategy = paddle.static.BuildStrategy()
build_strategy.build_cinn_pass = True
return paddle.jit.to_static(
net.__call__,
build_strategy=build_strategy,
full_graph=True,
**kwargs
)
to_cinn_net 函数期望接收一个函数作为输入,但是在 StructureSystem 类的初始化过程中,你将 self.layout_predictor 作为一个类实例传递给了 to_cinn_net,可以尝试
def to_cinn_net(net, **kwargs): build_strategy = paddle.static.BuildStrategy() build_strategy.build_cinn_pass = True return paddle.jit.to_static( net.__call__, build_strategy=build_strategy, full_graph=True, **kwargs )
按您说的修改后,修改之后执行打印log如下:
I0912 03:31:32.091351 1318574 init.cc:234] ENV [CUSTOM_DEVICE_ROOT]=/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle_custom_device
I0912 03:31:32.091378 1318574 init.cc:143] Try loading custom device libs from: [/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle_custom_device]
I0912 03:31:32.103998 1318574 custom_device.cc:1099] Succeed in loading custom runtime in lib: /home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle_custom_device/libpaddle-custom-mlu.so
I0912 03:31:32.105597 1318574 custom_kernel.cc:63] Succeed in loading 262 custom kernel(s) from loaded lib(s), will be used like native ones.
I0912 03:31:32.105671 1318574 init.cc:155] Finished in LoadCustomDevice with libs_path: [/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle_custom_device]
I0912 03:31:32.105688 1318574 init.cc:240] CustomDevice: mlu, visible devices count: 1
[2024/09/12 03:31:32] ppocr INFO: Init Structure System True cinn
[2024/09/12 03:31:32] ppocr INFO: Init Structure layout ........
E0912 03:31:32.809263 1318574 analysis_config.cc:127] Please use PaddlePaddle with GPU version.
Traceback (most recent call last):
File "/home/wzy/paddle_tests/models/PaddleOCR/ppstructure/predict_system.py", line 419, in <module>
main(args)
File "/home/wzy/paddle_tests/models/PaddleOCR/ppstructure/predict_system.py", line 319, in main
structure_sys = StructureSystem(args)
File "/home/wzy/paddle_tests/models/PaddleOCR/ppstructure/predict_system.py", line 85, in __init__
self.layout_predictor = to_cinn_net(self.layout_predictor)
File "/home/wzy/paddle_tests/models/PaddleOCR/ppstructure/predict_system.py", line 47, in to_cinn_net
return paddle.jit.to_static(
File "/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle/jit/api.py", line 250, in to_static
return decorated(function)
File "/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle/jit/api.py", line 221, in decorated
decorated_obj=StaticClass(
File "/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 774, in __init__
super().__init__(function, input_spec, **kwargs)
File "/home/wzy/build-python3-10-14/lib/python3.10/site-packages/paddle/jit/dy2static/program_translator.py", line 337, in __init__
raise TypeError(
TypeError: When using 'to_static' to convert method of a class, please ensure the class inherits from nn.Layer
这里的predictor是对paddle inference的封装,而且类继承是的python的object,不是paddle.nn.Layer,所以不能用to_static。要对paddle模型用to_static
这里的predictor是对paddle inference的封装,而且类继承是的python的object,不是paddle.nn.Layer,所以不能用to_static。要对paddle模型用to_static
如何对Paddle模型用to_static呢?
🔎 Search before asking
🐛 Bug (问题描述)
参照文档执行ppstruture https://github.com/PaddlePaddle/PaddleOCR/blob/main/ppstructure/docs/inference.md#11-%E7%89%88%E9%9D%A2%E5%88%86%E6%9E%90%E8%A1%A8%E6%A0%BC%E8%AF%86%E5%88%AB 通过添加paddle.jit.to_static 代码,准备利用CINN后端进行进一步优化和性能提升。参照 predict_system.py文件进行修改执行,通过添加 to_cinn_net 函数来完成 cinn后端转换。具体修改如下:
执行命令
执行时出现的log如下:
如何解决上述问题,完成 ppstructure 到CINN后端 的转换?
🏃♂️ Environment (运行环境)
OS:Ubuntu20.04 Python 3.10 PaddleOCR 2.8.0 paddlepaddle 2.6
🌰 Minimal Reproducible Example (最小可复现问题的Demo)
predict_system.py 参照上面的predict_system.py 增加 to_cinn_net 函数