From d0ef94798d541778cc655de59d816f405e4f233c Mon Sep 17 00:00:00 2001 From: wawltor Date: Wed, 13 May 2020 14:38:33 +0800 Subject: [PATCH] Fix the elementwise_ops axis bug, add the warning log for paddle 2.0 Fix the elementwise_ops axis bug, make elementwise_ops has the same the op function for override ops --- python/paddle/fluid/layers/math_op_patch.py | 36 ++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/layers/math_op_patch.py b/python/paddle/fluid/layers/math_op_patch.py index d86b3bbf491..12bd0d95190 100644 --- a/python/paddle/fluid/layers/math_op_patch.py +++ b/python/paddle/fluid/layers/math_op_patch.py @@ -14,6 +14,9 @@ from __future__ import print_function +import logging +import inspect + from .. import core from ..framework import Variable, unique_name from .layer_function_generator import OpProtoHolder @@ -28,6 +31,29 @@ _supported_int_dtype_ = [ compare_ops = ['__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__'] +EXPRESSION_MAP = { + "__add__": "A + B", + "__radd__": "A += B", + "__sub__": "A - B", + "__rsub__": "A -= B", + "__mul__": "A * B", + "__rmul__": "A *= B", + "__div__": "A / B", + "__truediv__": "A / B", + "__rdiv__": "A /= B", + "__rtruediv__": "A /= B", + "__pow__": "A ** B", + "__rpow__": "A **= B", + "__floordiv__": "A //B", + "__mod__": "A % B", + "__eq__": "A == B", + "__ne__": "A != B", + "__lt__": "A < B", + "__le__": "A <= B", + "__gt__": "A > B", + "__ge__": "A >= B" +} + def monkey_patch_variable(): def unique_tmp_name(): @@ -233,7 +259,15 @@ def monkey_patch_variable(): axis = -1 if other_var.shape[0] == -1: - axis = 0 + stack = inspect.stack()[1] + file_name = stack[1] + line_num = stack[2] + logging.warning( + "%s:%s\nThe behavior of expression %s has been unified with %s(X, Y, axis=-1) from Paddle 2.0. " + "If your code works well in the older versions but crashes in this version, try to use " + "%s(X, Y, axis=0) instead of %s. This transitional warning will be dropped in the future." + % (file_name, line_num, EXPRESSION_MAP[method_name], + op_type, op_type, EXPRESSION_MAP[method_name])) current_block(self).append_op( type=op_type, inputs={'X': [self], -- GitLab