未验证 提交 99ec2c16 编写于 作者: H HongyuJia 提交者: GitHub

[Clean fluid] Clean fluid elementwise_min (part1) (#48033)

* clean fluid elementwise_min

* fix elementwise_min op testcase
上级 29a0987a
......@@ -465,7 +465,7 @@ class AdaptiveLocalSGDOptimizer(MetaOptimizerBase):
min_local_steps = layers.fill_constant(
shape=[1], dtype='int64', value=1
)
next_local_steps = layers.elementwise_min(
next_local_steps = paddle.minimum(
next_local_steps, max_local_steps
)
next_local_steps = paddle.maximum(
......
......@@ -680,9 +680,7 @@ class NoamDecay(LearningRateDecay):
a = self.create_lr_var(self.step_num**-0.5)
b = self.create_lr_var((self.warmup_steps**-1.5) * self.step_num)
lr_value = (
self.learning_rate
* (self.d_model**-0.5)
* layers.elementwise_min(a, b)
self.learning_rate * (self.d_model**-0.5) * paddle.minimum(a, b)
)
return lr_value
......
......@@ -23,6 +23,7 @@ strategy according to this module.
import math
import numbers
import paddle
from . import control_flow
from . import nn
from . import ops
......@@ -109,9 +110,7 @@ def noam_decay(d_model, warmup_steps, learning_rate=1.0):
a = global_step**-0.5
b = (warmup_steps**-1.5) * global_step
lr_value = (
learning_rate * (d_model**-0.5) * nn.elementwise_min(a, b)
)
lr_value = learning_rate * (d_model**-0.5) * paddle.minimum(a, b)
return lr_value
......@@ -364,9 +363,7 @@ def polynomial_decay(
decay_steps_var = tensor.fill_constant(
shape=[1], dtype='float32', value=float(decay_steps)
)
global_step = nn.elementwise_min(
x=global_step, y=decay_steps_var
)
global_step = paddle.minimum(x=global_step, y=decay_steps_var)
decayed_lr = (learning_rate - end_learning_rate) * (
(1 - global_step / decay_steps) ** power
......
......@@ -140,7 +140,7 @@ class TestDiv(TestMul):
class TestMin(TestMul):
def set_test_op(self):
self.op = paddle.fluid.layers.elementwise_min
self.op = paddle.minimum
class TestMax(TestMul):
......
......@@ -18,6 +18,7 @@ from op_test import OpTest, skip_check_grad_ci
import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
from paddle import _legacy_C_ops
paddle.enable_static()
......@@ -213,7 +214,7 @@ class TestElementwiseMinOpFP16(unittest.TestCase):
y = paddle.to_tensor(y_np)
x.stop_gradient = False
y.stop_gradient = False
z = fluid.layers.elementwise_min(x, y, axis)
z = _legacy_C_ops.elementwise_min(x, y, 'axis', axis)
x_g, y_g = paddle.grad([z], [x, y])
return (
z.numpy().astype(dtype),
......
......@@ -649,14 +649,12 @@ class TestLayer(LayerTest):
with self.dynamic_graph():
with _test_eager_guard():
min_eager_ret = layers.elementwise_min(
to_variable(n), to_variable(n2)
)
min_eager_ret = paddle.minimum(to_variable(n), to_variable(n2))
max_eager_ret = paddle.maximum(to_variable(n), to_variable(n2))
min_eager_ret_value = min_eager_ret.numpy()
max_eager_ret_value = max_eager_ret.numpy()
min_ret = layers.elementwise_min(to_variable(n), to_variable(n2))
min_ret = paddle.minimum(to_variable(n), to_variable(n2))
max_ret = paddle.maximum(to_variable(n), to_variable(n2))
min_ret_value = min_ret.numpy()
max_ret_value = max_ret.numpy()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册