From 285f370b35bc029811e9866af7cf6d53113a3cc9 Mon Sep 17 00:00:00 2001 From: linjieccc <623543001@qq.com> Date: Tue, 1 Mar 2022 11:45:01 +0000 Subject: [PATCH 1/4] add benchmark for log_loss op --- api/dynamic_tests_v2/log_loss.py | 41 ++++++++++++++++++++++++++++++ api/tests_v2/configs/log_loss.json | 19 ++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 api/dynamic_tests_v2/log_loss.py create mode 100644 api/tests_v2/configs/log_loss.json diff --git a/api/dynamic_tests_v2/log_loss.py b/api/dynamic_tests_v2/log_loss.py new file mode 100644 index 0000000000..13ab08bfe8 --- /dev/null +++ b/api/dynamic_tests_v2/log_loss.py @@ -0,0 +1,41 @@ +# 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 LogLossConfig(APIConfig): + def __init__(self): + super(LogLossConfig, self).__init__("log_loss") + self.run_torch = False + self.feed_spec = [{"range": [-1, 1]}, {"range": [-1, 1]}] + + +class PDLogLoss(PaddleDynamicAPIBenchmarkBase): + def build_graph(self, config): + input = self.variable( + name='input', shape=config.input_shape, dtype=config.input_dtype) + label = self.variable( + name='label', shape=config.label_shape, dtype=config.label_dtype) + result = paddle.nn.functional.log_loss( + input=input, label=label, epsilon=config.epsilon) + + self.feed_list = [input, label] + self.fetch_list = [result] + if config.backward: + self.append_gradients(result, [input]) + + +if __name__ == '__main__': + test_main(pd_dy_obj=PDLogLoss(), config=LogLossConfig()) diff --git a/api/tests_v2/configs/log_loss.json b/api/tests_v2/configs/log_loss.json new file mode 100644 index 0000000000..7d34c3761c --- /dev/null +++ b/api/tests_v2/configs/log_loss.json @@ -0,0 +1,19 @@ +[{ + "op": "log_loss", + "param_info": { + "epsilon": { + "type": "float", + "value": "0.0001" + }, + "label": { + "dtype": "float32", + "shape": "[32L, 1L]", + "type": "Variable" + }, + "input": { + "dtype": "float32", + "shape": "[32L, 1L]", + "type": "Variable" + } + } +}] \ No newline at end of file From 70801f427588d3d29c7edf3eed109910350c4c24 Mon Sep 17 00:00:00 2001 From: linjieccc <623543001@qq.com> Date: Tue, 1 Mar 2022 14:05:40 +0000 Subject: [PATCH 2/4] update config --- api/tests_v2/configs/log_loss.json | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/api/tests_v2/configs/log_loss.json b/api/tests_v2/configs/log_loss.json index 7d34c3761c..de21666180 100644 --- a/api/tests_v2/configs/log_loss.json +++ b/api/tests_v2/configs/log_loss.json @@ -7,13 +7,31 @@ }, "label": { "dtype": "float32", - "shape": "[32L, 1L]", + "shape": "[3072L, 1L]", "type": "Variable" }, "input": { "dtype": "float32", - "shape": "[32L, 1L]", + "shape": "[3072L, 1L]", "type": "Variable" } } -}] \ No newline at end of file +}, { + "op": "log_loss", + "param_info": { + "epsilon": { + "type": "float", + "value": "0.001" + }, + "label": { + "dtype": "float32", + "shape": "[3072L, 1L]", + "type": "Variable" + }, + "input": { + "dtype": "float32", + "shape": "[3072L, 1L]", + "type": "Variable" + } + } +}] From d54c8d0d42b2d40fa0da7bd3a401c95bb84ca61a Mon Sep 17 00:00:00 2001 From: linjieccc <623543001@qq.com> Date: Wed, 2 Mar 2022 08:10:34 +0000 Subject: [PATCH 3/4] update config test=document_fix --- api/tests_v2/configs/log_loss.json | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/api/tests_v2/configs/log_loss.json b/api/tests_v2/configs/log_loss.json index de21666180..0106a5c2d5 100644 --- a/api/tests_v2/configs/log_loss.json +++ b/api/tests_v2/configs/log_loss.json @@ -7,15 +7,16 @@ }, "label": { "dtype": "float32", - "shape": "[3072L, 1L]", + "shape": "[30720L, 1L]", "type": "Variable" }, "input": { "dtype": "float32", - "shape": "[3072L, 1L]", + "shape": "[30720L, 1L]", "type": "Variable" } - } + }, + "repeat": 10000 }, { "op": "log_loss", "param_info": { @@ -25,13 +26,14 @@ }, "label": { "dtype": "float32", - "shape": "[3072L, 1L]", + "shape": "[40960L, 1L]", "type": "Variable" }, "input": { "dtype": "float32", - "shape": "[3072L, 1L]", + "shape": "[40960L, 1L]", "type": "Variable" } - } + }, + "repeat": 10000 }] From 212bd810db0ab74ce05c8c3d00cac9111009ccab Mon Sep 17 00:00:00 2001 From: linjieccc <623543001@qq.com> Date: Wed, 2 Mar 2022 08:24:59 +0000 Subject: [PATCH 4/4] update config test=document_fix --- api/dynamic_tests_v2/log_loss.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/dynamic_tests_v2/log_loss.py b/api/dynamic_tests_v2/log_loss.py index 13ab08bfe8..dea59185ac 100644 --- a/api/dynamic_tests_v2/log_loss.py +++ b/api/dynamic_tests_v2/log_loss.py @@ -30,7 +30,6 @@ def build_graph(self, config): name='label', shape=config.label_shape, dtype=config.label_dtype) result = paddle.nn.functional.log_loss( input=input, label=label, epsilon=config.epsilon) - self.feed_list = [input, label] self.fetch_list = [result] if config.backward: