Skip to content

Commit

Permalink
Fix logs overwriting issue for remote fs (#7889)
Browse files Browse the repository at this point in the history
* Fix logs overwriting issue for remote fs

* Add test
  • Loading branch information
kaushikb11 authored and lexierule committed Jun 17, 2021
1 parent 09efc25 commit 80ffc03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pytorch_lightning/loggers/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,16 @@ def version(self) -> int:
return self._version

def _get_next_version(self):
root_dir = os.path.join(self.save_dir, self.name)
root_dir = self.root_dir

if not self._fs.isdir(root_dir):
try:
listdir_info = self._fs.listdir(root_dir)
except OSError:
log.warning('Missing logger folder: %s', root_dir)
return 0

existing_versions = []
for listing in self._fs.listdir(root_dir):
for listing in listdir_info:
d = listing["name"]
bn = os.path.basename(d)
if self._fs.isdir(d) and bn.startswith("version_"):
Expand Down
13 changes: 13 additions & 0 deletions tests/loggers/test_tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import os
from argparse import Namespace
from unittest import mock
Expand Down Expand Up @@ -320,3 +321,15 @@ def test_tensorboard_with_symlink(log, tmpdir):
_ = logger.version

log.warning.assert_not_called()


def test_tensorboard_missing_folder_warning(tmpdir, caplog):
"""Verify that the logger throws a warning for invalid directory"""

name = "fake_dir"
logger = TensorBoardLogger(save_dir=tmpdir, name=name)

with caplog.at_level(logging.WARNING):
assert logger.version == 0

assert 'Missing logger folder:' in caplog.text

0 comments on commit 80ffc03

Please sign in to comment.