Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit 5a622f4

Browse files
QuentinDuvalfacebook-github-bot
authored andcommitted
Conversion to sliced checkpoints now supports PathManager (#387)
Summary: Pull Request resolved: #387 The sliced were not created at the right place because of os.path.abspath Reviewed By: iseessel Differential Revision: D30109789 fbshipit-source-id: c332fbf5f5c52241a537bd1188e3268a2f5cb966
1 parent 3660267 commit 5a622f4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

vissl/utils/checkpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from fvcore.common.file_io import PathManager
2121
from vissl.config import AttrDict
2222
from vissl.utils.env import get_machine_local_and_dist_rank
23-
from vissl.utils.io import create_file_symlink, makedir
23+
from vissl.utils.io import abspath, create_file_symlink, makedir
2424
from vissl.utils.layer_memory_tracking import null_context
2525

2626

@@ -353,10 +353,10 @@ def save_slice(cls, checkpoint_path: str, param_path: str, param) -> str:
353353
- return the created file name
354354
"""
355355
checkpoint_sub_folder = os.path.splitext(checkpoint_path)[0] + "_layers"
356-
os.makedirs(checkpoint_sub_folder, exist_ok=True)
356+
makedir(checkpoint_sub_folder)
357357
hash_name = hashlib.sha1(param_path.encode()).hexdigest()
358-
file_path = os.path.join(f"{checkpoint_sub_folder}", f"{hash_name}.torch")
359-
file_path = os.path.abspath(file_path)
358+
file_path = os.path.join(checkpoint_sub_folder, f"{hash_name}.torch")
359+
file_path = abspath(file_path)
360360
checkpoint_slice = {"type": CheckpointItemType.slice.name, "weight": param}
361361
with PathManager.open(file_path, "wb") as f:
362362
torch.save(checkpoint_slice, f)

vissl/utils/io.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ def load_file(filename, mmap_mode=None):
129129
return data
130130

131131

132+
def abspath(resource_path: str):
133+
"""
134+
Make a path absolute, but take into account prefixes like
135+
"http://" or "manifold://"
136+
"""
137+
regex = re.compile(r"^\w+://")
138+
if regex.match(resource_path) is None:
139+
return os.path.abspath(resource_path)
140+
else:
141+
return resource_path
142+
143+
132144
def makedir(dir_path):
133145
"""
134146
Create the directory if it does not exist.

0 commit comments

Comments
 (0)