From 796866fa74f23850b977d4023a7ed4f0031844ae Mon Sep 17 00:00:00 2001 From: zhangshengdong29 <435878393@qq.com> Date: Tue, 24 Oct 2023 10:18:54 +0800 Subject: [PATCH] fix the config file unclose (#268) We have a runtime checker, and it report: ``` ResourceWarning: unclosed file <_io.TextIOWrapper name='deepspeed_config_13B.json' mode='r' encoding='utf-8'> open(args.deepspeed_config, 'r', encoding='utf-8')) ``` Because when json.load(open()), it never close. --- megatron/training.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/megatron/training.py b/megatron/training.py index b0880206b5..98df5bd2b4 100644 --- a/megatron/training.py +++ b/megatron/training.py @@ -69,8 +69,8 @@ def print_datetime(string): ''' def _create_ds_config_dict(): args = get_args() - ds_config_dict = json.load( - open(args.deepspeed_config, 'r', encoding='utf-8')) + with open(args.deepspeed_config, 'r', encoding='utf-8') as config_file: + ds_config_dict = json.load(config_file) if args.universal_checkpoint: ds_config_dict["checkpoint"] = {"load_universal": True}