Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
8a07d02c
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
8a07d02c
编写于
7月 27, 2022
作者:
A
Allen Guo
提交者:
GitHub
7月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix UTs on physical ipu (#44647)
上级
be132719
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
102 addition
and
85 deletion
+102
-85
python/paddle/fluid/tests/unittests/ipu/op_test_ipu.py
python/paddle/fluid/tests/unittests/ipu/op_test_ipu.py
+1
-1
python/paddle/fluid/tests/unittests/ipu/test_cast_op_ipu.py
python/paddle/fluid/tests/unittests/ipu/test_cast_op_ipu.py
+12
-7
python/paddle/fluid/tests/unittests/ipu/test_groupnorm_op_ipu.py
...paddle/fluid/tests/unittests/ipu/test_groupnorm_op_ipu.py
+2
-2
python/paddle/fluid/tests/unittests/ipu/test_interpolate_ops_ipu.py
...dle/fluid/tests/unittests/ipu/test_interpolate_ops_ipu.py
+1
-1
python/paddle/fluid/tests/unittests/ipu/test_meshgrid_op_ipu.py
.../paddle/fluid/tests/unittests/ipu/test_meshgrid_op_ipu.py
+2
-2
python/paddle/fluid/tests/unittests/ipu/test_mixed_precision_training_ipu.py
.../tests/unittests/ipu/test_mixed_precision_training_ipu.py
+8
-7
python/paddle/fluid/tests/unittests/ipu/test_save_load_ipu.py
...on/paddle/fluid/tests/unittests/ipu/test_save_load_ipu.py
+65
-64
python/paddle/fluid/tests/unittests/ipu/test_scaled_optimizer_state_ipu.py
...id/tests/unittests/ipu/test_scaled_optimizer_state_ipu.py
+4
-0
python/paddle/fluid/tests/unittests/ipu/test_weight_decay_ipu.py
...paddle/fluid/tests/unittests/ipu/test_weight_decay_ipu.py
+1
-1
python/paddle/fluid/tests/unittests/ipu/test_yolo_box_op_ipu.py
.../paddle/fluid/tests/unittests/ipu/test_yolo_box_op_ipu.py
+6
-0
未找到文件。
python/paddle/fluid/tests/unittests/ipu/op_test_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -179,7 +179,7 @@ class IPUOpTest(IPUTest):
@
classmethod
def
cast_model_to_fp16
(
cls
,
main_program
):
amp_list
=
paddle
.
static
.
amp
.
CustomOpLists
()
amp_list
.
unsupported_list
=
{}
amp_list
.
unsupported_list
=
{
'scale'
}
to_fp16_var_names
=
paddle
.
static
.
amp
.
cast_model_to_fp16
(
main_program
,
amp_list
,
use_fp16_guard
=
False
)
paddle
.
static
.
amp
.
cast_parameters_to_fp16
(
...
...
python/paddle/fluid/tests/unittests/ipu/test_cast_op_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -35,7 +35,7 @@ class TestBase(IPUOpTest):
def
set_data_feed
(
self
):
data
=
np
.
random
.
uniform
(
size
=
[
1
,
3
,
3
,
3
])
self
.
feed_fp32
=
{
'x'
:
data
.
astype
(
np
.
float
32
)}
self
.
feed_fp32
=
{
'x'
:
data
.
astype
(
np
.
float
16
)}
def
set_feed_attr
(
self
):
self
.
feed_shape
=
[
x
.
shape
for
x
in
self
.
feed_fp32
.
values
()]
...
...
@@ -44,7 +44,7 @@ class TestBase(IPUOpTest):
def
set_op_attrs
(
self
):
self
.
attrs
=
{}
self
.
attrs
[
'dtype'
]
=
'float
16
'
self
.
attrs
[
'dtype'
]
=
'float
32
'
@
IPUOpTest
.
static_graph
def
build_model
(
self
):
...
...
@@ -86,14 +86,19 @@ class TestEnableFp16(TestBase):
class
TestCase2
(
TestBase
):
def
set_atol
(
self
):
super
().
set_atol
()
self
.
atol
=
1e-3
self
.
rtol
=
1e-3
def
set_data_feed
(
self
):
self
.
feed_fp32
=
{
"x"
:
np
.
random
.
uniform
(
size
=
[
1
,
3
,
3
,
3
]).
astype
(
'float
16
'
),
"x"
:
np
.
random
.
uniform
(
size
=
[
1
,
3
,
3
,
3
]).
astype
(
'float
32
'
),
}
def
set_op_attrs
(
self
):
self
.
attrs
=
{}
self
.
attrs
[
'dtype'
]
=
'float
32
'
self
.
attrs
[
'dtype'
]
=
'float
16
'
class
TestCase3
(
TestBase
):
...
...
@@ -145,7 +150,7 @@ class TestCase6(TestBase):
@
unittest
.
skip
(
'float64 is not supported'
)
class
TestCase
2
(
TestBase
):
class
TestCase
7
(
TestBase
):
def
set_op_attrs
(
self
):
self
.
attrs
=
{}
...
...
@@ -153,7 +158,7 @@ class TestCase2(TestBase):
@
unittest
.
skip
(
'skip float16 to float32'
)
class
TestCase
3
(
TestBase
):
class
TestCase
8
(
TestBase
):
def
set_data_feed
(
self
):
self
.
feed_fp32
=
{
...
...
@@ -166,7 +171,7 @@ class TestCase3(TestBase):
@
unittest
.
skip
(
'int32 to int8 is not supported'
)
class
TestCase
4
(
TestBase
):
class
TestCase
9
(
TestBase
):
def
set_atol
(
self
):
super
().
set_atol
()
...
...
python/paddle/fluid/tests/unittests/ipu/test_groupnorm_op_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -113,8 +113,8 @@ class TestTrainCase2(TestBase):
def
set_atol
(
self
):
self
.
atol
=
7e-4
self
.
rtol
=
1e-6
self
.
atol_fp16
=
4e-3
self
.
rtol_fp16
=
1e-
3
self
.
atol_fp16
=
1e-2
self
.
rtol_fp16
=
1e-
2
def
set_op_attrs
(
self
):
self
.
attrs
=
{
...
...
python/paddle/fluid/tests/unittests/ipu/test_interpolate_ops_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -30,7 +30,7 @@ class TestBase(IPUOpTest):
self
.
set_op_attrs
()
def
set_data_feed
(
self
):
x
=
np
.
random
.
uniform
(
size
=
[
2
,
3
,
6
,
10
])
x
=
np
.
random
.
uniform
(
size
=
[
1
,
2
,
6
,
10
])
self
.
feed_fp32
=
{
"x"
:
x
.
astype
(
np
.
float32
)}
self
.
feed_fp16
=
{
"x"
:
x
.
astype
(
np
.
float16
)}
...
...
python/paddle/fluid/tests/unittests/ipu/test_meshgrid_op_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -36,8 +36,8 @@ class TestBase(IPUOpTest):
self
.
rtol_fp16
=
1e-3
def
set_feed
(
self
):
data1
=
np
.
random
.
uniform
(
size
=
[
10
0
])
data2
=
np
.
random
.
uniform
(
size
=
[
20
0
])
data1
=
np
.
random
.
uniform
(
size
=
[
10
])
data2
=
np
.
random
.
uniform
(
size
=
[
20
])
self
.
feed_fp32
=
{
'x'
:
data1
.
astype
(
np
.
float32
),
'y'
:
data2
.
astype
(
np
.
float32
)
...
...
python/paddle/fluid/tests/unittests/ipu/test_mixed_precision_training_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -31,17 +31,18 @@ class TestBase(IPUOpTest):
self
.
set_attrs
()
def
set_atol
(
self
):
self
.
atol
=
2e-6
self
.
rtol
=
1e-5
super
().
set_atol
()
self
.
atol
=
1e-6
self
.
rtol
=
1e-3
self
.
atol_fp16
=
1e-2
self
.
rtol_fp16
=
1e-
3
self
.
rtol_fp16
=
1e-
1
def
set_training
(
self
):
self
.
is_training
=
True
self
.
epoch
=
20
def
set_data_feed
(
self
):
data
=
np
.
random
.
uniform
(
size
=
[
1
,
3
,
28
,
28
])
data
=
np
.
random
.
uniform
(
size
=
[
1
,
3
,
10
,
10
])
self
.
feed_fp32
=
{
"in_0"
:
data
.
astype
(
np
.
float32
)}
def
set_feed_attr
(
self
):
...
...
@@ -73,7 +74,7 @@ class TestBase(IPUOpTest):
# using fp16
with
paddle
.
static
.
amp
.
fp16_guard
():
x
=
paddle
.
static
.
nn
.
conv2d
(
input
=
x
,
num_filters
=
6
,
filter_size
=
3
)
x
=
paddle
.
static
.
nn
.
conv2d
(
input
=
x
,
num_filters
=
3
,
filter_size
=
3
)
x
=
paddle
.
static
.
nn
.
batch_norm
(
x
,
act
=
'relu'
)
x
=
F
.
max_pool2d
(
x
,
kernel_size
=
2
,
stride
=
2
)
...
...
@@ -82,9 +83,9 @@ class TestBase(IPUOpTest):
loss
=
paddle
.
mean
(
x
)
# optimizer
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
1e-
2
)
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
1e-
3
)
optimizer
.
minimize
(
loss
,
self
.
startup_prog
)
self
.
fetch_list
=
[
loss
.
name
]
self
.
fetch_list
=
[
x
.
name
]
def
run_model
(
self
,
exec_mode
):
# cast model to fp16
...
...
python/paddle/fluid/tests/unittests/ipu/test_save_load_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -45,78 +45,73 @@ class TestBase(IPUOpTest):
self
.
attrs
=
{}
self
.
attrs
[
'steps'
]
=
100
self
.
attrs
[
'save_at_step'
]
=
20
self
.
attrs
[
'enable_fp16'
]
=
False
self
.
attrs
[
'model_path'
]
=
tempfile
.
TemporaryDirectory
()
def
set_optimizer
(
self
):
self
.
optimizer
=
partial
(
paddle
.
optimizer
.
SGD
,
learning_rate
=
1e-1
)
def
_test_base
(
self
,
save_otherwise_load
):
scope
=
paddle
.
static
.
Scope
()
main_prog
=
paddle
.
static
.
Program
()
startup_prog
=
paddle
.
static
.
Program
()
main_prog
.
random_seed
=
self
.
SEED
startup_prog
.
random_seed
=
self
.
SEED
@
IPUOpTest
.
static_graph
def
build_model
(
self
):
generator
=
paddle
.
fluid
.
unique_name
.
UniqueNameGenerator
()
with
paddle
.
fluid
.
unique_name
.
guard
(
generator
):
with
paddle
.
static
.
scope_guard
(
scope
):
with
paddle
.
static
.
program_guard
(
main_prog
,
startup_prog
):
x
=
paddle
.
static
.
data
(
name
=
self
.
feed_list
[
0
],
shape
=
self
.
feed_shape
[
0
],
dtype
=
'float32'
)
conv1
=
paddle
.
static
.
nn
.
conv2d
(
x
,
num_filters
=
3
,
filter_size
=
3
,
bias_attr
=
False
,
name
=
'conv2d'
)
loss
=
paddle
.
mean
(
conv1
)
# apply optimizer
self
.
optimizer
().
minimize
(
loss
)
fetch_list
=
[
loss
.
name
]
place
=
paddle
.
IPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
startup_prog
)
if
not
save_otherwise_load
:
paddle
.
static
.
load
(
main_prog
,
self
.
attrs
[
'model_path'
].
name
)
ipu_strategy
=
paddle
.
static
.
IpuStrategy
()
ipu_strategy
.
set_graph_config
(
is_training
=
True
)
ipu_strategy
.
set_precision_config
(
enable_fp16
=
self
.
attrs
[
'enable_fp16'
])
ipu_program
=
paddle
.
static
.
IpuCompiledProgram
(
main_prog
,
ipu_strategy
=
ipu_strategy
)
program
=
ipu_program
.
compile
(
self
.
feed_list
,
fetch_list
)
result
=
[]
run_steps
=
self
.
attrs
[
'steps'
]
if
save_otherwise_load
\
else
self
.
attrs
[
'steps'
]
-
self
.
attrs
[
'save_at_step'
]
feed
=
self
.
feed_fp16
if
self
.
attrs
[
'enable_fp16'
]
else
self
.
feed_fp32
for
i
in
range
(
run_steps
):
tmp
=
exe
.
run
(
program
,
feed
=
feed
,
fetch_list
=
fetch_list
)
if
save_otherwise_load
and
\
i
==
self
.
attrs
[
'save_at_step'
]
-
1
:
ipu_program
.
_backend
.
weights_to_host
()
paddle
.
static
.
save
(
main_prog
,
self
.
attrs
[
'model_path'
].
name
)
if
save_otherwise_load
and
i
>=
self
.
attrs
[
'save_at_step'
]:
result
.
append
(
tmp
)
elif
not
save_otherwise_load
:
result
.
append
(
tmp
)
return
np
.
asarray
(
result
).
flatten
()
x
=
paddle
.
static
.
data
(
name
=
self
.
feed_list
[
0
],
shape
=
self
.
feed_shape
[
0
],
dtype
=
'float32'
)
conv1
=
paddle
.
static
.
nn
.
conv2d
(
x
,
num_filters
=
3
,
filter_size
=
3
,
bias_attr
=
False
,
name
=
'conv2d'
)
loss
=
paddle
.
mean
(
conv1
)
# apply optimizer
self
.
optimizer
().
minimize
(
loss
)
self
.
fetch_list
=
[
loss
.
name
]
def
run_model
(
self
,
exec_mode
,
save_otherwise_load
):
self
.
build_model
()
place
=
paddle
.
IPUPlace
()
exe
=
paddle
.
static
.
Executor
(
place
)
exe
.
run
(
self
.
startup_prog
)
if
not
save_otherwise_load
:
paddle
.
static
.
load
(
self
.
main_prog
,
self
.
attrs
[
'model_path'
].
name
)
ipu_strategy
=
paddle
.
static
.
IpuStrategy
()
ipu_strategy
.
set_graph_config
(
is_training
=
True
)
if
self
.
is_fp16_mode
(
exec_mode
):
ipu_strategy
.
set_precision_config
(
enable_fp16
=
True
)
IPUOpTest
.
cast_model_to_fp16
(
self
.
main_prog
)
ipu_compiler
=
paddle
.
static
.
IpuCompiledProgram
(
self
.
main_prog
,
ipu_strategy
=
ipu_strategy
)
program
=
ipu_compiler
.
compile
(
self
.
feed_list
,
self
.
fetch_list
)
feed
=
self
.
feed_fp32
if
self
.
is_fp16_mode
(
exec_mode
):
feed
=
self
.
feed_fp16
result
=
[]
run_steps
=
self
.
attrs
[
'steps'
]
if
save_otherwise_load
\
else
self
.
attrs
[
'steps'
]
-
self
.
attrs
[
'save_at_step'
]
for
i
in
range
(
run_steps
):
tmp
=
exe
.
run
(
program
,
feed
=
feed
,
fetch_list
=
self
.
fetch_list
)
if
save_otherwise_load
and
\
i
==
self
.
attrs
[
'save_at_step'
]
-
1
:
ipu_compiler
.
_backend
.
weights_to_host
()
paddle
.
static
.
save
(
self
.
main_prog
,
self
.
attrs
[
'model_path'
].
name
)
if
save_otherwise_load
and
i
>=
self
.
attrs
[
'save_at_step'
]:
result
.
append
(
tmp
)
elif
not
save_otherwise_load
:
result
.
append
(
tmp
)
return
np
.
asarray
(
result
)
def
test_base
(
self
):
res0
=
self
.
_test_base
(
True
)
res1
=
self
.
_test_base
(
False
)
res0
=
self
.
run_model
(
IPUOpTest
.
ExecutionMode
.
IPU_FP32
,
True
)
res1
=
self
.
run_model
(
IPUOpTest
.
ExecutionMode
.
IPU_FP32
,
False
)
self
.
assertTrue
(
np
.
allclose
(
res0
.
flatten
(),
res1
.
flatten
(),
atol
=
self
.
atol
))
self
.
attrs
[
'model_path'
].
cleanup
()
...
...
@@ -185,12 +180,18 @@ class TestSGDFP16(TestBase):
self
.
attrs
=
{}
self
.
attrs
[
'steps'
]
=
100
self
.
attrs
[
'save_at_step'
]
=
20
self
.
attrs
[
'enable_fp16'
]
=
True
self
.
attrs
[
'model_path'
]
=
tempfile
.
TemporaryDirectory
()
def
set_optimizer
(
self
):
self
.
optimizer
=
partial
(
paddle
.
optimizer
.
SGD
,
learning_rate
=
1e-1
)
def
test_base
(
self
):
res0
=
self
.
run_model
(
IPUOpTest
.
ExecutionMode
.
IPU_FP16
,
True
)
res1
=
self
.
run_model
(
IPUOpTest
.
ExecutionMode
.
IPU_FP16
,
False
)
self
.
assertTrue
(
np
.
allclose
(
res0
.
flatten
(),
res1
.
flatten
(),
atol
=
self
.
atol
))
self
.
attrs
[
'model_path'
].
cleanup
()
class
TestMomentumFp16
(
TestSGDFP16
):
...
...
python/paddle/fluid/tests/unittests/ipu/test_scaled_optimizer_state_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -28,6 +28,10 @@ class TestBase(IPUOpTest):
self
.
set_feed_attr
()
self
.
set_attrs
()
@
property
def
fp16_enabled
(
self
):
return
False
def
set_training
(
self
):
self
.
is_training
=
True
self
.
epoch
=
100
...
...
python/paddle/fluid/tests/unittests/ipu/test_weight_decay_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -83,7 +83,7 @@ class TestBase(IPUOpTest):
loss
=
paddle
.
mean
(
conv1
)
opt
=
paddle
.
optimizer
.
Lamb
(
learning_rate
=
1e-
1
,
learning_rate
=
1e-
3
,
lamb_weight_decay
=
self
.
attrs
[
'weight_decay'
],
exclude_from_weight_decay_fn
=
exclude_fn
)
opt
.
minimize
(
loss
)
...
...
python/paddle/fluid/tests/unittests/ipu/test_yolo_box_op_ipu.py
浏览文件 @
8a07d02c
...
...
@@ -29,6 +29,12 @@ class TestBase(IPUOpTest):
self
.
set_feed_attr
()
self
.
set_op_attrs
()
def
set_atol
(
self
):
self
.
atol
=
1e-6
self
.
rtol
=
1e-6
self
.
atol_fp16
=
1e-2
self
.
rtol_fp16
=
1e-2
def
set_data_feed
(
self
):
data
=
np
.
random
.
uniform
(
size
=
[
1
,
255
,
13
,
13
])
self
.
feed_fp32
=
{
"in_0"
:
data
.
astype
(
np
.
float32
)}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录