Skip to content

[SOT][FasterGuard] add ExprNodeBase cleanup func #72552

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

gouzil
Copy link
Member

@gouzil gouzil commented Apr 29, 2025

PR Category

Performance Optimization

PR Types

Performance

Description

添加清理方法,用于解决过程中临时变量的清理

TODO:

  • 加个东西 check 一下?不过这样是不是会更慢了,而且需要考虑 immortal

Copy link

paddle-bot bot commented Apr 29, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Apr 29, 2025
@gouzil gouzil requested a review from Copilot April 29, 2025 07:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a cleanup mechanism within expression nodes to ensure temporary Python objects are properly released, thereby improving performance.

  • Introduces a virtual cleanup() method in ExprNodeBase and corresponding overrides in AttributeExprNode and ItemExprNode.
  • Implements a macro (DELAYED_CLEAN) to decrement reference counts and clean up stored Python objects.
  • Updates evaluation functions to record cleanupable objects during attribute and item access.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
paddle/fluid/pybind/sot/guards.h Added cleanup() methods and storage vectors in expression nodes.
paddle/fluid/pybind/sot/guards.cc Introduced DELAYED_CLEAN macro and updated eval methods.
Comments suppressed due to low confidence (1)

paddle/fluid/pybind/sot/guards.h:354

  • [nitpick] Consider renaming 'clean_py_obj_' to 'cleanup_py_objects_' to improve clarity regarding its purpose.
std::vector<PyObject*> clean_py_obj_;

Comment on lines 67 to 73
bool should_erase = true; \
if (*it) { \
Py_DECREF(*it); \
should_erase = (Py_REFCNT(*it) <= 0); \
} \
it = should_erase ? clean_py_obj_.erase(it) : ++it; \
} \
Copy link
Preview

Copilot AI Apr 29, 2025

Choose a reason for hiding this comment

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

Calling Py_REFCNT on a PyObject immediately after a Py_DECREF may cause undefined behavior if the object is deallocated when its reference count reaches zero. Consider updating the cleanup logic to avoid accessing deallocated memory.

Suggested change
bool should_erase = true; \
if (*it) { \
Py_DECREF(*it); \
should_erase = (Py_REFCNT(*it) <= 0); \
} \
it = should_erase ? clean_py_obj_.erase(it) : ++it; \
} \
if (*it) { \
PyObject* temp = *it; \
Py_DECREF(temp); \
it = clean_py_obj_.erase(it); \
} else { \
++it; \
} \

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant