-
Couldn't load subscription status.
- Fork 157
Add test_dropout_nd #1673
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
Add test_dropout_nd #1673
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright (c) 2023 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. | ||
|
|
||
| from common_import import * | ||
| import paddle | ||
| from paddle import _legacy_C_ops | ||
|
|
||
|
|
||
| # no dropout_nd in pytorch | ||
| def dropout_nd(x, | ||
| p=0.5, | ||
| axis=None, | ||
| training=True, | ||
| mode="upscale_in_train", | ||
| name=None): | ||
| drop_axes = [axis] if isinstance(axis, int) else list(axis) | ||
| seed = None | ||
| mode = ('downgrade_in_infer' | ||
| if mode == 'downscale_in_infer' else mode) # semantic transfer | ||
| out = _legacy_C_ops.dropout_nd( | ||
| x, | ||
| 'dropout_prob', | ||
| p, | ||
| 'is_test', | ||
| not training, | ||
| 'fix_seed', | ||
| seed is not None, | ||
| 'seed', | ||
| seed if seed is not None else 0, | ||
| 'dropout_implementation', | ||
| mode, | ||
| 'axis', | ||
| drop_axes, ) | ||
| return out | ||
|
|
||
|
|
||
| @benchmark_registry.register("dropout_nd") | ||
|
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. 好像少个config模块 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. done,make run_torch false |
||
| class PaddleDropoutNdConfig(APIConfig): | ||
| def __init__(self): | ||
| super(PaddleDropoutNdConfig, self).__init__('dropout_nd') | ||
| self.run_torch = False | ||
|
|
||
|
|
||
| @benchmark_registry.register("dropout_nd") | ||
| class PaddleDropoutNd(PaddleOpBenchmarkBase): | ||
| def build_graph(self, config): | ||
| x = self.variable(name='x', shape=config.x_shape, dtype=config.x_dtype) | ||
| result = dropout_nd( | ||
| x=x, p=config.p, axis=config.axis, mode=config.mode) | ||
|
|
||
| self.feed_list = [x] | ||
| self.fetch_list = [result] | ||
| if config.backward: | ||
| self.append_gradients(result[0], self.feed_list) | ||
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,66 @@ | ||
| [{ | ||
| "op": "dropout_nd", | ||
| "param_info": { | ||
| "mode": { | ||
| "type": "string", | ||
| "value": "upscale_in_train" | ||
| }, | ||
| "p": { | ||
| "type": "float", | ||
| "value": "0.5" | ||
| }, | ||
| "x": { | ||
| "dtype": "float32", | ||
| "shape": "[-1L, 16L, -1L]", | ||
| "type": "Variable" | ||
| }, | ||
| "axis": { | ||
| "type": "list", | ||
| "value": "[1]" | ||
| } | ||
| }, | ||
| "repeat": 2000 | ||
| }, { | ||
| "op": "dropout_nd", | ||
| "param_info": { | ||
| "mode": { | ||
| "type": "string", | ||
| "value": "downscale_in_infer" | ||
| }, | ||
| "p": { | ||
| "type": "float", | ||
| "value": "0.5" | ||
| }, | ||
| "x": { | ||
| "dtype": "float32", | ||
| "shape": "[-1L, 16L, -1L, -1L]", | ||
| "type": "Variable" | ||
| }, | ||
| "axis": { | ||
| "type": "list", | ||
| "value": "[0,1]" | ||
| } | ||
| }, | ||
| "repeat": 2000 | ||
| }, { | ||
| "op": "dropout_nd", | ||
| "param_info": { | ||
| "mode": { | ||
| "type": "string", | ||
| "value": "upscale_in_train" | ||
| }, | ||
| "p": { | ||
| "type": "float", | ||
| "value": "0.1" | ||
| }, | ||
| "x": { | ||
| "dtype": "float32", | ||
| "shape": "[32L, 128L, 768L]", | ||
| "type": "Variable" | ||
| }, | ||
| "axis": { | ||
| "type": "list", | ||
| "value": "[0]" | ||
| } | ||
| } | ||
| }] |
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.
这里为啥要重新定义一遍dropout_nd
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.
dropout_nd 的使用需要调用 paddle._legacy_C_ops.dropout_nd, paddle.dropout 走不到这里