-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Prim][PIR] binary_cross_entropy_with_logits forward decomp #61613
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
b7650fa
sigmoid_cross_entropy_with_logits forward decomp
zeroRains b05d121
mean_all forward decomp
zeroRains 013cf4f
add the test case for binary_cross_entropy_with_logits
zeroRains 976ac31
creat a new test file
zeroRains 617aa99
modify the assert method
zeroRains 4ce41f5
fix conflict
zeroRains 4950de4
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains 7395204
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains cb9c8a0
modify the test
zeroRains 135b544
fix code style
zeroRains b72d42d
add prim in check grad for test and handle the optional tensor
zeroRains b1532ac
fix conflict
zeroRains fb315d2
fix conflict
zeroRains b9d874f
fix conflict
zeroRains 02a9896
do not modify the third_party package
zeroRains c62da1c
fix conflict
zeroRains ae5b59f
fix merge bug
zeroRains 32989f7
Merge branch 'develop' into logit
zeroRains 9f8d513
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains 8529a00
fix conflict
zeroRains a5b28a3
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains f718e0c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains af41ecc
fix bug
zeroRains 0026451
modfiy the test data and change the file name
zeroRains c2edfa0
roback
zeroRains 6283cb5
fix bug
zeroRains c55191d
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains 2235976
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zeroRains 6c2bfe7
support mean_all for dynamic shape
zeroRains f954cd6
modify the type
zeroRains File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
85 changes: 85 additions & 0 deletions
85
test/legacy_test/test_binary_cross_entropy_with_logits_op.py
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
import numpy as np | ||
|
||
import paddle | ||
|
||
|
||
class TestBinaryCrossEntropyWithLogits(unittest.TestCase): | ||
def setUp(self): | ||
np.random.seed(2023) | ||
self.x = np.random.randn(300, 1000).astype("float32") | ||
self.y = np.random.randint(0, 2, (300, 1000)).astype("float32") | ||
self.logits = paddle.to_tensor(self.x) | ||
self.labels = paddle.to_tensor(self.y) | ||
self.weight = paddle.to_tensor( | ||
np.random.randn(300, 1000).astype("float32") | ||
) | ||
self.reduction = ["none", "mean", "sum"] | ||
self.pos_weight = paddle.to_tensor( | ||
np.random.randn(1000).astype("float32") | ||
) | ||
|
||
def test_binary_cross_entropy_with_logits(self): | ||
for reduction in self.reduction: | ||
dynamic_result = ( | ||
paddle.nn.functional.binary_cross_entropy_with_logits( | ||
self.logits, | ||
self.labels, | ||
weight=self.weight, | ||
reduction=reduction, | ||
pos_weight=self.pos_weight, | ||
) | ||
) | ||
paddle.core._set_prim_all_enabled(True) | ||
static_result = paddle.jit.to_static( | ||
paddle.nn.functional.binary_cross_entropy_with_logits, | ||
full_graph=True, | ||
)( | ||
self.logits, | ||
self.labels, | ||
weight=self.weight, | ||
reduction=reduction, | ||
pos_weight=self.pos_weight, | ||
) | ||
paddle.core._set_prim_all_enabled(False) | ||
np.testing.assert_allclose( | ||
dynamic_result.numpy(), static_result.numpy(), rtol=1e-4 | ||
) | ||
|
||
|
||
class TestBinaryCrossEntropyWithLogits1(TestBinaryCrossEntropyWithLogits): | ||
def setUp(self): | ||
super().setUp() | ||
self.weight = None | ||
|
||
|
||
class TestBinaryCrossEntropyWithLogits2(TestBinaryCrossEntropyWithLogits): | ||
def setUp(self): | ||
super().setUp() | ||
self.pos_weight = None | ||
|
||
|
||
class TestBinaryCrossEntropyWithLogits3(TestBinaryCrossEntropyWithLogits): | ||
def setUp(self): | ||
super().setUp() | ||
self.weight = None | ||
self.pos_weight = None | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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
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.
1e-5同上?
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.
同上