Skip to content

Commit 80ffc03

Browse files
kaushikb11lexierule
authored andcommitted
Fix logs overwriting issue for remote fs (#7889)
* Fix logs overwriting issue for remote fs * Add test
1 parent 09efc25 commit 80ffc03

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

pytorch_lightning/loggers/tensorboard.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,16 @@ def version(self) -> int:
254254
return self._version
255255

256256
def _get_next_version(self):
257-
root_dir = os.path.join(self.save_dir, self.name)
257+
root_dir = self.root_dir
258258

259-
if not self._fs.isdir(root_dir):
259+
try:
260+
listdir_info = self._fs.listdir(root_dir)
261+
except OSError:
260262
log.warning('Missing logger folder: %s', root_dir)
261263
return 0
262264

263265
existing_versions = []
264-
for listing in self._fs.listdir(root_dir):
266+
for listing in listdir_info:
265267
d = listing["name"]
266268
bn = os.path.basename(d)
267269
if self._fs.isdir(d) and bn.startswith("version_"):

tests/loggers/test_tensorboard.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import logging
1415
import os
1516
from argparse import Namespace
1617
from unittest import mock
@@ -320,3 +321,15 @@ def test_tensorboard_with_symlink(log, tmpdir):
320321
_ = logger.version
321322

322323
log.warning.assert_not_called()
324+
325+
326+
def test_tensorboard_missing_folder_warning(tmpdir, caplog):
327+
"""Verify that the logger throws a warning for invalid directory"""
328+
329+
name = "fake_dir"
330+
logger = TensorBoardLogger(save_dir=tmpdir, name=name)
331+
332+
with caplog.at_level(logging.WARNING):
333+
assert logger.version == 0
334+
335+
assert 'Missing logger folder:' in caplog.text

0 commit comments

Comments
 (0)