-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
【Hackathon 第三期 No.4】 为 Paddle 新增 cummax API #45073
Closed
OccupyMars2025
wants to merge
2
commits into
PaddlePaddle:develop
from
OccupyMars2025:hackathon-3rd-task4-add-cummax
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3079,6 +3079,7 @@ def cumsum(x, axis=None, dtype=None, name=None): | |
else: | ||
return _C_ops.cumsum(x, 'axis', axis, 'flatten', flatten) | ||
|
||
# renziji: the static mode part is different, does it need to be modified ??? | ||
check_type(x, 'x', (Variable), 'cumsum') | ||
locals_var = locals().copy() | ||
kwargs = dict() | ||
|
@@ -3089,6 +3090,73 @@ def cumsum(x, axis=None, dtype=None, name=None): | |
return _cum_sum_(**kwargs) | ||
|
||
|
||
def cummax(x, axis=None, dtype=None, name=None): | ||
""" | ||
The cumulative sum of the elements along a given axis. | ||
|
||
**Note**: | ||
The first element of the result is the same as the first element of the input. | ||
|
||
Args: | ||
x (Tensor): The input tensor needed to be cumsumed. | ||
axis (int, optional): The dimension to accumulate along. -1 means the last dimension. The default (None) is to compute the cumsum over the flattened array. | ||
dtype (str, optional): The data type of the output tensor, can be float32, float64, int32, int64. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. The default value is None. | ||
name (str, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. | ||
|
||
Returns: | ||
Tensor, the result of cumsum operator. | ||
|
||
Examples: | ||
.. code-block:: python | ||
|
||
import paddle | ||
|
||
data = paddle.arange(12) | ||
data = paddle.reshape(data, (3, 4)) | ||
|
||
y = paddle.cumsum(data) | ||
# [ 0 1 3 6 10 15 21 28 36 45 55 66] | ||
|
||
y = paddle.cumsum(data, axis=0) | ||
# [[ 0 1 2 3] | ||
# [ 4 6 8 10] | ||
# [12 15 18 21]] | ||
|
||
y = paddle.cumsum(data, axis=-1) | ||
# [[ 0 1 3 6] | ||
# [ 4 9 15 22] | ||
# [ 8 17 27 38]] | ||
|
||
y = paddle.cumsum(data, dtype='float64') | ||
print(y.dtype) | ||
# paddle.float64 | ||
""" | ||
if axis is None: | ||
flatten = True | ||
else: | ||
flatten = False | ||
if dtype is not None and x.dtype != convert_np_dtype_to_dtype_(dtype): | ||
x = cast(x, dtype) | ||
|
||
if in_dygraph_mode(): | ||
if axis is None: axis = -1 | ||
return _C_ops.final_state_cummax(x, axis, flatten, False, False) | ||
if _in_legacy_dygraph(): | ||
if axis is None: | ||
return _C_ops.cummax(x, 'flatten', flatten) | ||
else: | ||
return _C_ops.cummax(x, 'axis', axis, 'flatten', flatten) | ||
Comment on lines
+3146
to
+3148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你好,Paddle底层过了改造,以后老动态图API不再放在_C_ops,而是放在_legacy_C_ops下。辛苦这里也修改一下吧。 |
||
|
||
check_type(x, 'x', (Variable), 'cummax') | ||
locals_var = locals().copy() | ||
kwargs = dict() | ||
for name, val in locals_var.items(): | ||
if val is not None: | ||
kwargs[name] = val | ||
_cum_sum_ = generate_layer_fn('cummax') | ||
return _cum_sum_(**kwargs) | ||
|
||
|
||
def logcumsumexp(x, axis=None, dtype=None, name=None): | ||
r""" | ||
The logarithm of the cumulative summation of the exponentiation of the elements along a given axis. | ||
|
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.
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.
你好,Paddle底层过了改造,同意去掉了final_state_前缀。麻烦把这里的final_state_删掉吧~
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.
@OccupyMars2025
改造的PR见 :#45306
开发文档的改造见:#45306 (comment)