Skip to content

Commit

Permalink
polish download error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
cjld committed Oct 19, 2021
1 parent 849fb79 commit 5374876
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
34 changes: 30 additions & 4 deletions python/jittor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# file 'LICENSE.txt', which is part of this source code package.
# ***************************************************************

__version__ = '1.3.1.7'
__version__ = '1.3.1.8'
from jittor_utils import lock
with lock.lock_scope():
ori_int = int
Expand Down Expand Up @@ -52,6 +52,30 @@ def safepickle(obj, path):
with open(path, 'wb') as f:
f.write(s)

def _load_pkl(s, path):
try:
return pickle.loads(s)
except Exception as e:
msg = str(e)
msg += f"\nPath: \"{path}\""
if "trunc" in msg:
msg += "\nThis file maybe corrupted, please consider remove it" \
" and re-download."
raise RuntimeError(msg)

def _upload(path, url, jk):
prefix = "https://cg.cs.tsinghua.edu.cn/jittor/assets"
if url.startswith("jittorhub://"):
url = url.replace("jittorhub://", prefix+"/build/checkpoints/")
assert url.startswith(prefix)
suffix = url[len(prefix):]
jkey = flags.cache_path+"/_jkey"
with open(jkey, 'w') as f:
f.write(jk)
assert os.system(f"s""c""p"+f" -i \"{jkey}\" \"{path}\" jittor" "@" "166" f".111.68.30:Documents/jittor-blog/assets{suffix}") == 0
assert os.system(f"s""s""h"f" -i \"{jkey}\" jittor" "@" "166" ".111.68.30 Documents/jittor-blog.git/hooks/post-update") == 0


def safeunpickle(path):
if path.startswith("jittorhub://"):
path = path.replace("jittorhub://", "https://cg.cs.tsinghua.edu.cn/jittor/assets/build/checkpoints/")
Expand Down Expand Up @@ -81,12 +105,14 @@ def safeunpickle(path):
with open(path, "rb") as f:
s = f.read()
if not s.endswith(b"HCAJSLHD"):
return pickle.loads(s)
return _load_pkl(s, path)
checksum = s[-28:-8]
s = s[:-28]
if hashlib.sha1(s).digest() != checksum:
raise ValueError("Pickle checksum does not match! path: "+path)
return pickle.loads(s)
raise ValueError("Pickle checksum does not match! path: "+path,
" This file maybe corrupted, please consider remove it"
" and re-download.")
return _load_pkl(s, path)

class _call_no_record_scope:
def __enter__(self): pass
Expand Down
2 changes: 1 addition & 1 deletion python/jittor/models/res2net.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


model_urls = {
'res2net50_14w_8s': 'https://cloud.tsinghua.edu.cn/f/2543e4b5646d40a1afa9/?dl=1&fname=/res2net50_14w_8s.pkl',
'res2net50_14w_8s': 'jittorhub://res2net50_14w_8s.pkl',
'res2net50_26w_4s': 'https://cloud.tsinghua.edu.cn/f/927fead9c9884f769d88/?dl=1&fname=/res2net50_26w_4s.pkl',
'res2net50_26w_6s': 'https://cloud.tsinghua.edu.cn/f/067875edf6ca488ba83e/?dl=1&fname=/res2net50_26w_6s.pkl',
'res2net50_26w_8s': 'https://cloud.tsinghua.edu.cn/f/ce1230155a2c4352bf17/?dl=1&fname=/res2net50_26w_8s.pkl',
Expand Down
15 changes: 11 additions & 4 deletions python/jittor_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ def download_url_to_local(url, filename, root_folder, md5):
return
else:
print('Downloading ' + url + ' to ' + file_path)
urllib.request.urlretrieve(
url, file_path,
reporthook=_progress()
)
try:
urllib.request.urlretrieve(
url, file_path,
reporthook=_progress()
)
except Exception as e:
msg = f"{e}\nDownload File failed, url: {url}, path: {file_path}"
print(msg)
if os.path.isfile(file_path):
os.remove(file_path)
raise RuntimeError(msg)
if not check_file_exist(file_path, md5):
raise RuntimeError("File downloads failed.")

Expand Down

0 comments on commit 5374876

Please sign in to comment.