CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[SOT][FasterGuard] add IsDenseTensorHoldAllocationMatchGuard
#72823
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
[SOT][FasterGuard] add IsDenseTensorHoldAllocationMatchGuard
#72823
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a new guard to the JIT executor that checks whether a dense tensor holds an allocation before proceeding.
- Uses
IsDenseTensorHoldAllocationMatchGuard
inmake_faster_guard
when encountering a null/uninitialized tensor. - Declares and implements the new guard in C++ (
guards.h
andguards.cc
). - Exposes the guard to Python via pybind11 binding in
jit.cc
.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py | Insert IsDenseTensorHoldAllocationMatchGuard in make_faster_guard |
paddle/fluid/pybind/sot/guards.h | Declare IsDenseTensorHoldAllocationMatchGuard |
paddle/fluid/pybind/sot/guards.cc | Implement IsDenseTensorHoldAllocationMatchGuard::check |
paddle/fluid/pybind/jit.cc | Bind the new guard to Python |
Comments suppressed due to low confidence (1)
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py:529
- [nitpick] This new guard path is introduced without accompanying unit tests to verify behavior when tensors do or do not hold allocation; consider adding tests to cover both scenarios.
paddle.framework.core.GuardNode(
return false; | ||
} | ||
|
||
PyObject* result = PyObject_CallOneArg(method, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result
object returned by PyObject_CallOneArg
is never decref'd, causing a memory leak. Add Py_DECREF(result)
after extracting its truth value.
Copilot uses AI. Check for mistakes.
paddle/fluid/pybind/jit.cc
Outdated
std::shared_ptr<IsDenseTensorHoldAllocationMatchGuard>>( | ||
*m, | ||
"IsDenseTensorHoldAllocationMatchGuard", | ||
R"DOC(IsDenseTensorHoldAllocationMatchGuard Class.)DOC") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The pybind11 binding for IsDenseTensorHoldAllocationMatchGuard
lacks a descriptive docstring. Including its purpose and expected behavior would help maintainers.
R"DOC(IsDenseTensorHoldAllocationMatchGuard Class.)DOC") | |
R"DOC( | |
IsDenseTensorHoldAllocationMatchGuard Class. | |
This guard checks whether a DenseTensor instance holds a valid allocation. | |
It is used to ensure that the memory allocation associated with a DenseTensor | |
is consistent and valid during runtime. This is particularly useful in scenarios | |
where memory integrity and allocation state need to be verified. | |
Example: | |
guard = IsDenseTensorHoldAllocationMatchGuard() | |
# Use the guard in conjunction with other runtime checks. | |
)DOC") |
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this 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 new guard IsDenseTensorHoldAllocationMatchGuard
to optimize tensor allocation checks in the SOT executor.
- Defines and implements
IsDenseTensorHoldAllocationMatchGuard
in C++ (guards.h / guards.cc) - Exposes the new guard to Python via pybind11 in jit.cc
- Applies the guard in the Python executor when
meta.is_null()
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py | Use the new guard in the null-meta branch |
paddle/fluid/pybind/sot/guards.h | Declare the IsDenseTensorHoldAllocationMatchGuard class |
paddle/fluid/pybind/sot/guards.cc | Implement the guard’s check method |
paddle/fluid/pybind/jit.cc | Bind IsDenseTensorHoldAllocationMatchGuard to Python |
Comments suppressed due to low confidence (2)
paddle/fluid/pybind/sot/guards.cc:240
- No tests have been added to verify the behavior of
IsDenseTensorHoldAllocationMatchGuard::check
. Consider adding unit tests for both allocated and unallocated tensor cases to ensure correctness.
bool IsDenseTensorHoldAllocationMatchGuard::check(PyObject* value) {
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py:530
- The code references
IsDenseTensorHoldAllocationMatchGuard
underpaddle.framework.core
, but the pybind binding is in the JIT module namespace. Ensure the class is exported inpaddle.framework.core
or adjust the import path to match where it's bound.
paddle.framework.core.IsDenseTensorHoldAllocationMatchGuard(),
paddle/fluid/pybind/jit.cc
Outdated
std::shared_ptr<IsDenseTensorHoldAllocationMatchGuard>>( | ||
*m, | ||
"IsDenseTensorHoldAllocationMatchGuard", | ||
R"DOC(IsDenseTensorHoldAllocationMatchGuard Class.)DOC") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The binding for IsDenseTensorHoldAllocationMatchGuard
lacks a descriptive docstring. Consider enhancing the R"DOC(...)"
block to explain the guard’s purpose and when it should be used.
R"DOC(IsDenseTensorHoldAllocationMatchGuard Class.)DOC") | |
R"DOC( | |
IsDenseTensorHoldAllocationMatchGuard Class. | |
This guard is used to check whether a DenseTensor object holds a specific | |
memory allocation. It is primarily used in scenarios where the memory | |
allocation of a DenseTensor needs to be validated for correctness or | |
consistency during runtime. | |
Use this guard when you need to ensure that a DenseTensor's memory | |
allocation matches expected criteria, such as during debugging or | |
when implementing custom tensor operations. | |
Example: | |
guard = IsDenseTensorHoldAllocationMatchGuard() | |
# Use the guard in your logic to validate DenseTensor allocations. | |
)DOC") |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsDenseTensorHoldAllocationMatchGuard
IsDenseTensorHoldAllocationMatchGuard
PR Category
Performance Optimization
PR Types
Performance
Description
IsDenseTensorHoldAllocationMatchGuard
用于检查 tensor 是否分配