Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
316ea549
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看板
未验证
提交
316ea549
编写于
4月 08, 2020
作者:
L
liym27
提交者:
GitHub
4月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert to usage of 'fill_constant' in test_transformer. test=develop (#23529)
上级
ca7bd2be
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
14 addition
and
13 deletion
+14
-13
python/paddle/fluid/tests/unittests/dygraph_to_static/test_transformer.py
...uid/tests/unittests/dygraph_to_static/test_transformer.py
+12
-11
python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py
.../unittests/dygraph_to_static/transformer_dygraph_model.py
+2
-2
未找到文件。
python/paddle/fluid/tests/unittests/dygraph_to_static/test_transformer.py
浏览文件 @
316ea549
...
...
@@ -29,7 +29,7 @@ trainer_count = 1
place
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
is_compiled_with_cuda
()
else
fluid
.
CPUPlace
(
)
SEED
=
10
step_num
=
10
STEP_NUM
=
10
def
train_static
(
args
,
batch_generator
):
...
...
@@ -109,7 +109,7 @@ def train_static(args, batch_generator):
else
:
logging
.
info
(
"step_idx: %d, epoch: %d, batch: %d, avg loss: %f, "
"normalized loss: %f, ppl: %f, speed: %.2f step/s"
%
"normalized loss: %f, ppl: %f, speed: %.2f step
s
/s"
%
(
step_idx
,
pass_id
,
batch_id
,
total_avg_cost
,
total_avg_cost
-
loss_normalizer
,
np
.
exp
([
min
(
total_avg_cost
,
100
)]),
...
...
@@ -118,7 +118,7 @@ def train_static(args, batch_generator):
batch_id
+=
1
step_idx
+=
1
total_batch_num
=
total_batch_num
+
1
if
step_idx
==
step_num
:
if
step_idx
==
STEP_NUM
:
if
args
.
save_dygraph_model_path
:
model_path
=
os
.
path
.
join
(
args
.
save_static_model_path
,
"transformer"
)
...
...
@@ -193,7 +193,8 @@ def train_dygraph(args, batch_generator):
else
:
logging
.
info
(
"step_idx: %d, epoch: %d, batch: %d, avg loss: %f, "
"normalized loss: %f, ppl: %f, speed: %.2f step/s"
%
"normalized loss: %f, ppl: %f, speed: %.2f steps/s"
%
(
step_idx
,
pass_id
,
batch_id
,
total_avg_cost
,
total_avg_cost
-
loss_normalizer
,
np
.
exp
([
min
(
total_avg_cost
,
100
)]),
...
...
@@ -202,7 +203,7 @@ def train_dygraph(args, batch_generator):
avg_batch_time
=
time
.
time
()
batch_id
+=
1
step_idx
+=
1
if
step_idx
==
step_num
:
if
step_idx
==
STEP_NUM
:
if
args
.
save_dygraph_model_path
:
model_dir
=
os
.
path
.
join
(
args
.
save_dygraph_model_path
)
if
not
os
.
path
.
exists
(
model_dir
):
...
...
@@ -277,14 +278,14 @@ def predict_dygraph(args, batch_generator):
speed
=
args
.
print_step
/
(
time
.
time
()
-
avg_batch_time
)
speed_list
.
append
(
speed
)
logging
.
info
(
"Dygraph Predict: step_idx: %d, 1st seq_id: %d, 1st seq_score: %.2f, speed: %.3f step/s"
"Dygraph Predict: step_idx: %d, 1st seq_id: %d, 1st seq_score: %.2f, speed: %.3f step
s
/s"
%
(
step_idx
,
seq_ids
[
0
][
0
][
0
],
seq_scores
[
0
][
0
],
speed
))
avg_batch_time
=
time
.
time
()
step_idx
+=
1
if
step_idx
==
step_num
:
if
step_idx
==
STEP_NUM
:
break
logging
.
info
(
"Dygraph Predict: avg_speed: %.4f step/s"
%
logging
.
info
(
"Dygraph Predict: avg_speed: %.4f step
s
/s"
%
(
np
.
mean
(
speed_list
)))
return
seq_ids
,
seq_scores
...
...
@@ -353,14 +354,14 @@ def predict_static(args, batch_generator):
speed
=
args
.
print_step
/
(
time
.
time
()
-
avg_batch_time
)
speed_list
.
append
(
speed
)
logging
.
info
(
"Static Predict: step_idx: %d, 1st seq_id: %d, 1st seq_score: %.2f, speed: %.3f step/s"
"Static Predict: step_idx: %d, 1st seq_id: %d, 1st seq_score: %.2f, speed: %.3f step
s
/s"
%
(
step_idx
,
seq_ids
[
0
][
0
][
0
],
seq_scores
[
0
][
0
],
speed
))
avg_batch_time
=
time
.
time
()
step_idx
+=
1
if
step_idx
==
step_num
:
if
step_idx
==
STEP_NUM
:
break
logging
.
info
(
"Static Predict: avg_speed: %.4f step/s"
%
logging
.
info
(
"Static Predict: avg_speed: %.4f step
s
/s"
%
(
np
.
mean
(
speed_list
)))
return
seq_ids
,
seq_scores
...
...
python/paddle/fluid/tests/unittests/dygraph_to_static/transformer_dygraph_model.py
浏览文件 @
316ea549
...
...
@@ -608,8 +608,8 @@ class Transformer(Layer):
}
for
i
in
range
(
self
.
n_layer
)]
for
i
in
range
(
max_len
):
trg_pos
=
layers
.
zeros_like
(
trg_word
)
+
i
# TODO: modified for dygraph2static
trg_pos
=
layers
.
fill_constant
(
shape
=
trg_word
.
shape
,
dtype
=
"int64"
,
value
=
i
)
caches
=
map_structure
(
merge_batch_beams
,
caches
)
# TODO: modified for dygraph2static
logits
=
self
.
decoder
(
trg_word
,
trg_pos
,
None
,
trg_src_attn_bias
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录