Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f1c5815e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f1c5815e
编写于
4月 01, 2022
作者:
P
pangyoki
提交者:
GitHub
4月 01, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bug of inplace fill_ and zero_ API (#41229)
* fix inplace fill_ and zero_ API * add eager unittest
上级
93cb2350
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
33 addition
and
29 deletion
+33
-29
paddle/fluid/eager/auto_code_generator/eager_generator.cc
paddle/fluid/eager/auto_code_generator/eager_generator.cc
+1
-1
paddle/fluid/eager/utils.cc
paddle/fluid/eager/utils.cc
+0
-21
paddle/fluid/eager/utils.h
paddle/fluid/eager/utils.h
+0
-3
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+6
-0
python/paddle/fluid/tests/unittests/test_tensor_fill_.py
python/paddle/fluid/tests/unittests/test_tensor_fill_.py
+19
-3
python/paddle/fluid/tests/unittests/test_tensor_zero_.py
python/paddle/fluid/tests/unittests/test_tensor_zero_.py
+7
-1
未找到文件。
paddle/fluid/eager/auto_code_generator/eager_generator.cc
浏览文件 @
f1c5815e
...
...
@@ -1824,7 +1824,7 @@ static std::pair<std::string, std::string> GenerateForwardFunctionContents(
// Bump inplace version of inplace tensor.
auto
inplace_input_name
=
inplace_map
[
output_name
];
const
char
*
FWD_OUT_TENSOR_TEMPLATE
=
" egr::EagerUtils::
ModifyInplaceIn
put(outs[
\"
%s
\"
][0], &%s);
\n
"
" egr::EagerUtils::
GetOut
put(outs[
\"
%s
\"
][0], &%s);
\n
"
" %s.bump_inplace_version();
\n
"
" VLOG(3) <<
\"
Tensor(
\"
<< %s.name() <<
\"
) uses Inplace "
"Strategy.
\"
;
\n
"
;
...
...
paddle/fluid/eager/utils.cc
浏览文件 @
f1c5815e
...
...
@@ -271,27 +271,6 @@ void EagerUtils::HandleViewBetweenInputAndOutput(
}
}
void
EagerUtils
::
ModifyInplaceInput
(
const
std
::
shared_ptr
<
EagerVariable
>&
inplace_variable
,
paddle
::
experimental
::
Tensor
*
inplace_tensor
)
{
// Only modify the meta information of the inplace tensor, because
// EagerVariable cannot modify Tensor's meta information after inplace
// op (such as ``reshape``) is executed.
PADDLE_ENFORCE_NOT_NULL
(
inplace_tensor
,
paddle
::
platform
::
errors
::
Fatal
(
"Inplace Tensor is null and cannot be modified. "
"We are tring to Modify Inplace Input from its "
"shared_ptr, this error may indicate the inplace "
" input is nullptr"
));
if
(
phi
::
DenseTensor
::
classof
(
inplace_variable
->
GetTensorBase
().
get
()))
{
phi
::
DenseTensor
*
variable_dense_tensor
=
static_cast
<
phi
::
DenseTensor
*>
(
inplace_variable
->
GetTensorBase
().
get
());
phi
::
DenseTensor
*
tensor_dense_tensor
=
static_cast
<
phi
::
DenseTensor
*>
(
inplace_tensor
->
impl
().
get
());
tensor_dense_tensor
->
set_meta
(
variable_dense_tensor
->
meta
());
}
}
std
::
vector
<
paddle
::
experimental
::
Tensor
>
EagerUtils
::
GetOutputs
(
const
std
::
vector
<
std
::
shared_ptr
<
EagerVariable
>>&
outs
)
{
std
::
vector
<
paddle
::
experimental
::
Tensor
>
res
;
...
...
paddle/fluid/eager/utils.h
浏览文件 @
f1c5815e
...
...
@@ -203,9 +203,6 @@ class EagerUtils {
static
std
::
vector
<
std
::
shared_ptr
<
EagerVariable
>>
CreateVars
(
const
size_t
num
);
// Construct Tensor From var
static
void
ModifyInplaceInput
(
const
std
::
shared_ptr
<
EagerVariable
>&
inplace_variable
,
paddle
::
experimental
::
Tensor
*
inplace_tensor
);
static
std
::
vector
<
paddle
::
experimental
::
Tensor
>
GetOutputs
(
const
std
::
vector
<
std
::
shared_ptr
<
EagerVariable
>>&
outs
);
static
paddle
::
experimental
::
Tensor
GetOutput
(
...
...
python/paddle/fluid/framework.py
浏览文件 @
f1c5815e
...
...
@@ -171,6 +171,12 @@ def _test_eager_guard(place=None):
if
not
_already_patch_eager_tensor
:
monkey_patch_varbase
()
monkey_patch_math_varbase
()
# Ugly setting
from
paddle.tensor.manipulation
import
fill_
,
zero_
setattr
(
core
.
eager
.
Tensor
,
'fill_'
,
fill_
)
setattr
(
core
.
eager
.
Tensor
,
'zero_'
,
zero_
)
_already_patch_eager_tensor
=
True
try
:
yield
...
...
python/paddle/fluid/tests/unittests/test_tensor_fill_.py
浏览文件 @
f1c5815e
...
...
@@ -17,13 +17,14 @@ import unittest
import
numpy
as
np
import
six
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
class
TensorFill_Test
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
shape
=
[
32
,
32
]
def
test_tensor_fill_true
(
self
):
def
func_
test_tensor_fill_true
(
self
):
typelist
=
[
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'float16'
]
places
=
[
fluid
.
CPUPlace
()]
if
fluid
.
core
.
is_compiled_with_cuda
():
...
...
@@ -46,7 +47,12 @@ class TensorFill_Test(unittest.TestCase):
tensor
.
fill_
(
var
)
#var type is basic type in typelist
self
.
assertEqual
((
tensor
.
numpy
()
==
target
).
all
(),
True
)
def
test_tensor_fill_backward
(
self
):
def
test_tensor_fill_true
(
self
):
with
_test_eager_guard
():
self
.
func_test_tensor_fill_true
()
self
.
func_test_tensor_fill_true
()
def
func_test_tensor_fill_backward
(
self
):
typelist
=
[
'float32'
]
places
=
[
fluid
.
CPUPlace
()]
if
fluid
.
core
.
is_compiled_with_cuda
():
...
...
@@ -71,13 +77,23 @@ class TensorFill_Test(unittest.TestCase):
self
.
assertEqual
((
y
.
grad
.
numpy
()
==
0
).
all
().
item
(),
True
)
def
test_errors
(
self
):
def
test_tensor_fill_backward
(
self
):
with
_test_eager_guard
():
self
.
func_test_tensor_fill_backward
()
self
.
func_test_tensor_fill_backward
()
def
func_test_errors
(
self
):
def
test_list
():
x
=
paddle
.
to_tensor
([
2
,
3
,
4
])
x
.
fill_
([
1
])
self
.
assertRaises
(
TypeError
,
test_list
)
def
test_errors
(
self
):
with
_test_eager_guard
():
self
.
func_test_errors
()
self
.
func_test_errors
()
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/fluid/tests/unittests/test_tensor_zero_.py
浏览文件 @
f1c5815e
...
...
@@ -17,13 +17,14 @@ import unittest
import
numpy
as
np
import
six
import
paddle
from
paddle.fluid.framework
import
_test_eager_guard
class
TensorFill_Test
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
shape
=
[
32
,
32
]
def
test_tensor_fill_true
(
self
):
def
func_
test_tensor_fill_true
(
self
):
typelist
=
[
'float32'
,
'float64'
,
'int32'
,
'int64'
,
'float16'
]
places
=
[
fluid
.
CPUPlace
()]
if
fluid
.
core
.
is_compiled_with_cuda
():
...
...
@@ -41,6 +42,11 @@ class TensorFill_Test(unittest.TestCase):
tensor
.
zero_
()
self
.
assertEqual
((
tensor
.
numpy
()
==
target
).
all
().
item
(),
True
)
def
test_tensor_fill_true
(
self
):
with
_test_eager_guard
():
self
.
func_test_tensor_fill_true
()
self
.
func_test_tensor_fill_true
()
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录