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

Cleanup fetch_file_cached() operations in the download model #44

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 15 additions & 4 deletions point_e/models/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import requests
import torch
import shutil
from filelock import FileLock
from tqdm.auto import tqdm

Expand Down Expand Up @@ -39,26 +40,36 @@ def fetch_file_cached(
"""
if cache_dir is None:
cache_dir = default_cache_dir()

os.makedirs(cache_dir, exist_ok=True)
local_path = os.path.join(cache_dir, url.split("/")[-1])

if os.path.exists(local_path):
return local_path

response = requests.get(url, stream=True)
size = int(response.headers.get("content-length", "0"))

with FileLock(local_path + ".lock"):
if progress:
pbar = tqdm(total=size, unit="iB", unit_scale=True)

tmp_path = local_path + ".tmp"

with open(tmp_path, "wb") as f:
for chunk in response.iter_content(chunk_size):
if progress:
pbar.update(len(chunk))
f.write(chunk)
os.rename(tmp_path, local_path)
if progress:
pbar.close()
return local_path

shutil.copyfile(tmp_path, local_path)

os.remove(tmp_path)

if progress:
pbar.close()

return local_path


def load_checkpoint(
Expand Down