Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
4d28bb18
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4d28bb18
编写于
2月 24, 2020
作者:
X
Xing Wu
提交者:
GitHub
2月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update save/load for v1.7 (#4332)
* update save/load for v1.7 * update load api * update load api
上级
d0937f0b
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
48 addition
and
75 deletion
+48
-75
PaddleNLP/PaddleTextGEN/seq2seq/infer.py
PaddleNLP/PaddleTextGEN/seq2seq/infer.py
+2
-1
PaddleNLP/PaddleTextGEN/seq2seq/train.py
PaddleNLP/PaddleTextGEN/seq2seq/train.py
+5
-4
PaddleNLP/PaddleTextGEN/variational_seq2seq/infer.py
PaddleNLP/PaddleTextGEN/variational_seq2seq/infer.py
+2
-1
PaddleNLP/PaddleTextGEN/variational_seq2seq/train.py
PaddleNLP/PaddleTextGEN/variational_seq2seq/train.py
+5
-4
PaddleNLP/lexical_analysis/run_ernie_sequence_labeling.py
PaddleNLP/lexical_analysis/run_ernie_sequence_labeling.py
+6
-6
PaddleNLP/lexical_analysis/train.py
PaddleNLP/lexical_analysis/train.py
+3
-2
PaddleNLP/lexical_analysis/utils.py
PaddleNLP/lexical_analysis/utils.py
+7
-25
PaddleNLP/sentiment_classification/run_classifier.py
PaddleNLP/sentiment_classification/run_classifier.py
+6
-4
PaddleNLP/sentiment_classification/run_ernie_classifier.py
PaddleNLP/sentiment_classification/run_ernie_classifier.py
+6
-4
PaddleNLP/sentiment_classification/utils.py
PaddleNLP/sentiment_classification/utils.py
+6
-24
未找到文件。
PaddleNLP/PaddleTextGEN/seq2seq/infer.py
浏览文件 @
4d28bb18
...
@@ -127,7 +127,8 @@ def infer():
...
@@ -127,7 +127,8 @@ def infer():
dir_name
=
args
.
reload_model
dir_name
=
args
.
reload_model
print
(
"dir name"
,
dir_name
)
print
(
"dir name"
,
dir_name
)
fluid
.
io
.
load_params
(
exe
,
dir_name
)
dir_name
=
os
.
path
.
join
(
dir_name
,
"checkpoint"
)
fluid
.
load
(
main_program
,
dir_name
,
exe
)
train_data_iter
=
reader
.
get_data_iter
(
infer_data
,
1
,
mode
=
'eval'
)
train_data_iter
=
reader
.
get_data_iter
(
infer_data
,
1
,
mode
=
'eval'
)
...
...
PaddleNLP/PaddleTextGEN/seq2seq/train.py
浏览文件 @
4d28bb18
...
@@ -229,10 +229,11 @@ def main():
...
@@ -229,10 +229,11 @@ def main():
%
(
epoch_id
,
epoch_time
,
sum
(
batch_times
)
/
len
(
batch_times
)))
%
(
epoch_id
,
epoch_time
,
sum
(
batch_times
)
/
len
(
batch_times
)))
if
not
args
.
profile
:
if
not
args
.
profile
:
dir_name
=
os
.
path
.
join
(
args
.
model_path
,
save_path
=
os
.
path
.
join
(
args
.
model_path
,
"epoch_"
+
str
(
epoch_id
))
"epoch_"
+
str
(
epoch_id
),
print
(
"begin to save"
,
dir_name
)
"checkpoint"
)
fluid
.
io
.
save_params
(
exe
,
dir_name
,
main_program
=
train_program
)
print
(
"begin to save"
,
save_path
)
fluid
.
save
(
train_program
,
save_path
)
print
(
"save finished"
)
print
(
"save finished"
)
dev_ppl
=
eval
(
valid_data
)
dev_ppl
=
eval
(
valid_data
)
print
(
"dev ppl"
,
dev_ppl
)
print
(
"dev ppl"
,
dev_ppl
)
...
...
PaddleNLP/PaddleTextGEN/variational_seq2seq/infer.py
浏览文件 @
4d28bb18
...
@@ -88,7 +88,8 @@ def infer():
...
@@ -88,7 +88,8 @@ def infer():
dir_name
=
args
.
reload_model
dir_name
=
args
.
reload_model
print
(
"dir name"
,
dir_name
)
print
(
"dir name"
,
dir_name
)
fluid
.
io
.
load_params
(
exe
,
dir_name
)
dir_name
=
os
.
path
.
join
(
dir_name
,
"checkpoint"
)
fluid
.
load
(
main_program
,
dir_name
,
exe
)
vocab
,
tar_id2vocab
=
get_vocab
(
args
.
dataset_prefix
)
vocab
,
tar_id2vocab
=
get_vocab
(
args
.
dataset_prefix
)
infer_output
=
np
.
ones
((
batch_size
,
1
),
dtype
=
'int64'
)
*
BOS_ID
infer_output
=
np
.
ones
((
batch_size
,
1
),
dtype
=
'int64'
)
*
BOS_ID
...
...
PaddleNLP/PaddleTextGEN/variational_seq2seq/train.py
浏览文件 @
4d28bb18
...
@@ -255,10 +255,11 @@ def main():
...
@@ -255,10 +255,11 @@ def main():
best_nll
=
test_nll
best_nll
=
test_nll
best_ppl
=
test_ppl
best_ppl
=
test_ppl
best_epoch_id
=
epoch_id
best_epoch_id
=
epoch_id
dir_name
=
os
.
path
.
join
(
args
.
model_path
,
save_path
=
os
.
path
.
join
(
args
.
model_path
,
"epoch_"
+
str
(
best_epoch_id
))
"epoch_"
+
str
(
best_epoch_id
),
print
(
"save model {}"
.
format
(
dir_name
))
"checkpoint"
)
fluid
.
io
.
save_params
(
exe
,
dir_name
,
main_program
)
print
(
"save model {}"
.
format
(
save_path
))
fluid
.
save
(
main_program
,
save_path
)
else
:
else
:
steps_not_improved
+=
1
steps_not_improved
+=
1
if
steps_not_improved
==
decay_ts
:
if
steps_not_improved
==
decay_ts
:
...
...
PaddleNLP/lexical_analysis/run_ernie_sequence_labeling.py
浏览文件 @
4d28bb18
...
@@ -187,17 +187,17 @@ def do_train(args):
...
@@ -187,17 +187,17 @@ def do_train(args):
end_time
-
start_time
,
train_pyreader
.
queue
.
size
()))
end_time
-
start_time
,
train_pyreader
.
queue
.
size
()))
if
steps
%
args
.
save_steps
==
0
:
if
steps
%
args
.
save_steps
==
0
:
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
"step_"
+
str
(
steps
),
"
step_"
+
str
(
steps
)
)
"
checkpoint"
)
print
(
"
\t
saving model as %s"
%
(
save_path
))
print
(
"
\t
saving model as %s"
%
(
save_path
))
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
fluid
.
save
(
train_program
,
save_path
)
if
steps
%
args
.
validation_steps
==
0
:
if
steps
%
args
.
validation_steps
==
0
:
evaluate
(
exe
,
test_program
,
test_pyreader
,
train_ret
)
evaluate
(
exe
,
test_program
,
test_pyreader
,
train_ret
)
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
"step_"
+
str
(
steps
)
)
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
"step_"
+
str
(
steps
)
,
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
def
do_eval
(
args
):
def
do_eval
(
args
):
# init executor
# init executor
...
...
PaddleNLP/lexical_analysis/train.py
浏览文件 @
4d28bb18
...
@@ -151,8 +151,9 @@ def do_train(args):
...
@@ -151,8 +151,9 @@ def do_train(args):
# save checkpoints
# save checkpoints
if
step
%
args
.
save_steps
==
0
and
step
!=
0
:
if
step
%
args
.
save_steps
==
0
and
step
!=
0
:
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
save_path
=
os
.
path
.
join
(
args
.
model_save_dir
,
"step_"
+
str
(
step
))
"step_"
+
str
(
step
),
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
step
+=
1
step
+=
1
if
args
.
enable_ce
:
if
args
.
enable_ce
:
...
...
PaddleNLP/lexical_analysis/utils.py
浏览文件 @
4d28bb18
...
@@ -200,22 +200,13 @@ def init_checkpoint(exe, init_checkpoint_path, main_program):
...
@@ -200,22 +200,13 @@ def init_checkpoint(exe, init_checkpoint_path, main_program):
assert
os
.
path
.
exists
(
assert
os
.
path
.
exists
(
init_checkpoint_path
),
"[%s] cann't be found."
%
init_checkpoint_path
init_checkpoint_path
),
"[%s] cann't be found."
%
init_checkpoint_path
def
existed_persitables
(
var
):
try
:
"""
checkpoint_path
=
os
.
path
.
join
(
init_checkpoint_path
,
"checkpoint"
)
If existed presitabels
fluid
.
load
(
main_program
,
checkpoint_path
,
exe
)
"""
except
:
if
not
fluid
.
io
.
is_persistable
(
var
):
fluid
.
load
(
main_program
,
init_checkpoint_path
,
exe
)
return
False
return
os
.
path
.
exists
(
os
.
path
.
join
(
init_checkpoint_path
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
init_checkpoint_path
,
main_program
=
main_program
,
predicate
=
existed_persitables
)
print
(
"Load model from {}"
.
format
(
init_checkpoint_path
))
print
(
"Load model from {}"
.
format
(
init_checkpoint_path
))
def
init_pretraining_params
(
exe
,
def
init_pretraining_params
(
exe
,
pretraining_params_path
,
pretraining_params_path
,
main_program
,
main_program
,
...
@@ -224,15 +215,6 @@ def init_pretraining_params(exe,
...
@@ -224,15 +215,6 @@ def init_pretraining_params(exe,
assert
os
.
path
.
exists
(
pretraining_params_path
assert
os
.
path
.
exists
(
pretraining_params_path
),
"[%s] cann't be found."
%
pretraining_params_path
),
"[%s] cann't be found."
%
pretraining_params_path
def
_existed_params
(
var
):
fluid
.
load
(
main_program
,
pretraining_params_path
,
exe
)
if
not
isinstance
(
var
,
fluid
.
framework
.
Parameter
):
return
False
return
os
.
path
.
exists
(
os
.
path
.
join
(
pretraining_params_path
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
pretraining_params_path
,
main_program
=
main_program
,
predicate
=
_existed_params
)
print
(
"Load pretraining parameters from {}."
.
format
(
print
(
"Load pretraining parameters from {}."
.
format
(
pretraining_params_path
))
pretraining_params_path
))
PaddleNLP/sentiment_classification/run_classifier.py
浏览文件 @
4d28bb18
...
@@ -289,8 +289,9 @@ def main(args):
...
@@ -289,8 +289,9 @@ def main(args):
if
steps
%
args
.
save_steps
==
0
:
if
steps
%
args
.
save_steps
==
0
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
"step_"
+
str
(
steps
),
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
if
steps
%
args
.
validation_steps
==
0
:
if
steps
%
args
.
validation_steps
==
0
:
# evaluate dev set
# evaluate dev set
...
@@ -301,8 +302,9 @@ def main(args):
...
@@ -301,8 +302,9 @@ def main(args):
"dev"
)
"dev"
)
except
fluid
.
core
.
EOFException
:
except
fluid
.
core
.
EOFException
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
),
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
train_reader
.
reset
()
train_reader
.
reset
()
break
break
...
...
PaddleNLP/sentiment_classification/run_ernie_classifier.py
浏览文件 @
4d28bb18
...
@@ -353,8 +353,9 @@ def main(args):
...
@@ -353,8 +353,9 @@ def main(args):
if
steps
%
args
.
save_steps
==
0
:
if
steps
%
args
.
save_steps
==
0
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
"step_"
+
str
(
steps
),
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
if
steps
%
args
.
validation_steps
==
0
:
if
steps
%
args
.
validation_steps
==
0
:
# evaluate dev set
# evaluate dev set
...
@@ -364,8 +365,9 @@ def main(args):
...
@@ -364,8 +365,9 @@ def main(args):
"dev"
)
"dev"
)
except
fluid
.
core
.
EOFException
:
except
fluid
.
core
.
EOFException
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
))
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
),
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
"checkpoint"
)
fluid
.
save
(
train_program
,
save_path
)
train_pyreader
.
reset
()
train_pyreader
.
reset
()
break
break
...
...
PaddleNLP/sentiment_classification/utils.py
浏览文件 @
4d28bb18
...
@@ -63,20 +63,11 @@ def init_checkpoint(exe, init_checkpoint_path, main_program):
...
@@ -63,20 +63,11 @@ def init_checkpoint(exe, init_checkpoint_path, main_program):
"""
"""
assert
os
.
path
.
exists
(
assert
os
.
path
.
exists
(
init_checkpoint_path
),
"[%s] cann't be found."
%
init_checkpoint_path
init_checkpoint_path
),
"[%s] cann't be found."
%
init_checkpoint_path
try
:
def
existed_persitables
(
var
):
checkpoint_path
=
os
.
path
.
join
(
init_checkpoint_path
,
"checkpoint"
)
"""
fluid
.
load
(
main_program
,
checkpoint_path
,
exe
)
If existed presitabels
except
:
"""
fluid
.
load
(
main_program
,
init_checkpoint_path
,
exe
)
if
not
fluid
.
io
.
is_persistable
(
var
):
return
False
return
os
.
path
.
exists
(
os
.
path
.
join
(
init_checkpoint_path
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
init_checkpoint_path
,
main_program
=
main_program
,
predicate
=
existed_persitables
)
print
(
"Load model from {}"
.
format
(
init_checkpoint_path
))
print
(
"Load model from {}"
.
format
(
init_checkpoint_path
))
...
@@ -144,15 +135,6 @@ def init_pretraining_params(exe,
...
@@ -144,15 +135,6 @@ def init_pretraining_params(exe,
assert
os
.
path
.
exists
(
pretraining_params_path
assert
os
.
path
.
exists
(
pretraining_params_path
),
"[%s] cann't be found."
%
pretraining_params_path
),
"[%s] cann't be found."
%
pretraining_params_path
def
_existed_params
(
var
):
fluid
.
load
(
main_program
,
pretraining_params_path
,
exe
)
if
not
isinstance
(
var
,
fluid
.
framework
.
Parameter
):
return
False
return
os
.
path
.
exists
(
os
.
path
.
join
(
pretraining_params_path
,
var
.
name
))
fluid
.
io
.
load_vars
(
exe
,
pretraining_params_path
,
main_program
=
main_program
,
predicate
=
_existed_params
)
print
(
"Load pretraining parameters from {}."
.
format
(
print
(
"Load pretraining parameters from {}."
.
format
(
pretraining_params_path
))
pretraining_params_path
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录