Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] nranks bug of download #3126

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/portraitnet/portraitnet_eg1800_224x224_46k.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
42 changes: 27 additions & 15 deletions paddleseg/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,33 @@ 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)
shutil.move(savepath, 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
18 changes: 8 additions & 10 deletions paddleseg/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import os
import contextlib
import filelock
import tempfile
import random
from urllib.parse import urlparse, unquote
Expand Down Expand Up @@ -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


Expand Down