From 615038c33f19bcb14e00b3d7d75cdd0e3c24787b Mon Sep 17 00:00:00 2001 From: phlrain Date: Wed, 12 Feb 2020 08:54:36 +0000 Subject: [PATCH] change load to load_program_sate, set_program_state; test=develop --- PaddleNLP/PaddleLARK/BERT/utils/init.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PaddleNLP/PaddleLARK/BERT/utils/init.py b/PaddleNLP/PaddleLARK/BERT/utils/init.py index 8948eae5..e3594871 100644 --- a/PaddleNLP/PaddleLARK/BERT/utils/init.py +++ b/PaddleNLP/PaddleLARK/BERT/utils/init.py @@ -62,7 +62,19 @@ def init_pretraining_params(exe, assert os.path.exists(pretraining_params_path ), "[%s] cann't be found." % pretraining_params_path - fluid.load( main_program, pretraining_params_path, exe) + def existed_params(var): + if not isinstance(var, fluid.framework.Parameter): + 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 + + load_var_list = list(filter(existed_params, main_program.list_vars()) ) + para_state = fluid.load_program_state( pretraining_params_path, var_list = load_var_list) + fluid.set_program_state( main_program, para_state) print("Load pretraining parameters from {}.".format( pretraining_params_path)) -- GitLab