-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: (#2164)
commit 29fb0506cd38a15c359e369cc8bc4435916b0c78 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 19:35:30 2020 +0000 fix checking for version for docs to build commit 467fd64 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 18:56:05 2020 +0000 remove no local test commit a7cc9f8 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 18:46:44 2020 +0000 fix commit 3fdbb72 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 18:23:30 2020 +0000 revert requirements commit 9b8686b Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 18:16:42 2020 +0000 make it a fixture commit eec7495 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 18:01:32 2020 +0000 fix up the testing commit 896d94a Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 17:47:28 2020 +0000 fix some tests commit 6d22bde Merge: 6175d4e 6ebe0d7 Author: Brendan Fahy <[email protected]> Date: Sat Aug 8 10:20:47 2020 +0000 Merge remote-tracking branch 'origin/master' into tb_use_gfile commit 6175d4e Author: Brendan Fahy <[email protected]> Date: Fri Aug 7 10:16:36 2020 +0000 Use tensorboard.compat.gfile to support remote writing
- Loading branch information
Showing
6 changed files
with
111 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,65 @@ | ||
import sys | ||
import os | ||
from typing import Union | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
|
||
import torch | ||
|
||
import tensorboard | ||
from packaging import version | ||
from pytorch_lightning import _logger as log | ||
|
||
# we want this for tf.io.gfile, which if tf is installed gives full tf, | ||
# otherwise gives a pruned down version which works for some file backends but | ||
# not all | ||
from tensorboard.compat import tf | ||
|
||
gfile = tf.io.gfile | ||
|
||
pathlike = Union[Path, str] | ||
|
||
# older version of tensorboard had buggy gfile compatibility layers | ||
# only support remote cloud paths if newer | ||
|
||
|
||
def load(path_or_url: str, map_location=None): | ||
if urlparse(path_or_url).scheme == '' or Path(path_or_url).drive: # no scheme or with a drive letter | ||
return torch.load(path_or_url, map_location=map_location) | ||
else: | ||
return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location) | ||
return torch.hub.load_state_dict_from_url(path_or_url, map_location=map_location) | ||
|
||
|
||
def modern_gfile(): | ||
"""Check the version number of tensorboard. | ||
Cheking to see if it has the gfile compatibility layers needed for remote | ||
file operations | ||
""" | ||
tb_version = version.parse(tensorboard.version.VERSION) | ||
modern_gfile = tb_version >= version.parse('2.0') | ||
|
||
|
||
def cloud_open(path: pathlike, mode: str, newline:str = None): | ||
if sys.platform == "win32": | ||
log.debug( | ||
"gfile does not handle newlines correctly on windows so remote files are not" | ||
"supported falling back to normal local file open." | ||
) | ||
return open(path, mode, newline=newline) | ||
if not modern_gfile(): | ||
log.debug( | ||
"tenosrboard.compat gfile does not work on older versions " | ||
"of tensorboard for remote files, using normal local file open." | ||
) | ||
return open(path, mode, newline=newline) | ||
try: | ||
return gfile.GFile(path, mode) | ||
except NotImplementedError as e: | ||
# minimal dependencies are installed and only local files will work | ||
return open(path, mode, newline=newline) | ||
|
||
|
||
def makedirs(path: pathlike): | ||
if hasattr(gfile, "makedirs") and modern_gfile(): | ||
return gfile.makedirs(str(path)) | ||
# otherwise minimal dependencies are installed and only local files will work | ||
return os.makedirs(path, exist_ok=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters