Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
9f7258da
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看板
提交
9f7258da
编写于
2月 06, 2020
作者:
P
phlrain
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new save load interface; test=develop
上级
54f64c66
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
15 addition
and
29 deletion
+15
-29
PaddleNLP/PaddleLARK/BERT/convert_params.py
PaddleNLP/PaddleLARK/BERT/convert_params.py
+2
-1
PaddleNLP/PaddleLARK/BERT/run_classifier.py
PaddleNLP/PaddleLARK/BERT/run_classifier.py
+2
-2
PaddleNLP/PaddleLARK/BERT/run_squad.py
PaddleNLP/PaddleLARK/BERT/run_squad.py
+2
-2
PaddleNLP/PaddleLARK/BERT/train.py
PaddleNLP/PaddleLARK/BERT/train.py
+3
-2
PaddleNLP/PaddleLARK/BERT/utils/init.py
PaddleNLP/PaddleLARK/BERT/utils/init.py
+6
-22
未找到文件。
PaddleNLP/PaddleLARK/BERT/convert_params.py
浏览文件 @
9f7258da
...
@@ -183,7 +183,8 @@ def convert(args):
...
@@ -183,7 +183,8 @@ def convert(args):
param
]).
get_tensor
().
set
(
value
,
place
)
param
]).
get_tensor
().
set
(
value
,
place
)
print
(
param
,
' --> '
,
tf_fluid_param_name_map
[
param
],
' '
,
value
.
shape
)
print
(
param
,
' --> '
,
tf_fluid_param_name_map
[
param
],
' '
,
value
.
shape
)
fluid
.
io
.
save_params
(
exe
,
args
.
fluid_params_dir
,
main_program
=
program
)
save_path
=
os
.
join
(
args
.
fluid_params_dir
,
"checkpoint"
)
fluid
.
save
(
program
,
save_path
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
PaddleNLP/PaddleLARK/BERT/run_classifier.py
浏览文件 @
9f7258da
...
@@ -392,7 +392,7 @@ def main(args):
...
@@ -392,7 +392,7 @@ 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
)
fluid
.
save
(
train_program
,
save_path
)
if
steps
%
args
.
validation_steps
==
0
:
if
steps
%
args
.
validation_steps
==
0
:
print
(
"Average throughtput: %s"
%
(
np
.
average
(
throughput
)))
print
(
"Average throughtput: %s"
%
(
np
.
average
(
throughput
)))
...
@@ -409,7 +409,7 @@ def main(args):
...
@@ -409,7 +409,7 @@ def main(args):
"test"
)
"test"
)
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
)
fluid
.
save
(
train_program
,
save_path
)
train_data_loader
.
reset
()
train_data_loader
.
reset
()
break
break
if
args
.
enable_ce
:
if
args
.
enable_ce
:
...
...
PaddleNLP/PaddleLARK/BERT/run_squad.py
浏览文件 @
9f7258da
...
@@ -398,11 +398,11 @@ def train(args):
...
@@ -398,11 +398,11 @@ def train(args):
if
steps
%
args
.
save_steps
==
0
or
steps
==
max_train_steps
:
if
steps
%
args
.
save_steps
==
0
or
steps
==
max_train_steps
:
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
)
fluid
.
save
(
train_program
,
save_path
)
except
fluid
.
core
.
EOFException
:
except
fluid
.
core
.
EOFException
:
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
save_path
=
os
.
path
.
join
(
args
.
checkpoints
,
"step_"
+
str
(
steps
)
+
"_final"
)
"step_"
+
str
(
steps
)
+
"_final"
)
fluid
.
io
.
save_persistables
(
exe
,
save_path
,
train_program
)
fluid
.
save
(
train_program
,
save_path
)
train_data_loader
.
reset
()
train_data_loader
.
reset
()
break
break
...
...
PaddleNLP/PaddleLARK/BERT/train.py
浏览文件 @
9f7258da
...
@@ -38,7 +38,7 @@ from optimization import optimization
...
@@ -38,7 +38,7 @@ from optimization import optimization
from
utils.args
import
ArgumentGroup
,
print_arguments
,
check_cuda
from
utils.args
import
ArgumentGroup
,
print_arguments
,
check_cuda
from
utils.init
import
init_checkpoint
,
init_pretraining_params
from
utils.init
import
init_checkpoint
,
init_pretraining_params
#
yapf: disable
yapf
:
disable
parser
=
argparse
.
ArgumentParser
(
__doc__
)
parser
=
argparse
.
ArgumentParser
(
__doc__
)
model_g
=
ArgumentGroup
(
parser
,
"model"
,
"model configuration and paths."
)
model_g
=
ArgumentGroup
(
parser
,
"model"
,
"model configuration and paths."
)
model_g
.
add_arg
(
"bert_config_path"
,
str
,
"./config/bert_config.json"
,
"Path to the json file for bert model config."
)
model_g
.
add_arg
(
"bert_config_path"
,
str
,
"./config/bert_config.json"
,
"Path to the json file for bert model config."
)
...
@@ -412,7 +412,8 @@ def train(args):
...
@@ -412,7 +412,8 @@ def train(args):
if
steps
%
args
.
save_steps
==
0
:
if
steps
%
args
.
save_steps
==
0
:
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
)
#fluid.io.save_persistables(exe, save_path, train_program)
fluid
.
save
(
train_program
,
save_path
)
if
args
.
validation_set_dir
and
steps
%
args
.
validation_steps
==
0
:
if
args
.
validation_set_dir
and
steps
%
args
.
validation_steps
==
0
:
vali_cost
,
vali_lm_cost
,
vali_acc
,
vali_steps
,
vali_speed
=
predict
(
vali_cost
,
vali_lm_cost
,
vali_acc
,
vali_steps
,
vali_speed
=
predict
(
...
...
PaddleNLP/PaddleLARK/BERT/utils/init.py
浏览文件 @
9f7258da
...
@@ -48,11 +48,7 @@ def init_checkpoint(exe, init_checkpoint_path, main_program, use_fp16=False):
...
@@ -48,11 +48,7 @@ def init_checkpoint(exe, init_checkpoint_path, main_program, use_fp16=False):
print
(
"INIT {}"
.
format
(
var
.
name
))
print
(
"INIT {}"
.
format
(
var
.
name
))
return
True
return
True
fluid
.
io
.
load_vars
(
fluid
.
load
(
main_program
,
init_checkpoint_path
,
exe
)
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
))
if
use_fp16
:
if
use_fp16
:
...
@@ -63,24 +59,12 @@ def init_pretraining_params(exe,
...
@@ -63,24 +59,12 @@ def init_pretraining_params(exe,
pretraining_params_path
,
pretraining_params_path
,
main_program
,
main_program
,
use_fp16
=
False
):
use_fp16
=
False
):
assert
os
.
path
.
exists
(
pretraining_params_path
assert
os
.
path
.
exists
(
pretraining_params_path
+
".params"
),
"[%s] cann't be found."
%
pretraining_params_path
),
"[%s] cann't be found."
%
(
pretraining_params_path
+
".params"
)
def
existed_params
(
var
):
program_state
=
fluid
.
load_program_state
(
pretraining_params_path
)
if
not
isinstance
(
var
,
fluid
.
framework
.
Parameter
):
fluid
.
set_program_state
(
main_program
,
program_state
)
return
False
if
os
.
path
.
exists
(
os
.
path
.
join
(
pretraining_params_path
,
var
.
name
)):
print
(
"INIT {}"
.
format
(
var
.
name
))
return
True
else
:
print
(
"SKIP {}"
.
format
(
var
.
name
))
return
False
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录