diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index 165005e808ca9071d616ac4b637be58cca7730fb..6e87936e7298329fee39052cd4a186e79263956f 100755 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -1798,15 +1798,6 @@ func : mode backward : mode_grad -- api : modulo - args : (Tensor x, Tensor y) - output : Tensor - infer_meta : - func : ElementwiseInferMeta - kernel : - func : modulo - backward : modulo_grad - - api : momentum_ args : (Tensor param, Tensor grad, Tensor velocity, Tensor learning_rate, Tensor master_param, float mu, bool use_nesterov = false, str regularization_method = "", float regularization_coeff = 0.0, bool multi_precision = false, float rescale_grad = 1.0f) output : Tensor(param_out), Tensor(velocity_out), Tensor(master_param_out) @@ -2128,6 +2119,15 @@ func : relu6 backward : relu6_grad +- api : remainder + args : (Tensor x, Tensor y) + output : Tensor + infer_meta : + func : ElementwiseInferMeta + kernel : + func : remainder + inplace : (x -> out) + - api : renorm args : (Tensor x, float p, int axis, float max_norm) output : Tensor diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 307e7c453a9e3aea472ad5f9ae3072018c51b5bf..24793465b53ab6ef06101b1d0f8bf444088fc0e6 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -1576,17 +1576,6 @@ kernel : func : mode_grad -- backward_api : modulo_grad - forward : modulo (Tensor x, Tensor y) -> Tensor(out) - args : (Tensor x, Tensor y, Tensor out_grad, int axis = -1) - output : Tensor(x_grad), Tensor(y_grad) - infer_meta : - func : GeneralBinaryGradInferMeta - param : [x, y] - kernel : - func : modulo_grad - no_need_buffer : x, y - - backward_api : multi_dot_grad forward : multi_dot (Tensor[] x) -> Tensor(out) args : (Tensor[] x, Tensor out_grad) diff --git a/paddle/phi/kernels/cpu/elementwise_kernel.cc b/paddle/phi/kernels/cpu/elementwise_kernel.cc index f090ddd5bbe9a7bc77ddaf469913bed3fdbdce72..b7c3f3c84823f90377a31c1e57d302deadd6e944 100644 --- a/paddle/phi/kernels/cpu/elementwise_kernel.cc +++ b/paddle/phi/kernels/cpu/elementwise_kernel.cc @@ -46,21 +46,21 @@ void MinimumRawKernel(const Context& dev_ctx, } template -void ModuloRawKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - int axis, - DenseTensor* out) { +void RemainderRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + int axis, + DenseTensor* out) { // allocate memory for out dev_ctx.template Alloc(out); auto x_dims = x.dims(); auto y_dims = y.dims(); if (x_dims.size() >= y_dims.size()) { - funcs::ElementwiseCompute, T>( - dev_ctx, x, y, axis, funcs::ModuloFunctor(), out); + funcs::ElementwiseCompute, T>( + dev_ctx, x, y, axis, funcs::RemainderFunctor(), out); } else { - funcs::ElementwiseCompute, T>( - dev_ctx, x, y, axis, funcs::InverseModuloFunctor(), out); + funcs::ElementwiseCompute, T>( + dev_ctx, x, y, axis, funcs::InverseRemainderFunctor(), out); } } @@ -139,10 +139,10 @@ PD_REGISTER_KERNEL(minimum_raw, int, int64_t, phi::dtype::bfloat16) {} -PD_REGISTER_KERNEL(modulo_raw, +PD_REGISTER_KERNEL(remainder_raw, CPU, ALL_LAYOUT, - phi::ModuloRawKernel, + phi::RemainderRawKernel, float, double, int, diff --git a/paddle/phi/kernels/elementwise_kernel.cc b/paddle/phi/kernels/elementwise_kernel.cc index 5e29eb5ace675fd2cf246827e585633b44cbb541..ebdb6299f352ff43ef0a940722e8599c4e56a308 100644 --- a/paddle/phi/kernels/elementwise_kernel.cc +++ b/paddle/phi/kernels/elementwise_kernel.cc @@ -38,12 +38,12 @@ void MinimumKernel(const Context& dev_ctx, } template -void ModuloKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out) { +void RemainderKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + DenseTensor* out) { int axis = -1; - ModuloRawKernel(dev_ctx, x, y, axis, out); + RemainderRawKernel(dev_ctx, x, y, axis, out); } template @@ -96,8 +96,14 @@ PD_REGISTER_KERNEL(minimum, int, int64_t, phi::dtype::bfloat16) {} -PD_REGISTER_KERNEL( - modulo, CPU, ALL_LAYOUT, phi::ModuloKernel, float, double, int, int64_t) {} +PD_REGISTER_KERNEL(remainder, + CPU, + ALL_LAYOUT, + phi::RemainderKernel, + float, + double, + int, + int64_t) {} PD_REGISTER_KERNEL( floor_divide, CPU, ALL_LAYOUT, phi::FloorDivideKernel, int, int64_t) {} PD_REGISTER_KERNEL(elementwise_heaviside, @@ -139,8 +145,14 @@ PD_REGISTER_KERNEL(minimum, int64_t, phi::dtype::float16, phi::dtype::bfloat16) {} -PD_REGISTER_KERNEL( - modulo, GPU, ALL_LAYOUT, phi::ModuloKernel, float, double, int, int64_t) {} +PD_REGISTER_KERNEL(remainder, + GPU, + ALL_LAYOUT, + phi::RemainderKernel, + float, + double, + int, + int64_t) {} PD_REGISTER_KERNEL( floor_divide, KPS, ALL_LAYOUT, phi::FloorDivideKernel, int, int64_t) {} PD_REGISTER_KERNEL(elementwise_heaviside, diff --git a/paddle/phi/kernels/elementwise_kernel.h b/paddle/phi/kernels/elementwise_kernel.h index a39da52e7e3b543f6ed43e89f728b7a9dec12a48..65040e1937a59a399549ae3637f1115e2d13bdec 100644 --- a/paddle/phi/kernels/elementwise_kernel.h +++ b/paddle/phi/kernels/elementwise_kernel.h @@ -60,18 +60,18 @@ void MinimumKernel(const Context& dev_ctx, DenseTensor* out); template -void ModuloRawKernel(const Context& dev_ctx, +void RemainderRawKernel(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y, + int axis, + DenseTensor* out); + +template +void RemainderKernel(const Context& dev_ctx, const DenseTensor& x, const DenseTensor& y, - int axis, DenseTensor* out); -template -void ModuloKernel(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y, - DenseTensor* out); - template void FloorDivideRawKernel(const Context& dev_ctx, const DenseTensor& x, @@ -134,13 +134,13 @@ DenseTensor Minimum(const Context& dev_ctx, } template -DenseTensor Modulo(const Context& dev_ctx, - const DenseTensor& x, - const DenseTensor& y) { +DenseTensor Remainder(const Context& dev_ctx, + const DenseTensor& x, + const DenseTensor& y) { DenseTensor dense_out; MetaTensor meta_out(&dense_out); ElementwiseInferMeta(x, y, &meta_out); - ModuloKernel(dev_ctx, x, y, &dense_out); + RemainderKernel(dev_ctx, x, y, &dense_out); return dense_out; } diff --git a/paddle/phi/kernels/funcs/elementwise_functor.h b/paddle/phi/kernels/funcs/elementwise_functor.h index e30ab8716b608942fcadf47b456271d9f1a8260f..bfbfd28abbe1941071ca1aa83e78422420a41b7c 100644 --- a/paddle/phi/kernels/funcs/elementwise_functor.h +++ b/paddle/phi/kernels/funcs/elementwise_functor.h @@ -21,7 +21,7 @@ limitations under the License. */ #if defined(__xpu__) #include -#include "xpu/kernel/math_xpu2.h" //pow() +#include "xpu/kernel/math_xpu2.h" // pow() #endif namespace phi { @@ -499,7 +499,7 @@ struct MinGradXYFunctor { // Modulo template -struct ModuloFunctor { +struct RemainderFunctor { inline HOSTDEVICE T operator()(const T a, const T b) const { T res = a % b; @@ -511,7 +511,7 @@ struct ModuloFunctor { }; template -struct ModuloFunctor< +struct RemainderFunctor< T, typename std::enable_if_t::value>> { inline HOSTDEVICE T operator()(const T a, const T b) const { @@ -525,7 +525,7 @@ struct ModuloFunctor< }; template -struct InverseModuloFunctor { +struct InverseRemainderFunctor { inline HOSTDEVICE T operator()(const T a, const T b) const { T res = b % a; if ((res != 0) && ((res < 0) != (a < 0))) res += a; @@ -534,7 +534,7 @@ struct InverseModuloFunctor { }; template -struct InverseModuloFunctor< +struct InverseRemainderFunctor< T, typename std::enable_if_t::value>> { inline HOSTDEVICE T operator()(const T a, const T b) const { diff --git a/paddle/phi/kernels/kps/elementwise_kernel.cu b/paddle/phi/kernels/kps/elementwise_kernel.cu index d387096a70b75e0cced379b2a1093a484dc5be88..9da65c590b4d98c3d8fae639e81436f1b8840c1b 100644 --- a/paddle/phi/kernels/kps/elementwise_kernel.cu +++ b/paddle/phi/kernels/kps/elementwise_kernel.cu @@ -42,8 +42,8 @@ void MinimumKernel(const Context& dev_ctx, int axis = -1; MinimumRawKernel(dev_ctx, x, y, axis, out); } -// Create the definition of Modulo -DEFINE_CUDA_ELEMENTWISE_OP(Modulo) +// Create the definition of Remainder +DEFINE_CUDA_ELEMENTWISE_OP(Remainder) // Create the definition of FloorDivide DEFINE_CUDA_ELEMENTWISE_OP(FloorDivide) template @@ -118,10 +118,10 @@ PD_REGISTER_KERNEL(minimum_raw, int64_t, float16, bfloat16) {} -PD_REGISTER_KERNEL(modulo_raw, +PD_REGISTER_KERNEL(remainder_raw, KPS, ALL_LAYOUT, - phi::ModuloRawKernel, + phi::RemainderRawKernel, float, double, int, diff --git a/paddle/phi/ops/compat/elementwise_sig.cc b/paddle/phi/ops/compat/elementwise_sig.cc index 17fb1858373d9581e62ed89cd3e05abe744362fe..1d82ceaf1dea3b354e21a83af3daa8ca8ada7e7f 100644 --- a/paddle/phi/ops/compat/elementwise_sig.cc +++ b/paddle/phi/ops/compat/elementwise_sig.cc @@ -86,9 +86,9 @@ KernelSignature ElementwiseModOpArgumentMapping( const ArgumentMappingContext& ctx) { int axis = paddle::any_cast(ctx.Attr("axis")); if (axis == -1) { - return KernelSignature("modulo", {"X", "Y"}, {}, {"Out"}); + return KernelSignature("remainder", {"X", "Y"}, {}, {"Out"}); } - return KernelSignature("modulo_raw", {"X", "Y"}, {"axis"}, {"Out"}); + return KernelSignature("remainder_raw", {"X", "Y"}, {"axis"}, {"Out"}); } KernelSignature ElementwiseFloorDivOpArgumentMapping( @@ -247,7 +247,7 @@ PD_REGISTER_BASE_KERNEL_NAME(elementwise_mul, multiply); PD_REGISTER_BASE_KERNEL_NAME(elementwise_div, divide); PD_REGISTER_BASE_KERNEL_NAME(elementwise_max, maximum); PD_REGISTER_BASE_KERNEL_NAME(elementwise_min, minimum); -PD_REGISTER_BASE_KERNEL_NAME(elementwise_mod, modulo); +PD_REGISTER_BASE_KERNEL_NAME(elementwise_mod, remainder); PD_REGISTER_BASE_KERNEL_NAME(elementwise_floordiv, floor_divide); PD_REGISTER_BASE_KERNEL_NAME(elementwise_add_grad, add_grad); PD_REGISTER_BASE_KERNEL_NAME(elementwise_add_grad_grad, add_double_grad); diff --git a/python/paddle/fluid/dygraph/math_op_patch.py b/python/paddle/fluid/dygraph/math_op_patch.py index b66d1ee302231d7c6b9f8e4a1c6b5fd008133c47..b12c43fa17bdeca4db2516d3ead356306357d54f 100644 --- a/python/paddle/fluid/dygraph/math_op_patch.py +++ b/python/paddle/fluid/dygraph/math_op_patch.py @@ -395,7 +395,7 @@ def monkey_patch_math_varbase(): if framework._in_eager_mode_ else ('__floordiv__', _binary_creator_('__floordiv__', 'elementwise_floordiv', False, None)), - ('__mod__', _binary_creator_('__mod__', 'modulo', False, None, True)) + ('__mod__', _binary_creator_('__mod__', 'remainder', False, None, True)) if framework._in_eager_mode_ else ('__mod__', _binary_creator_('__mod__', 'elementwise_mod', False, None)), diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 48e6924660a468e91ca0039503a43279f6b0c9fb..ebb50604b7311f492d24e0b3582053c0ffa02096 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -205,7 +205,7 @@ OP_NAMEMAPPING = { 'elementwise_sub': 'subtract', 'elementwise_mul': 'multiply', 'elementwise_div': 'divide', - 'elementwise_mod': 'modulo', + 'elementwise_mod': 'remainder', } diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index cd8bd888cc1fbdf3979cb729d614001114f86a41..0bad545025c1c2c0f3bda776eb670760d7f7837d 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -419,12 +419,11 @@ OP_NAMEMAPPING = { 'elementwise_min': 'minimum', 'elementwise_pow': 'elementwise_pow', 'elementwise_floordiv': 'floor_divide', - 'elementwise_mod': 'modulo', 'elementwise_add': 'add', 'elementwise_sub': 'subtract', 'elementwise_mul': 'multiply', 'elementwise_div': 'divide', - 'elementwise_mod': 'modulo', + 'elementwise_mod': 'remainder', } @dygraph_only