From d2f96d08671c18cf2c34c340796f908a37dac477 Mon Sep 17 00:00:00 2001 From: Sunting78 Date: Mon, 27 Mar 2023 19:27:34 +0800 Subject: [PATCH 1/3] [update ranks lock] --- paddleseg/utils/utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/paddleseg/utils/utils.py b/paddleseg/utils/utils.py index cad88aacd0..9cf0b9b89f 100644 --- a/paddleseg/utils/utils.py +++ b/paddleseg/utils/utils.py @@ -14,7 +14,6 @@ import os import contextlib -import filelock import tempfile import random from urllib.parse import urlparse, unquote @@ -135,15 +134,14 @@ def download_pretrained_model(pretrained_model): filename = 'model.pdparams' with generate_tempdir() as _dir: - with filelock.FileLock(os.path.join(seg_env.TMP_HOME, savename)): - pretrained_model = download_file_and_uncompress( - pretrained_model, - savepath=_dir, - cover=False, - extrapath=seg_env.PRETRAINED_MODEL_HOME, - extraname=savename, - filename=filename) - pretrained_model = os.path.join(pretrained_model, filename) + pretrained_model = download_file_and_uncompress( + pretrained_model, + savepath=_dir, + cover=False, + extrapath=seg_env.PRETRAINED_MODEL_HOME, + extraname=savename, + filename=filename) + pretrained_model = os.path.join(pretrained_model, filename) return pretrained_model From d2f50945d0042076aa7409a693ac9db7f51b5550 Mon Sep 17 00:00:00 2001 From: Sunting78 Date: Fri, 17 Mar 2023 15:25:11 +0800 Subject: [PATCH 2/3] [Bug nranks_download] --- .../portraitnet_eg1800_224x224_46k.yml | 2 +- paddleseg/utils/download.py | 43 ++++++++++++------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/configs/portraitnet/portraitnet_eg1800_224x224_46k.yml b/configs/portraitnet/portraitnet_eg1800_224x224_46k.yml index 70b9277e5e..fd72f6f854 100644 --- a/configs/portraitnet/portraitnet_eg1800_224x224_46k.yml +++ b/configs/portraitnet/portraitnet_eg1800_224x224_46k.yml @@ -68,5 +68,5 @@ model: backbone: type: MobileNetV2_x1_0 pretrained: https://paddleseg.bj.bcebos.com/dygraph/backbone/mobilenetv2_x1_0_ssld.tar.gz - add_edge: True + add_edge: False num_classes: 2 diff --git a/paddleseg/utils/download.py b/paddleseg/utils/download.py index 5d8bf800ac..7403e8f3c9 100644 --- a/paddleseg/utils/download.py +++ b/paddleseg/utils/download.py @@ -146,21 +146,34 @@ def download_file_and_uncompress(url, shutil.rmtree(extraname) full_path = os.path.join(extraname, filename) if filename is not None else extraname + + rank_id_curr_node = int(os.environ.get("PADDLE_RANK_IN_NODE", 0)) + if not os.path.exists( full_path): # If pretrained model exists, skip download process. - if not os.path.exists(savename): - if not os.path.exists(savepath): - _download_file(url, savepath, print_progress) - - if (not tarfile.is_tarfile(savepath)) and ( - not zipfile.is_zipfile(savepath)): - if not os.path.exists(extraname): - os.makedirs(extraname) - shutil.move(savepath, extraname) - return extraname - - savename = _uncompress_file(savepath, extrapath, delete_file, - print_progress) - savename = os.path.join(extrapath, savename) - shutil.move(savename, extraname) + lock_path = extraname + '.download.lock' + with open(lock_path, 'w'): # touch + os.utime(lock_path, None) + if rank_id_curr_node == 0: + if not os.path.exists(savename): + if not os.path.exists(savepath): + _download_file(url, savepath, print_progress) + + if (not tarfile.is_tarfile(savepath)) and ( + not zipfile.is_zipfile(savepath)): + if not os.path.exists(extraname): + os.makedirs(extraname) + + else: + savename = _uncompress_file(savepath, extrapath, + delete_file, print_progress) + savename = os.path.join(extrapath, savename) + + shutil.move(savename, extraname) + os.remove(lock_path) + + else: + while os.path.exists(lock_path): + time.sleep(0.5) + return extraname From eb9aa9e13c9a42b0fa11a6e875f37c464df3360a Mon Sep 17 00:00:00 2001 From: Sunting78 Date: Tue, 4 Apr 2023 20:25:39 +0800 Subject: [PATCH 3/3] [cherry-pick] nranks download --- paddleseg/utils/download.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/paddleseg/utils/download.py b/paddleseg/utils/download.py index 7403e8f3c9..8c184f18b9 100644 --- a/paddleseg/utils/download.py +++ b/paddleseg/utils/download.py @@ -146,9 +146,7 @@ def download_file_and_uncompress(url, shutil.rmtree(extraname) full_path = os.path.join(extraname, filename) if filename is not None else extraname - rank_id_curr_node = int(os.environ.get("PADDLE_RANK_IN_NODE", 0)) - if not os.path.exists( full_path): # If pretrained model exists, skip download process. lock_path = extraname + '.download.lock' @@ -163,13 +161,14 @@ def download_file_and_uncompress(url, not zipfile.is_zipfile(savepath)): if not os.path.exists(extraname): os.makedirs(extraname) + shutil.move(savepath, extraname) else: savename = _uncompress_file(savepath, extrapath, delete_file, print_progress) savename = os.path.join(extrapath, savename) + shutil.move(savename, extraname) - shutil.move(savename, extraname) os.remove(lock_path) else: