From 7351eb4b612c181e946412aee007bcb982771e04 Mon Sep 17 00:00:00 2001 From: wozeparrot Date: Thu, 25 May 2023 23:46:02 -0400 Subject: [PATCH] feat: put temperary file in the same directory as the destination file (#805) --- extra/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extra/utils.py b/extra/utils.py index 535bf904b7..ae1e505fbd 100644 --- a/extra/utils.py +++ b/extra/utils.py @@ -21,18 +21,19 @@ def fetch(url): return f.read() def download_file(url, fp, skip_if_exists=True): - import requests, os + import requests, os, pathlib if skip_if_exists and os.path.isfile(fp) and os.stat(fp).st_size > 0: return r = requests.get(url, stream=True) assert r.status_code == 200 progress_bar = tqdm(total=int(r.headers.get('content-length', 0)), unit='B', unit_scale=True, desc=url) - with tempfile.NamedTemporaryFile(delete=False) as f: + with tempfile.NamedTemporaryFile(dir=pathlib.Path(fp).parent, delete=False) as f: for chunk in r.iter_content(chunk_size=16384): progress_bar.update(f.write(chunk)) f.close() os.rename(f.name, fp) + def my_unpickle(fb0): key_prelookup = defaultdict(list) def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks, metadata=None):