From 7c76d0eeac9baa14ccff55b7edbdea2e2833d6ae Mon Sep 17 00:00:00 2001 From: hanchao Date: Mon, 28 Nov 2016 14:20:37 +0800 Subject: [PATCH] config_parser new feature at ISSUE #726 --- python/paddle/trainer/config_parser.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/paddle/trainer/config_parser.py b/python/paddle/trainer/config_parser.py index a19a9a7cd65..01ff586c4f1 100644 --- a/python/paddle/trainer/config_parser.py +++ b/python/paddle/trainer/config_parser.py @@ -3377,7 +3377,20 @@ def parse_config(config_file, config_arg_str): g_root_submodel.is_recurrent_layer_group = False g_current_submodel = g_root_submodel - execfile(config_file, make_config_environment(config_file, config_args)) + # for paddle on spark, need support non-file config. + # you can use parse_config like below: + # + # from paddle.trainer.config_parser import parse_config + # def configs(): + # #your paddle config code, which is same as config file. + # + # config = parse_config(configs, "is_predict=1") + # # then you get config proto object. + if hasattr(config_file, '__call__'): + config_file.func_globals.update(make_config_environment("", config_args)) + config_file() + else: + execfile(config_file, make_config_environment(config_file, config_args)) for k, v in settings.iteritems(): if v is None: continue -- GitLab