PaddleX icon indicating copy to clipboard operation
PaddleX copied to clipboard

fix: `DocVLMPredictor` device use error

Open gouzil opened this issue 9 months ago • 5 comments

fix

  • 在使用 PaddleOCR 时遇到的 PaddleX DocVLMPredictor 显存分配异常情况

复现代码

from paddleocr import PPStructureV3

pipeline = PPStructureV3(device="gpu:1") # device 指定为任意,非默认 device 即可

表现形式

当使用 PPStructureV3(device="cpu"), 同时有 gpu 时,DocVLMPredictor 下的几个模型会被加载到 gpu:0 上,并占用大约 2034MiB 显存

修复方案

  • 修改 device 设置策略,优先加载 kwargs 传入,当 device 为 None 时加载 pp_option 中的 device。(paddlex 框架内居然有两种 device 加载选项挺奇怪的)

TODO

  • 现有的 paddlex/inference/models/common/vlm/flash_attn_utils.py 下的 is_flash_attn_available 函数也有类似问题,需要换一种形式确认是否支持 flash_attention

gouzil avatar Jul 09 '25 12:07 gouzil

Thanks for your contribution!

paddle-bot[bot] avatar Jul 09 '25 12:07 paddle-bot[bot]

@luotao1 能帮忙看看 cla 为啥过不了嘛,还有应该找谁 review

gouzil avatar Jul 10 '25 03:07 gouzil

  • self.pp_option.device_type != "cpu"如果设置device为cpu,那self.device依然是None,依然会加载模型到gpu:0上。

done,我这没有权限能查看 ci 日志,能帮忙看看 ci 挂了是啥原因嘛

gouzil avatar Jul 16 '25 13:07 gouzil

哈喽,感谢PR。

依然存在一些小问题哈,在你的逻辑里:

                self.device = constr_device(
                    self.pp_option.device_type,
                    (
                        str(self.pp_option.device_id)
                        if self.pp_option.device_type != "cpu"
                        else None
                    ),
                )

如果设置self.pp_option.device_type为gpu,但是self.pp_option.device_id如果为默认参数None,那么会导致str(self.pp_option.device_id)为"None",进而输入给constr_device导致错误的device_id形式。

方便的话,辛苦更正上述问题重新PR。

感谢您的共享精神,besides,代码的修改所涉及的所有变量,辛苦考虑到每一种可能的情况。

BluebirdStory avatar Aug 19 '25 13:08 BluebirdStory

方便的话,辛苦更正上述问题重新PR。

Done

gouzil avatar Sep 06 '25 03:09 gouzil