-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[API Compatibility] Add paddle.Tensor.clamp_ ,paddle.nn.functional.logsigmoid, paddle.functional.meshgrid, paddle.nn.init.calculate_fan_in_and_fan_out ,paddle.autocast #76206
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ace5747
sharding stage3 bugfix
AlAuAu 4911b59
Merge branch 'PaddlePaddle:develop' into develop
AlAuAu 6b24646
sharding stage3 bugfix
AlAuAu e054b48
sharding stage3 bugfix
AlAuAu fbde952
sharding stage3 bugfix
AlAuAu 333bae9
sharding stage3 bugfix
AlAuAu 143d785
sharding stage3 bugfix
AlAuAu 183a930
Merge branch 'PaddlePaddle:develop' into develop
AlAuAu 312fc19
Merge branch 'PaddlePaddle:develop' into develop
AlAuAu 7fd48d9
support recompute's forward and backward in pipeline mode
AlAuAu f97edd4
Merge branch 'PaddlePaddle:develop' into develop
AlAuAu 025efc3
[API Compatibility] Add paddle.Tensor.clip_
AlAuAu dd52286
Merge branch 'PaddlePaddle:develop' into develop
AlAuAu 4e54642
Revert "support recompute's forward and backward in pipeline mode"
AlAuAu f45380c
Revert "[API Compatibility] Add paddle.Tensor.clip_"
AlAuAu dc28d5e
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu a8f7186
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 7fcdd48
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 6431d8f
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 9d93a48
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu fdb2a25
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu b2f67a7
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu fdce602
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 767effe
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 97e5dc1
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu b228dce
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 56deece
[API Compatibility] Add clip_、logsigmoid、_calculate_fan_in_and_fan_ou…
AlAuAu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,62 @@ | ||
| # Copyright (c) 2025 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 paddle | ||
| from paddle.base import core | ||
|
|
||
|
|
||
| @unittest.skipIf( | ||
| not core.is_compiled_with_cuda() and not core.is_compiled_with_xpu(), | ||
| "Require compiled with CUDA or XPU.", | ||
| ) | ||
| @unittest.skipIf( | ||
| core.is_compiled_with_cuda() | ||
| and paddle.device.cuda.get_device_capability()[0] < 7.0, | ||
| "run test when gpu's compute capability is at least 7.0.", | ||
| ) | ||
| @unittest.skipIf( | ||
| core.is_compiled_with_xpu() | ||
| and core.get_xpu_device_version(0) < core.XPUVersion.XPU3, | ||
| "run test when xpu's compute capability >= xpu3.", | ||
| ) | ||
| @unittest.skipIf( | ||
|
Contributor
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. 这两个xpu是不是重复的 |
||
| core.is_compiled_with_xpu() | ||
| and core.get_xpu_device_version(0) == core.XPUVersion.XPU3, | ||
| "Bugs on XPU3, disable temporarily", | ||
| ) | ||
| class TestCudaAutoCast(unittest.TestCase): | ||
| def setUp(self): | ||
| self._conv = paddle.nn.Conv2D(1, 1, 3, bias_attr=False) | ||
| self._linear = paddle.nn.Linear(4, 4) | ||
|
|
||
| def _run_autocast_test(self, ctx): | ||
| with paddle.autocast( | ||
| device_type='cuda', | ||
| enabled=True, | ||
| dtype=paddle.float16, | ||
| cache_enabled=True, | ||
| ): | ||
| out1 = self._conv(paddle.rand(shape=[1, 1, 6, 6], dtype='float32')) | ||
| out2 = out1 + paddle.rand(shape=out1.shape, dtype='float16') | ||
| out3 = self._linear(out2) | ||
|
|
||
| self.assertEqual(out1.dtype, paddle.float16) | ||
| self.assertEqual(out2.dtype, paddle.float16) | ||
| self.assertEqual(out3.dtype, paddle.float32) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -62,6 +62,22 @@ def _calculate_gain(nonlinearity, param): | |
| return recommended_gain[nonlinearity] | ||
|
|
||
|
|
||
| def _calculate_fan_in_and_fan_out(var: paddle.Tensor) -> tuple[int, int]: | ||
| shape = var.shape | ||
| if not shape or len(shape) == 0: | ||
| fan_in = fan_out = 1 | ||
| elif len(shape) == 1: | ||
| fan_in = fan_out = shape[0] | ||
| elif len(shape) == 2: | ||
| fan_in = shape[0] | ||
| fan_out = shape[1] | ||
| else: | ||
| receptive_field_size = np.prod(shape[2:]) | ||
| fan_in = shape[1] * receptive_field_size | ||
| fan_out = shape[0] * receptive_field_size | ||
| return (fan_in, fan_out) | ||
|
|
||
|
|
||
| class Test_calculate_gain(unittest.TestCase): | ||
| def test(self): | ||
| for nonlinearity in [ | ||
|
|
@@ -87,6 +103,27 @@ def test(self): | |
| ) | ||
|
|
||
|
|
||
| class TestCAlFanINOUT(unittest.TestCase): | ||
| def test_cal_fan_in_and_out(self): | ||
| x = paddle.tensor.randn([10]) | ||
| self.assertEqual( | ||
| _calculate_fan_in_and_fan_out(x), | ||
|
Contributor
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. 这里不用重新复制一个api过来,可以直接算好expect的值 |
||
| paddle.nn.init._calculate_fan_in_and_fan_out(x), | ||
| ) | ||
|
|
||
| y = paddle.tensor.randn([10, 10]) | ||
| self.assertEqual( | ||
| _calculate_fan_in_and_fan_out(y), | ||
| paddle.nn.init._calculate_fan_in_and_fan_out(y), | ||
| ) | ||
|
|
||
| z = paddle.randn([10, 10, 10]) | ||
| self.assertEqual( | ||
| _calculate_fan_in_and_fan_out(z), | ||
| paddle.nn.init._calculate_fan_in_and_fan_out(z), | ||
| ) | ||
|
|
||
|
|
||
| class Test_kaiming_uniform_(unittest.TestCase): | ||
| def check_kaiming_uniform( | ||
| self, tensor, a=0, mode='fan_in', nonlinearity='leaky_relu' | ||
|
|
||
Oops, something went wrong.
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.
这里的skipIf怎么写了这么多