Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3792a49d
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
3792a49d
编写于
6月 03, 2020
作者:
L
LielinJiang
提交者:
GitHub
6月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bilinear_initializer bug when type of input data is float64 (#24771)
* fix bilinear initializer, test=develop
上级
9bbb9542
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
11 addition
and
4 deletion
+11
-4
python/paddle/fluid/initializer.py
python/paddle/fluid/initializer.py
+4
-3
python/paddle/fluid/tests/unittests/test_initializer.py
python/paddle/fluid/tests/unittests/test_initializer.py
+7
-1
未找到文件。
python/paddle/fluid/initializer.py
浏览文件 @
3792a49d
...
@@ -783,7 +783,7 @@ class BilinearInitializer(Initializer):
...
@@ -783,7 +783,7 @@ class BilinearInitializer(Initializer):
weight
=
np
.
reshape
(
weight
,
shape
)
weight
=
np
.
reshape
(
weight
,
shape
)
# to be compatible of fp16 initalizers
# to be compatible of fp16 initalizers
if
var
.
dtype
==
VarDesc
.
VarType
.
FP16
:
if
var
.
dtype
==
VarDesc
.
VarType
.
FP16
or
var
.
dtype
==
VarDesc
.
VarType
.
FP64
:
out_dtype
=
VarDesc
.
VarType
.
FP32
out_dtype
=
VarDesc
.
VarType
.
FP32
out_var
=
block
.
create_var
(
out_var
=
block
.
create_var
(
name
=
unique_name
.
generate
(
"."
.
join
(
name
=
unique_name
.
generate
(
"."
.
join
(
...
@@ -800,7 +800,8 @@ class BilinearInitializer(Initializer):
...
@@ -800,7 +800,8 @@ class BilinearInitializer(Initializer):
value_name
=
"fp32_values"
value_name
=
"fp32_values"
values
=
[
float
(
v
)
for
v
in
weight
.
flat
]
values
=
[
float
(
v
)
for
v
in
weight
.
flat
]
else
:
else
:
raise
ValueError
(
"Unsupported dtype %s"
,
input
.
dtype
)
raise
TypeError
(
"Unsupported dtype %s"
,
var
.
dtype
)
if
np
.
prod
(
shape
)
>
1024
*
1024
:
if
np
.
prod
(
shape
)
>
1024
*
1024
:
raise
ValueError
(
"The size of input is too big. "
)
raise
ValueError
(
"The size of input is too big. "
)
op
=
block
.
append_op
(
op
=
block
.
append_op
(
...
@@ -812,7 +813,7 @@ class BilinearInitializer(Initializer):
...
@@ -812,7 +813,7 @@ class BilinearInitializer(Initializer):
value_name
:
values
value_name
:
values
})
})
if
var
.
dtype
==
VarDesc
.
VarType
.
FP16
:
if
var
.
dtype
==
VarDesc
.
VarType
.
FP16
or
var
.
dtype
==
VarDesc
.
VarType
.
FP64
:
block
.
append_op
(
block
.
append_op
(
type
=
"cast"
,
type
=
"cast"
,
inputs
=
{
"X"
:
out_var
},
inputs
=
{
"X"
:
out_var
},
...
...
python/paddle/fluid/tests/unittests/test_initializer.py
浏览文件 @
3792a49d
...
@@ -474,18 +474,24 @@ class TestBilinearInitializer(unittest.TestCase):
...
@@ -474,18 +474,24 @@ class TestBilinearInitializer(unittest.TestCase):
lod_level
=
0
,
lod_level
=
0
,
name
=
"param"
,
name
=
"param"
,
initializer
=
initializer
.
BilinearInitializer
())
initializer
=
initializer
.
BilinearInitializer
())
num_ops
=
2
if
dtype
==
"float16"
else
1
num_ops
=
2
if
dtype
==
"float16"
or
dtype
==
"float64"
else
1
self
.
assertEqual
(
len
(
block
.
ops
),
num_ops
)
self
.
assertEqual
(
len
(
block
.
ops
),
num_ops
)
init_op
=
block
.
ops
[
0
]
init_op
=
block
.
ops
[
0
]
self
.
assertEqual
(
init_op
.
type
,
'assign_value'
)
self
.
assertEqual
(
init_op
.
type
,
'assign_value'
)
return
block
return
block
def
test_bilinear_initializer_fp64
(
self
):
self
.
test_bilinear_initializer
(
dtype
=
'float64'
)
def
test_bilinear_initializer_fp16
(
self
):
def
test_bilinear_initializer_fp16
(
self
):
"""Test the bilinear initializer with supplied arguments
"""Test the bilinear initializer with supplied arguments
"""
"""
block
=
self
.
test_bilinear_initializer
(
"float16"
)
block
=
self
.
test_bilinear_initializer
(
"float16"
)
self
.
assertTrue
(
check_cast_op
(
block
.
ops
[
1
]))
self
.
assertTrue
(
check_cast_op
(
block
.
ops
[
1
]))
def
test_type_error
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
test_bilinear_initializer
,
'int32'
)
class
TestNumpyArrayInitializer
(
unittest
.
TestCase
):
class
TestNumpyArrayInitializer
(
unittest
.
TestCase
):
def
test_numpy_array_initializer
(
self
,
dtype
=
"float32"
):
def
test_numpy_array_initializer
(
self
,
dtype
=
"float32"
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录