Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions api/tests/dropout_nd.py
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里为啥要重新定义一遍dropout_nd

Copy link
Collaborator Author

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 走不到这里

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好像少个config模块

Copy link
Collaborator Author

@zhangboSJTU zhangboSJTU Sep 22, 2023

Choose a reason for hiding this comment

The 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)
66 changes: 66 additions & 0 deletions api/tests_v2/configs/dropout_nd.json
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]"
}
}
}]