Skip to content

Commit 8f70b66

Browse files
authored
Merge pull request #729 from hohdiy/dev
config_parser增加新特性:支持同一个python文件内配置paddle
2 parents 239cade + 7c76d0e commit 8f70b66

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

python/paddle/trainer/config_parser.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3377,7 +3377,20 @@ def parse_config(config_file, config_arg_str):
33773377
g_root_submodel.is_recurrent_layer_group = False
33783378
g_current_submodel = g_root_submodel
33793379

3380-
execfile(config_file, make_config_environment(config_file, config_args))
3380+
# for paddle on spark, need support non-file config.
3381+
# you can use parse_config like below:
3382+
#
3383+
# from paddle.trainer.config_parser import parse_config
3384+
# def configs():
3385+
# #your paddle config code, which is same as config file.
3386+
#
3387+
# config = parse_config(configs, "is_predict=1")
3388+
# # then you get config proto object.
3389+
if hasattr(config_file, '__call__'):
3390+
config_file.func_globals.update(make_config_environment("", config_args))
3391+
config_file()
3392+
else:
3393+
execfile(config_file, make_config_environment(config_file, config_args))
33813394
for k, v in settings.iteritems():
33823395
if v is None:
33833396
continue

0 commit comments

Comments
 (0)