From c18aa8a30dd0eec6d8fc9204d0bc5fda8f5a33ef Mon Sep 17 00:00:00 2001 From: Jiabin Yang <360788950@qq.com> Date: Mon, 22 Aug 2022 14:24:06 +0800 Subject: [PATCH] [Eager] Optimize python api to speed up eager exec (#45262) * optimize python api to speed up eager exec * optimize python api to speed up eager exec * optimize python api to speed up eager exec --- python/paddle/fluid/dygraph/math_op_patch.py | 5 +++-- python/paddle/tensor/math.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/dygraph/math_op_patch.py b/python/paddle/fluid/dygraph/math_op_patch.py index 1a59d2f95fd..1f6ce480887 100644 --- a/python/paddle/fluid/dygraph/math_op_patch.py +++ b/python/paddle/fluid/dygraph/math_op_patch.py @@ -379,8 +379,9 @@ def monkey_patch_math_varbase(): ('__rtruediv__', _binary_creator_('rtruediv__', 'elementwise_div', True, None)), ('__pow__', - _binary_creator_('__pow__', 'final_state_elementwise_pow', False, None, - True)) if framework._in_eager_mode_ else + _binary_creator_('__pow__', 'final_state_elementwise_pow', False, + _C_ops.final_state_pow, True)) + if framework._in_eager_mode_ else ('__pow__', _binary_creator_('__pow__', 'elementwise_pow', False, None)), ('__rpow__', _binary_creator_('__rpow__', 'elementwise_pow', True, diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 6199cd8120f..0ea657d8c7c 100644 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -736,7 +736,9 @@ def floor_divide(x, y, name=None): """ op_type = 'elementwise_floordiv' axis = -1 - if paddle.in_dynamic_mode(): + if in_dygraph_mode(): + return _C_ops.final_state_floor_divide(x, y) + if _in_legacy_dygraph(): return _elementwise_op_in_dygraph( x, y, axis=axis, op_name=op_type) @@ -776,7 +778,9 @@ def remainder(x, y, name=None): """ op_type = 'elementwise_mod' axis = -1 - if paddle.in_dynamic_mode(): + if in_dygraph_mode(): + return _C_ops.final_state_modulo(x, y) + if _in_legacy_dygraph(): return _elementwise_op_in_dygraph( x, y, axis=axis, op_name=op_type) @@ -894,7 +898,9 @@ def maximum(x, y, name=None): op_type = 'elementwise_max' axis = -1 act = None - if paddle.in_dynamic_mode(): + if in_dygraph_mode(): + return _C_ops.final_state_maximum(x, y) + if _in_legacy_dygraph(): return _elementwise_op_in_dygraph( x, y, axis=axis, act=act, op_name=op_type) return _elementwise_op(LayerHelper(op_type, **locals())) @@ -953,7 +959,9 @@ def minimum(x, y, name=None): op_type = 'elementwise_min' axis = -1 act = None - if paddle.in_dynamic_mode(): + if in_dygraph_mode(): + return _C_ops.final_state_minimum(x, y) + if _in_legacy_dygraph(): return _elementwise_op_in_dygraph( x, y, axis=axis, act=act, op_name=op_type) return _elementwise_op(LayerHelper(op_type, **locals())) -- GitLab