Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
03026cea
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
03026cea
编写于
9月 13, 2021
作者:
C
chentianyu03
提交者:
GitHub
9月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "change '/' method from scale Op to elementwise_div Op (#33279)" (#35650)
This reverts commit
ae93d9c2
.
上级
7b743ba2
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
22 addition
and
23 deletion
+22
-23
python/paddle/fluid/dygraph/math_op_patch.py
python/paddle/fluid/dygraph/math_op_patch.py
+11
-5
python/paddle/fluid/layers/math_op_patch.py
python/paddle/fluid/layers/math_op_patch.py
+11
-5
python/paddle/fluid/tests/unittests/test_tensor_scalar_type_promotion_dynamic.py
...ts/unittests/test_tensor_scalar_type_promotion_dynamic.py
+0
-7
python/paddle/fluid/tests/unittests/test_tensor_scalar_type_promotion_static.py
...sts/unittests/test_tensor_scalar_type_promotion_static.py
+0
-6
未找到文件。
python/paddle/fluid/dygraph/math_op_patch.py
浏览文件 @
03026cea
...
...
@@ -46,7 +46,9 @@ _supported_promote_complex_types_ = [
'__rsub__'
,
'__mul__'
,
'__rmul__'
,
'__div__'
,
'__truediv__'
,
'__rdiv__'
,
'__rtruediv__'
,
'__matmul__'
,
]
...
...
@@ -170,6 +172,9 @@ def monkey_patch_math_varbase():
def
_scalar_mul_
(
var
,
value
):
return
_scalar_elementwise_op_
(
var
,
value
,
0.0
)
def
_scalar_div_
(
var
,
value
):
return
_scalar_elementwise_op_
(
var
,
1.0
/
value
,
0.0
)
# for binary operator such as elementwise, compare
def
_binary_creator_
(
method_name
,
op_type
,
...
...
@@ -200,10 +205,7 @@ def monkey_patch_math_varbase():
if
op_type
==
'elementwise_div'
and
self
.
dtype
in
_supported_int_dtype_
:
self
=
astype
(
self
,
'float32'
)
# here use `scale` replace `elementwise` to get better performance
# but only +, -, * can use this method
# NOTE(chentianyu03): / can not use `scale` method,because the result of
# `scale` method (self*(1/other_var)) do not exactly equal with the result
# of `elementwise_div` method.
# but only +, -, *, / can use this method
if
scalar_method
is
not
None
:
return
scalar_method
(
self
,
other_var
)
else
:
...
...
@@ -296,8 +298,12 @@ def monkey_patch_math_varbase():
## a*b == b*a. Do not need to reverse explicitly
(
'__rmul__'
,
_binary_creator_
(
'__rmul__'
,
'elementwise_mul'
,
False
,
_scalar_mul_
)),
(
'__div__'
,
_binary_creator_
(
'__div__'
,
'elementwise_div'
,
False
,
_scalar_div_
)),
(
'__truediv__'
,
_binary_creator_
(
'__truediv__'
,
'elementwise_div'
,
False
,
None
)),
False
,
_scalar_div_
)),
(
'__rdiv__'
,
_binary_creator_
(
'__rdiv__'
,
'elementwise_div'
,
True
,
None
)),
(
'__rtruediv__'
,
_binary_creator_
(
'rtruediv__'
,
'elementwise_div'
,
True
,
None
)),
(
'__pow__'
,
_binary_creator_
(
'__pow__'
,
'elementwise_pow'
,
False
,
...
...
python/paddle/fluid/layers/math_op_patch.py
浏览文件 @
03026cea
...
...
@@ -40,7 +40,9 @@ EXPRESSION_MAP = {
"__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"
,
...
...
@@ -249,6 +251,9 @@ def monkey_patch_variable():
def
_scalar_mul_
(
var
,
value
):
return
_scalar_op_
(
var
,
value
,
0.0
)
def
_scalar_div_
(
var
,
value
):
return
_scalar_op_
(
var
,
1.0
/
value
,
0.0
)
def
_binary_creator_
(
method_name
,
op_type
,
reverse
=
False
,
...
...
@@ -278,10 +283,7 @@ def monkey_patch_variable():
if
op_type
==
'elementwise_div'
and
self
.
dtype
in
_supported_int_dtype_
:
self
=
astype
(
self
,
'float32'
)
# here use `scale` replace `elementwise` to get better performance
# but only +, -, * can use this method
# NOTE(chentianyu03): / can not use `scale` method,because the result of
# `scale` method (self*(1/other_var)) do not exactly equal with the result
# of `elementwise_div` method.
# but only +, -, *, / can use this method
if
scalar_method
is
not
None
:
return
scalar_method
(
self
,
other_var
)
else
:
...
...
@@ -381,8 +383,12 @@ def monkey_patch_variable():
# a*b == b*a. Do not need to reverse explicitly
(
'__rmul__'
,
_binary_creator_
(
'__rmul__'
,
'elementwise_mul'
,
False
,
_scalar_mul_
)),
(
'__div__'
,
_binary_creator_
(
'__div__'
,
'elementwise_div'
,
False
,
_scalar_div_
)),
(
'__truediv__'
,
_binary_creator_
(
'__truediv__'
,
'elementwise_div'
,
False
,
None
)),
False
,
_scalar_div_
)),
(
'__rdiv__'
,
_binary_creator_
(
'__rdiv__'
,
'elementwise_div'
,
True
,
None
)),
(
'__rtruediv__'
,
_binary_creator_
(
'__rtruediv__'
,
'elementwise_div'
,
True
,
None
)),
(
'__pow__'
,
_binary_creator_
(
'__pow__'
,
'elementwise_pow'
,
False
,
...
...
python/paddle/fluid/tests/unittests/test_tensor_scalar_type_promotion_dynamic.py
浏览文件 @
03026cea
...
...
@@ -187,13 +187,6 @@ class TestTensorScalarTypePromotionDynamic(unittest.TestCase):
c
=
paddle
.
full
([
2
,
2
,
2
],
0.5
,
dtype
=
"float32"
)
self
.
check_operation
(
a
,
b
,
c
,
'/'
)
# tensor(float32) / scalar(int)
# this behavior should be equal to elementwise_div Op
a
=
paddle
.
to_tensor
([
99
,
99
,
99
],
dtype
=
'float32'
)
b
=
100
c
=
a
/
paddle
.
to_tensor
([
100
,
100
,
100
],
dtype
=
'float32'
)
self
.
check_operation
(
a
,
b
,
c
,
'/'
)
# tensor(int64) / scalar(float, .0)
a
=
paddle
.
ones
([
2
,
2
,
2
],
dtype
=
'int64'
)
b
=
2.0
...
...
python/paddle/fluid/tests/unittests/test_tensor_scalar_type_promotion_static.py
浏览文件 @
03026cea
...
...
@@ -218,12 +218,6 @@ class TestTensorScalarTypePromotionStatic(unittest.TestCase):
c
=
paddle
.
full
([
2
,
2
,
2
],
0.5
,
dtype
=
"float32"
)
self
.
check_operation
(
a
,
b
,
c
,
'/'
)
# this behavior should be equal to elementwise_div Op
a
=
paddle
.
full
([
2
,
2
,
2
],
99
,
dtype
=
"float32"
)
b
=
100
c
=
a
/
paddle
.
full
([
2
,
2
,
2
],
100
,
dtype
=
"float32"
)
self
.
check_operation
(
a
,
b
,
c
,
'/'
)
# tensor(int64) / scalar(float, .0)
with
program_guard
(
Program
()):
a
=
paddle
.
ones
([
2
,
2
,
2
],
dtype
=
'int64'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录