Skip to content

Commit

Permalink
add benchmark for maxout/put_along_axis/take_along_axis, test=documen…
Browse files Browse the repository at this point in the history
…t_fix (#1326)
  • Loading branch information
m3ngyang authored Mar 4, 2022
1 parent 3a67159 commit af074d0
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/dynamic_tests_v2/maxout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (c) 2022 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 *


class MaxoutConfig(APIConfig):
def __init__(self):
super(MaxoutConfig, self).__init__('maxout')
self.feed_spec = {"range": [-1, 1]}
self.run_torch = False


class PaddleMaxout(PaddleDynamicAPIBenchmarkBase):
def build_graph(self, config):
x = self.variable(name="x", shape=config.x_shape, dtype=config.x_dtype)
result = paddle.nn.functional.maxout(x=x,
groups=config.groups,
axis=config.axis)

self.feed_list = [x]
self.fetch_list = [result]
if config.backward:
self.append_gradients(result, [x])


if __name__ == '__main__':
test_main(pd_dy_obj=PaddleMaxout(), config=MaxoutConfig())
45 changes: 45 additions & 0 deletions api/dynamic_tests_v2/put_along_axis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (c) 2022 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 *


class PutAlongAxisConfig(APIConfig):
def __init__(self):
super(PutAlongAxisConfig, self).__init__("put_along_axis")
self.feed_spec = [{"range": [-1, 1]}, {"range": [0, 100]}]
self.run_torch = False


class PaddlePutAlongAxis(PaddleDynamicAPIBenchmarkBase):
def build_graph(self, config):
arr = self.variable(name="arr",
shape=config.arr_shape,
dtype=config.arr_dtype)
indices = self.variable(name="indices",
shape=config.indices_shape,
dtype=config.indices_dtype)
result = paddle.put_along_axis(arr=arr,
indices=indices,
values=config.values,
axis=config.axis)

self.feed_list = [arr]
self.fetch_list = [result]
if config.backward:
self.append_gradients(result, [arr])


if __name__ == '__main__':
test_main(pd_dy_obj=PaddlePutAlongAxis(), config=PutAlongAxisConfig())
44 changes: 44 additions & 0 deletions api/dynamic_tests_v2/take_along_axis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2022 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 *


class TakeAlongAxisConfig(APIConfig):
def __init__(self):
super(TakeAlongAxisConfig, self).__init__("take_along_axis")
self.feed_spec = [{"range": [-1, 1]}, {"range": [0, 100]}]
self.run_torch = False


class PaddleTakeAlongAxis(PaddleDynamicAPIBenchmarkBase):
def build_graph(self, config):
arr = self.variable(name="arr",
shape=config.arr_shape,
dtype=config.arr_dtype)
indices = self.variable(name="indices",
shape=config.indices_shape,
dtype=config.indices_dtype)
result = paddle.take_along_axis(arr=arr,
indices=indices,
axis=config.axis)

self.feed_list = [arr, indices]
self.fetch_list = [result]
if config.backward:
self.append_gradients(result, [arr])


if __name__ == '__main__':
test_main(pd_dy_obj=PaddleTakeAlongAxis(), config=TakeAlongAxisConfig())
40 changes: 40 additions & 0 deletions api/tests_v2/configs/maxout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"op": "maxout",
"param_info": {
"groups": {
"type": "int",
"value": "2"
},
"axis": {
"type": "int",
"value": "-1"
},
"x": {
"dtype": "float32",
"shape": "[32L, 12L, 128L, 128L]",
"type": "Variable"
}
},
"repeat": 5000
},
{
"op": "maxout",
"param_info": {
"groups": {
"type": "int",
"value": "2"
},
"axis": {
"type": "int",
"value": "-1"
},
"x": {
"dtype": "float32",
"shape": "[32L, 8L, 1024L, 3072L]",
"type": "Variable"
}
},
"repeat": 5000
}
]
48 changes: 48 additions & 0 deletions api/tests_v2/configs/put_along_axis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[
{
"op": "put_along_axis",
"param_info": {
"arr": {
"dtype": "float32",
"shape": "[200, 300]",
"type": "Variable"
},
"indices": {
"dtype": "int",
"shape": "[1, 1]",
"type": "Variable"
},
"values": {
"type": "float32",
"value": "99"
},
"axis": {
"type": "int",
"value": "0"
}
}
},
{
"op": "put_along_axis",
"param_info": {
"arr": {
"dtype": "float32",
"shape": "[1024L, 3072L]",
"type": "Variable"
},
"indices": {
"dtype": "int",
"shape": "[1, 1]",
"type": "Variable"
},
"values": {
"type": "float32",
"value": "1000"
},
"axis": {
"type": "int",
"value": "0"
}
}
}
]
40 changes: 40 additions & 0 deletions api/tests_v2/configs/take_along_axis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"op": "take_along_axis",
"param_info": {
"arr": {
"dtype": "float32",
"shape": "[200, 300]",
"type": "Variable"
},
"indices": {
"dtype": "int",
"shape": "[1, 1]",
"type": "Variable"
},
"axis": {
"type": "int",
"value": "0"
}
}
},
{
"op": "take_along_axis",
"param_info": {
"arr": {
"dtype": "float32",
"shape": "[1024L, 3072L]",
"type": "Variable"
},
"indices": {
"dtype": "int",
"shape": "[1, 1]",
"type": "Variable"
},
"axis": {
"type": "int",
"value": "0"
}
}
}
]

0 comments on commit af074d0

Please sign in to comment.