[Place] Fix comparision between pybind place and Place #73532
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
PR Category
User Experience
PR Types
Bug fixes
Description
Pcard-75624
tensor.place(pybind自phi::Place)和paddle.XXXPlace(pybind自phi::XXXPlace)之间进行比较时,经常出现不符合预期的结果,举例如下其根本原因在于 paddle.XXXPlace和tensor.place两个类型来自C++ pybind上来的
class XXXPlace(phi::Place) {...}和class Place {...},Paddle/paddle/fluid/pybind/place.cc
Line 493 in 6a5494b
而在为XXXPlace pybind时并没有为指定其父类,导致了从python传到C++的 place obj无法被py::isinstance识别,一直执行的是return false这个分支
Paddle/paddle/fluid/pybind/place.cc
Lines 664 to 670 in 6a5494b
通过在py::class_中指定父类,从而让python传到C++的obj也可以被
py::isinstance识别到,这样就可以让place之间的判等行为恢复正常