未验证 提交 d0ef9479 编写于 作者: W wawltor 提交者: GitHub

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
上级 05d20e57
...@@ -14,6 +14,9 @@ ...@@ -14,6 +14,9 @@
from __future__ import print_function from __future__ import print_function
import logging
import inspect
from .. import core from .. import core
from ..framework import Variable, unique_name from ..framework import Variable, unique_name
from .layer_function_generator import OpProtoHolder from .layer_function_generator import OpProtoHolder
...@@ -28,6 +31,29 @@ _supported_int_dtype_ = [ ...@@ -28,6 +31,29 @@ _supported_int_dtype_ = [
compare_ops = ['__eq__', '__ne__', '__lt__', '__le__', '__gt__', '__ge__'] 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 monkey_patch_variable():
def unique_tmp_name(): def unique_tmp_name():
...@@ -233,7 +259,15 @@ def monkey_patch_variable(): ...@@ -233,7 +259,15 @@ def monkey_patch_variable():
axis = -1 axis = -1
if other_var.shape[0] == -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( current_block(self).append_op(
type=op_type, type=op_type,
inputs={'X': [self], inputs={'X': [self],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册