Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
785684ad
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看板
未验证
提交
785684ad
编写于
8月 06, 2023
作者:
C
co63oc
提交者:
GitHub
8月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix typos in dy2st unittests (#56006)
上级
9877fb88
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
30 addition
and
30 deletion
+30
-30
test/dygraph_to_static/ifelse_simple_func.py
test/dygraph_to_static/ifelse_simple_func.py
+5
-5
test/dygraph_to_static/seq2seq_dygraph_model.py
test/dygraph_to_static/seq2seq_dygraph_model.py
+1
-1
test/dygraph_to_static/test_ifelse.py
test/dygraph_to_static/test_ifelse.py
+2
-2
test/dygraph_to_static/test_jit_property_save.py
test/dygraph_to_static/test_jit_property_save.py
+1
-1
test/dygraph_to_static/test_jit_setitem.py
test/dygraph_to_static/test_jit_setitem.py
+5
-5
test/dygraph_to_static/test_origin_info.py
test/dygraph_to_static/test_origin_info.py
+3
-3
test/dygraph_to_static/test_program_translator.py
test/dygraph_to_static/test_program_translator.py
+9
-9
test/dygraph_to_static/test_resnet_amp.py
test/dygraph_to_static/test_resnet_amp.py
+1
-1
test/dygraph_to_static/test_seq2seq.py
test/dygraph_to_static/test_seq2seq.py
+2
-2
test/dygraph_to_static/test_tensor_shape.py
test/dygraph_to_static/test_tensor_shape.py
+1
-1
未找到文件。
test/dygraph_to_static/ifelse_simple_func.py
浏览文件 @
785684ad
...
...
@@ -21,9 +21,9 @@ def add_fn(x):
return
x
def
loss_fn
(
x
,
lab
le
):
def
loss_fn
(
x
,
lab
el
):
loss
=
paddle
.
nn
.
functional
.
cross_entropy
(
x
,
lab
le
,
reduction
=
'none'
,
use_softmax
=
False
x
,
lab
el
,
reduction
=
'none'
,
use_softmax
=
False
)
return
loss
...
...
@@ -57,7 +57,7 @@ def dyfunc_with_if_else(x_v, label=None):
def
dyfunc_with_if_else2
(
x
,
col
=
100
):
row
=
0
if
abs
(
col
)
>
x
.
shape
[
-
1
]:
# TODO: Don't support return non-Tensor in Tensor-dependent `if` stament currently.
# TODO: Don't support return non-Tensor in Tensor-dependent `if` sta
te
ment currently.
# `x` is Tensor, `col` is not Tensor, and `col` is the return value of `true_fn` after transformed.
# col = -1
col
=
paddle
.
tensor
.
fill_constant
(
shape
=
[
1
],
value
=-
1
,
dtype
=
"int64"
)
...
...
@@ -136,7 +136,7 @@ def dyfunc_with_if_else_early_return2():
return
e
,
None
def
dyfunc_with_if_else_with_list_geneator
(
x
):
def
dyfunc_with_if_else_with_list_gene
r
ator
(
x
):
if
10
>
5
:
y
=
paddle
.
add_n
(
[
paddle
.
full
(
shape
=
[
2
],
fill_value
=
v
)
for
v
in
range
(
5
)]
...
...
@@ -151,7 +151,7 @@ def nested_if_else(x_v):
feat_size
=
x_v
.
shape
[
-
1
]
bias
=
paddle
.
tensor
.
fill_constant
([
feat_size
],
dtype
=
'float32'
,
value
=
1
)
if
x_v
.
shape
[
0
]
!=
batch_size
:
# TODO: Don't support return non-Tensor in Tensor-dependent `if` stament currently.
# TODO: Don't support return non-Tensor in Tensor-dependent `if` sta
te
ment currently.
# `x_v.shape[0]` is not Tensor, and `batch_size` is the return value of `true_fn` after transformed.
# col = -1
# batch_size = x_v.shape[0]
...
...
test/dygraph_to_static/seq2seq_dygraph_model.py
浏览文件 @
785684ad
...
...
@@ -728,7 +728,7 @@ class AttentionModel(paddle.nn.Layer):
src_emb
=
self
.
src_embeder
(
self
.
_transpose_batch_time
(
src
))
# NOTE: modify model code about `enc_hidden` and `enc_cell` to transform
e
dygraph code successfully.
# NOTE: modify model code about `enc_hidden` and `enc_cell` to transform dygraph code successfully.
# Because nested list can't be transformed now.
enc_hidden_0
=
to_variable
(
np
.
zeros
((
self
.
batch_size
,
self
.
hidden_size
),
dtype
=
'float32'
)
...
...
test/dygraph_to_static/test_ifelse.py
浏览文件 @
785684ad
...
...
@@ -26,7 +26,7 @@ from ifelse_simple_func import (
dyfunc_with_if_else
,
dyfunc_with_if_else2
,
dyfunc_with_if_else3
,
dyfunc_with_if_else_with_list_geneator
,
dyfunc_with_if_else_with_list_gene
r
ator
,
fluid
,
if_tensor_case
,
if_with_and_or
,
...
...
@@ -116,7 +116,7 @@ class TestDygraphIfElse4(TestDygraphIfElse):
class
TestDygraphIfElseWithListGenerator
(
TestDygraphIfElse
):
def
setUp
(
self
):
self
.
x
=
np
.
random
.
random
([
10
,
16
]).
astype
(
'float32'
)
self
.
dyfunc
=
dyfunc_with_if_else_with_list_geneator
self
.
dyfunc
=
dyfunc_with_if_else_with_list_gene
r
ator
class
TestDygraphNestedIfElse
(
TestDygraphIfElse
):
...
...
test/dygraph_to_static/test_jit_property_save.py
浏览文件 @
785684ad
...
...
@@ -44,7 +44,7 @@ class TestPropertySave(unittest.TestCase):
self
.
a
.
get_float
(
1
)
def
test_set
(
self
):
"""test propety set."""
"""test prope
r
ty set."""
try
:
a
=
paddle
.
framework
.
core
.
Property
()
a
.
set_float
(
'float'
,
10.0
)
...
...
test/dygraph_to_static/test_jit_setitem.py
浏览文件 @
785684ad
...
...
@@ -39,13 +39,13 @@ class TestSetItemBase(unittest.TestCase):
def
test_case
(
self
):
func
=
self
.
init_func
()
dy_res
=
self
.
run_dygrah
(
func
)
dy_res
=
self
.
run_dygra
p
h
(
func
)
st_res
=
self
.
run_to_static
(
func
)
for
dy_out
,
st_out
in
zip
(
dy_res
,
st_res
):
np
.
testing
.
assert_allclose
(
dy_out
.
numpy
(),
st_out
.
numpy
())
def
run_dygrah
(
self
,
func
):
def
run_dygra
p
h
(
self
,
func
):
x
=
self
.
init_data
()
y
=
func
(
x
)
x_grad
=
paddle
.
grad
(
y
,
x
)[
0
]
...
...
@@ -53,7 +53,7 @@ class TestSetItemBase(unittest.TestCase):
def
run_to_static
(
self
,
func
):
func
=
paddle
.
jit
.
to_static
(
func
)
return
self
.
run_dygrah
(
func
)
return
self
.
run_dygra
p
h
(
func
)
class
TestCase1
(
TestSetItemBase
):
...
...
@@ -169,7 +169,7 @@ class TestCase11(TestSetItemBase):
return
foo
def
run_dygrah
(
self
,
func
):
def
run_dygra
p
h
(
self
,
func
):
x
=
self
.
init_data
()
value
=
paddle
.
ones
((
16
,
32
))
value
.
stop_gradient
=
False
...
...
@@ -188,7 +188,7 @@ class TestCase12(TestSetItemBase):
return
foo
def
run_dygrah
(
self
,
func
):
def
run_dygra
p
h
(
self
,
func
):
x
=
self
.
init_data
()
value
=
paddle
.
ones
((
32
,))
value
.
stop_gradient
=
False
...
...
test/dygraph_to_static/test_origin_info.py
浏览文件 @
785684ad
...
...
@@ -116,8 +116,8 @@ class TestOriginInfo(unittest.TestCase):
for
i
in
range
(
self
.
line_num
):
static_lineno
=
self
.
static_abs_lineno_list
[
i
]
staic_loc
=
Location
(
static_filepath
,
static_lineno
)
self
.
assertIn
(
staic_loc
.
line_location
,
origin_info_map
)
sta
t
ic_loc
=
Location
(
static_filepath
,
static_lineno
)
self
.
assertIn
(
sta
t
ic_loc
.
line_location
,
origin_info_map
)
dy_lineno
=
dygraph_abs_lineno_list
[
i
]
dy_col_offset
=
self
.
dy_abs_col_offset
[
i
]
...
...
@@ -129,7 +129,7 @@ class TestOriginInfo(unittest.TestCase):
code
,
)
self
.
assertEqual
(
str
(
origin_info_map
[
staic_loc
.
line_location
]),
str
(
origin_info
)
str
(
origin_info_map
[
sta
t
ic_loc
.
line_location
]),
str
(
origin_info
)
)
def
test_attach_origin_info
(
self
):
...
...
test/dygraph_to_static/test_program_translator.py
浏览文件 @
785684ad
...
...
@@ -261,23 +261,23 @@ class SwitchModeNet(paddle.nn.Layer):
@
paddle
.
jit
.
to_static
def
switch_mode_func
it
on
():
def
switch_mode_func
ti
on
():
return
True
class
TestFunctionTrainEvalMode
(
unittest
.
TestCase
):
def
test_switch_mode
(
self
):
paddle
.
disable_static
()
switch_mode_func
it
on
.
eval
()
switch_mode_func
it
on
()
self
.
assertEqual
(
switch_mode_func
it
on
.
_training
,
False
)
_
,
partial_layer
=
switch_mode_func
it
on
.
program_cache
.
last
()[
-
1
]
switch_mode_func
ti
on
.
eval
()
switch_mode_func
ti
on
()
self
.
assertEqual
(
switch_mode_func
ti
on
.
_training
,
False
)
_
,
partial_layer
=
switch_mode_func
ti
on
.
program_cache
.
last
()[
-
1
]
self
.
assertEqual
(
partial_layer
.
training
,
False
)
switch_mode_func
it
on
.
train
()
switch_mode_func
it
on
()
self
.
assertEqual
(
switch_mode_func
it
on
.
_training
,
True
)
_
,
partial_layer
=
switch_mode_func
it
on
.
program_cache
.
last
()[
-
1
]
switch_mode_func
ti
on
.
train
()
switch_mode_func
ti
on
()
self
.
assertEqual
(
switch_mode_func
ti
on
.
_training
,
True
)
_
,
partial_layer
=
switch_mode_func
ti
on
.
program_cache
.
last
()[
-
1
]
self
.
assertEqual
(
partial_layer
.
training
,
True
)
def
test_raise_error
(
self
):
...
...
test/dygraph_to_static/test_resnet_amp.py
浏览文件 @
785684ad
...
...
@@ -70,7 +70,7 @@ def train(to_static, build_strategy=None):
with
paddle
.
amp
.
auto_cast
():
pred
=
resnet
(
img
)
# FIXME(Aurelius84): The follow
d
ing cross_entropy seems to bring out a
# FIXME(Aurelius84): The following cross_entropy seems to bring out a
# precision problem, need to figure out the underlying reason.
# If we remove it, the loss between dygraph and dy2stat is exactly same.
loss
=
paddle
.
nn
.
functional
.
cross_entropy
(
...
...
test/dygraph_to_static/test_seq2seq.py
浏览文件 @
785684ad
...
...
@@ -70,11 +70,11 @@ def train(args, attn_model=False):
dropout
=
args
.
dropout
,
)
glo
ab
l_norm_clip
=
ClipGradByGlobalNorm
(
args
.
max_grad_norm
)
glo
ba
l_norm_clip
=
ClipGradByGlobalNorm
(
args
.
max_grad_norm
)
optimizer
=
fluid
.
optimizer
.
SGD
(
args
.
learning_rate
,
parameter_list
=
model
.
parameters
(),
grad_clip
=
glo
ab
l_norm_clip
,
grad_clip
=
glo
ba
l_norm_clip
,
)
model
.
train
()
...
...
test/dygraph_to_static/test_tensor_shape.py
浏览文件 @
785684ad
...
...
@@ -486,7 +486,7 @@ class TestTensorShapeInWhile4(TestTensorShapeBasic):
self
.
expected_slice_op_num
=
0
# 5. Test op num for neg
e
tive dim
# 5. Test op num for neg
a
tive dim
class
TestOpNumBasicWithTensorShape
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
_set_input_spec
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录