Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0fff9306
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看板
未验证
提交
0fff9306
编写于
3月 04, 2021
作者:
L
liym27
提交者:
GitHub
3月 04, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug for set_value op when input dtype is not float32 (#31411)
上级
c40b98e0
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
24 addition
and
7 deletion
+24
-7
paddle/fluid/operators/set_value_op.cc
paddle/fluid/operators/set_value_op.cc
+1
-2
paddle/fluid/operators/set_value_op.h
paddle/fluid/operators/set_value_op.h
+1
-2
python/paddle/fluid/tests/unittests/test_var_base.py
python/paddle/fluid/tests/unittests/test_var_base.py
+22
-3
未找到文件。
paddle/fluid/operators/set_value_op.cc
浏览文件 @
0fff9306
...
@@ -57,8 +57,7 @@ class SetValue : public framework::OperatorWithKernel {
...
@@ -57,8 +57,7 @@ class SetValue : public framework::OperatorWithKernel {
framework
::
OpKernelType
GetExpectedKernelType
(
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
OpKernelType
(
return
framework
::
OpKernelType
(
framework
::
proto
::
VarType
::
Type
(
ctx
.
Attr
<
int
>
(
"dtype"
)),
OperatorWithKernel
::
IndicateVarDataType
(
ctx
,
"Input"
),
ctx
.
GetPlace
());
ctx
.
GetPlace
());
}
}
framework
::
OpKernelType
GetKernelTypeForVar
(
framework
::
OpKernelType
GetKernelTypeForVar
(
...
...
paddle/fluid/operators/set_value_op.h
浏览文件 @
0fff9306
...
@@ -174,14 +174,13 @@ class SetValueKernel : public framework::OpKernel<T> {
...
@@ -174,14 +174,13 @@ class SetValueKernel : public framework::OpKernel<T> {
auto
steps_tensor_list
=
auto
steps_tensor_list
=
ctx
.
MultiInput
<
framework
::
Tensor
>
(
"StepsTensorList"
);
ctx
.
MultiInput
<
framework
::
Tensor
>
(
"StepsTensorList"
);
auto
dtype
=
static_cast
<
framework
::
proto
::
VarType
::
Type
>
(
ctx
.
Attr
<
int
>
(
"dtype"
));
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"axes"
);
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"axes"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"starts"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"starts"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"ends"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"ends"
);
auto
steps
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"steps"
);
auto
steps
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"steps"
);
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"shape"
);
auto
shape
=
ctx
.
Attr
<
std
::
vector
<
int64_t
>>
(
"shape"
);
auto
dtype
=
in
->
type
();
if
(
!
starts_tensor_list
.
empty
())
{
if
(
!
starts_tensor_list
.
empty
())
{
starts
=
GetDataFromTensorList
<
int64_t
>
(
starts_tensor_list
);
starts
=
GetDataFromTensorList
<
int64_t
>
(
starts_tensor_list
);
}
}
...
...
python/paddle/fluid/tests/unittests/test_var_base.py
浏览文件 @
0fff9306
...
@@ -631,10 +631,14 @@ class TestVarBase(unittest.TestCase):
...
@@ -631,10 +631,14 @@ class TestVarBase(unittest.TestCase):
class
TestVarBaseSetitem
(
unittest
.
TestCase
):
class
TestVarBaseSetitem
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
self
.
tensor_x
=
paddle
.
to_tensor
(
np
.
ones
((
4
,
2
,
3
)).
astype
(
np
.
float32
))
self
.
set_dtype
()
self
.
np_value
=
np
.
random
.
random
((
2
,
3
)).
astype
(
np
.
float32
)
self
.
tensor_x
=
paddle
.
to_tensor
(
np
.
ones
((
4
,
2
,
3
)).
astype
(
self
.
dtype
))
self
.
np_value
=
np
.
random
.
random
((
2
,
3
)).
astype
(
self
.
dtype
)
self
.
tensor_value
=
paddle
.
to_tensor
(
self
.
np_value
)
self
.
tensor_value
=
paddle
.
to_tensor
(
self
.
np_value
)
def
set_dtype
(
self
):
self
.
dtype
=
"int32"
def
_test
(
self
,
value
):
def
_test
(
self
,
value
):
paddle
.
disable_static
()
paddle
.
disable_static
()
self
.
assertEqual
(
self
.
tensor_x
.
inplace_version
,
0
)
self
.
assertEqual
(
self
.
tensor_x
.
inplace_version
,
0
)
...
@@ -644,7 +648,7 @@ class TestVarBaseSetitem(unittest.TestCase):
...
@@ -644,7 +648,7 @@ class TestVarBaseSetitem(unittest.TestCase):
self
.
assertEqual
(
self
.
tensor_x
.
inplace_version
,
1
)
self
.
assertEqual
(
self
.
tensor_x
.
inplace_version
,
1
)
if
isinstance
(
value
,
(
six
.
integer_types
,
float
)):
if
isinstance
(
value
,
(
six
.
integer_types
,
float
)):
result
=
np
.
zeros
((
2
,
3
)).
astype
(
np
.
float32
)
+
value
result
=
np
.
zeros
((
2
,
3
)).
astype
(
self
.
dtype
)
+
value
else
:
else
:
result
=
self
.
np_value
result
=
self
.
np_value
...
@@ -674,11 +678,26 @@ class TestVarBaseSetitem(unittest.TestCase):
...
@@ -674,11 +678,26 @@ class TestVarBaseSetitem(unittest.TestCase):
paddle
.
disable_static
()
paddle
.
disable_static
()
self
.
_test
(
10
)
self
.
_test
(
10
)
class
TestVarBaseSetitemInt64
(
TestVarBaseSetitem
):
def
set_dtype
(
self
):
self
.
dtype
=
"int64"
class
TestVarBaseSetitemFp32
(
TestVarBaseSetitem
):
def
set_dtype
(
self
):
self
.
dtype
=
"float32"
def
test_value_float
(
self
):
def
test_value_float
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
self
.
_test
(
3.3
)
self
.
_test
(
3.3
)
class
TestVarBaseSetitemFp64
(
TestVarBaseSetitem
):
def
set_dtype
(
self
):
self
.
dtype
=
"float64"
class
TestVarBaseInplaceVersion
(
unittest
.
TestCase
):
class
TestVarBaseInplaceVersion
(
unittest
.
TestCase
):
def
test_setitem
(
self
):
def
test_setitem
(
self
):
paddle
.
disable_static
()
paddle
.
disable_static
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录