Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
urhero
Paddle
提交
fb34bdb4
P
Paddle
项目概览
urhero
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
fb34bdb4
编写于
4月 12, 2020
作者:
W
wangchaochaohu
提交者:
GitHub
4月 12, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
API/OP(fill_constant) error message enhancement (#23584)
上级
25ef38bc
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
30 addition
and
21 deletion
+30
-21
paddle/fluid/framework/parallel_executor.cc
paddle/fluid/framework/parallel_executor.cc
+0
-1
paddle/fluid/operators/fill_constant_op.cc
paddle/fluid/operators/fill_constant_op.cc
+1
-2
paddle/fluid/operators/fill_constant_op.h
paddle/fluid/operators/fill_constant_op.h
+8
-8
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+9
-8
python/paddle/fluid/tests/unittests/test_fill_constant_op.py
python/paddle/fluid/tests/unittests/test_fill_constant_op.py
+12
-2
未找到文件。
paddle/fluid/framework/parallel_executor.cc
浏览文件 @
fb34bdb4
...
...
@@ -789,7 +789,6 @@ void ParallelExecutor::BCastParamsToDevices(
FetchResultType
ParallelExecutor
::
Run
(
const
std
::
vector
<
std
::
string
>
&
fetch_tensors
,
bool
return_merged
)
{
VLOG
(
3
)
<<
"enter ParallelExecutor Run"
;
platform
::
RecordEvent
parallel_executor_event
(
"ParallelExecutor::Run"
);
#ifdef WITH_GPERFTOOLS
if
(
gProfileStarted
)
{
ProfilerFlush
();
...
...
paddle/fluid/operators/fill_constant_op.cc
浏览文件 @
fb34bdb4
...
...
@@ -22,8 +22,7 @@ class FillConstantOp : public framework::OperatorWithKernel {
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
"Output(Out) of FillConstantOp should not be null."
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"FillConstant"
);
auto
&
shape
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int64_t
>>
(
"shape"
);
...
...
paddle/fluid/operators/fill_constant_op.h
浏览文件 @
fb34bdb4
...
...
@@ -49,11 +49,11 @@ inline framework::DDim GetShape(const framework::ExecutionContext &ctx) {
auto
tensor
=
shape_tensor_list
[
i
];
PADDLE_ENFORCE_EQ
(
tensor
->
dims
(),
framework
::
make_ddim
({
1
}),
"ShapeError: If the element type of 'shape' in FillConstantOp is "
"Tensor,
"
"the element's shape must be [1]. But received the element's shape
"
"
is [%s]"
,
tensor
->
dims
(
));
platform
::
errors
::
InvalidArgument
(
"If the element type of 'shape'(tensor_list type) in
"
"FillConstantOp is Tensor, the shape of this Tensor element must
"
"be [1]. But received the Tensor element's shape
is [%s]"
,
tensor
->
dims
()
));
if
(
platform
::
is_gpu_place
(
tensor
->
place
()))
{
framework
::
Tensor
temp
;
TensorCopySync
(
*
tensor
,
platform
::
CPUPlace
(),
&
temp
);
...
...
@@ -124,9 +124,9 @@ class FillConstantKernel : public framework::OpKernel<T> {
tensor
=
out_var
->
GetMutable
<
framework
::
SelectedRows
>
()
->
mutable_value
();
tensor
->
Resize
(
shape
);
}
else
{
PADDLE_THROW
(
"
fill constant op's output only
"
"
supports SelectedRows and LoDTensor"
);
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"
In fill constant Op, the output only supports SelectedRows and
"
"
LoDTensor."
)
);
}
platform
::
DeviceContextPool
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
...
...
python/paddle/fluid/layers/tensor.py
浏览文件 @
fb34bdb4
...
...
@@ -628,11 +628,18 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
out
.
stop_gradient
=
True
return
out
helper
=
LayerHelper
(
"fill_constant"
,
**
locals
())
check_dtype
(
dtype
,
'create data type'
,
check_dtype
(
dtype
,
'dtype'
,
[
'bool'
,
'float16'
,
'float32'
,
'float64'
,
'int32'
,
'int64'
],
'fill_constant'
)
check_type
(
shape
,
'shape'
,
(
Variable
,
list
,
tuple
),
'fill_constant'
)
if
isinstance
(
shape
,
Variable
):
check_variable_and_dtype
(
shape
,
'shape'
,
[
'int32'
,
'int64'
],
'fill_constant'
)
if
out
is
not
None
:
check_variable_and_dtype
(
out
,
'out'
,
[
convert_dtype
(
dtype
)],
'fill_constant'
)
helper
=
LayerHelper
(
"fill_constant"
,
**
locals
())
inputs
=
utils
.
_get_shape_tensor_inputs
(
inputs
=
inputs
,
helper
=
helper
,
...
...
@@ -642,12 +649,6 @@ def fill_constant(shape, dtype, value, force_cpu=False, out=None):
if
out
is
None
:
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
dtype
)
else
:
check_dtype
(
dtype
,
'create data type'
,
convert_dtype
(
out
.
dtype
),
'fill_constant'
,
'(The create data type in fill_constant must be the same with out data type.)'
)
attrs
[
'dtype'
]
=
out
.
dtype
helper
.
append_op
(
type
=
'fill_constant'
,
...
...
python/paddle/fluid/tests/unittests/test_fill_constant_op.py
浏览文件 @
fb34bdb4
...
...
@@ -23,6 +23,7 @@ import paddle.fluid.core as core
from
paddle.fluid.op
import
Operator
import
paddle.fluid
as
fluid
from
paddle.fluid
import
compiler
,
Program
,
program_guard
import
numpy
as
np
# Situation 1: Attr(shape) is a list(without tensor)
...
...
@@ -263,12 +264,12 @@ class TestFillConstantOp2_ValueTensor(OpTest):
# Test python API
class
TestFillConstantAPI
(
unittest
.
TestCase
):
def
test_api
(
self
):
positive_2_int32
=
fluid
.
layers
.
fill_constant
([
1
],
"int32"
,
2
)
positive_2_int32
=
fluid
.
layers
.
fill_constant
([
1
],
"int32"
,
2
)
positive_2_int64
=
fluid
.
layers
.
fill_constant
([
1
],
"int64"
,
2
)
shape_tensor_int32
=
fluid
.
data
(
name
=
"shape_tensor_int32"
,
shape
=
[
2
],
dtype
=
"int32"
)
shape_tensor_int64
=
fluid
.
data
(
name
=
"shape_tensor_int64"
,
shape
=
[
2
],
dtype
=
"int64"
)
...
...
@@ -349,6 +350,15 @@ class TestFillConstantOpError(unittest.TestCase):
dtype
=
'float64'
,
out
=
x2
)
x3
=
np
.
random
.
randn
(
100
,
100
).
astype
(
'int32'
)
self
.
assertRaises
(
TypeError
,
fluid
.
layers
.
fill_constant
,
shape
=
[
100
,
100
],
value
=
5
,
dtype
=
'float64'
,
out
=
x3
)
# The argument shape's type of fill_constant_op must be list, tuple or Variable.
def
test_shape_type
():
fluid
.
layers
.
fill_constant
(
shape
=
1
,
dtype
=
"float32"
,
value
=
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录