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

fix LoDTensorArray crash in Debug mode build #37954

Merged

Conversation

Aganlengzi
Copy link
Contributor

@Aganlengzi Aganlengzi commented Dec 8, 2021

PR types

Others

PR changes

Others

Describe

Paddle中 LoDTensorArray 实际为 std::vector<LoDTensor> ,Pybind11针对stl容器提供自动转换功能,std::vector<LoDTensor>自动转换为List[LoDTensor];通过bind前添加PYBIND11_MAKE_OPAQUE(paddle::framework::LoDTensorArray)避免自动转换。

现有实现中:
pybind.cc中,bind前通过添加PYBIND11_MAKE_OPAQUE,避免自动转换为Python的List,Python层LoDTensorArray相关的功能基于此(LoDTensorArray不是Python List)完成。

reader_py.cc中,bind也有使用std::vector<framework::LoDTensor>,且在bind前没有添加PYBIND11_MAKE_OPAQUE,所以接口中会自动转换为List。

这样在Python层两者一起使用会造成不一致的情况,进而导致Debug Mode下参数传递问题。

为修复这种不一致,可以在reader_py.cc中添加PYBIND11_MAKE_OPAQUE,但这会产生副作用,即reader_py.cc中也有bind接口是期望自动转换的:MultiDeviceFeedReader::ResultList(),所以随着PYBIND11_MAKE_OPAQUE的添加,同时需要在Python层对期望得到List的调用进行LoDTensorArray对象的手动_move_to_list()调用,这样能够保持LoDTensorArray使用的一致性,同时也可以显式转换避免问题。

相关:#37387 #32252 #24863

@paddle-bot-old
Copy link

paddle-bot-old bot commented Dec 8, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@Aganlengzi Aganlengzi requested review from qili93 and sneaxiy December 9, 2021 07:29
Copy link
Contributor

@qili93 qili93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aganlengzi Aganlengzi merged commit 1f9a5d8 into PaddlePaddle:develop Dec 9, 2021
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

Successfully merging this pull request may close these issues.

3 participants