From 62033f25a2f221b6099f34c8d44733ed9d8c2582 Mon Sep 17 00:00:00 2001 From: Weilong Wu Date: Mon, 5 Sep 2022 09:53:56 +0800 Subject: [PATCH] [Eager, Performance optimization] fix prelu interface under eager mode (#45694) --- python/paddle/fluid/dygraph/nn.py | 3 +++ python/paddle/fluid/layers/nn.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/python/paddle/fluid/dygraph/nn.py b/python/paddle/fluid/dygraph/nn.py index 09030e9441..6a13e0bb49 100644 --- a/python/paddle/fluid/dygraph/nn.py +++ b/python/paddle/fluid/dygraph/nn.py @@ -2418,6 +2418,9 @@ class PRelu(layers.Layer): default_initializer=Constant(1.0)) def forward(self, input): + if in_dygraph_mode(): + return _C_ops.prelu(input, self.weight, "NCHW", self._mode) + check_variable_and_dtype(input, 'input', ['float32'], 'PRelu') out = self._helper.create_variable_for_type_inference(self._dtype) self._helper.append_op(type="prelu", diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index cf138cc5a4..d458e71fc0 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -10259,6 +10259,9 @@ def prelu(x, mode, param_attr=None, data_format="NCHW", name=None): dtype=dtype, is_bias=False, default_initializer=Constant(0.25)) + if in_dygraph_mode(): + return _C_ops.prelu(x, alpha, data_format, mode) + out = helper.create_variable_for_type_inference(dtype) helper.append_op(type="prelu", inputs={ -- GitLab