Skip to content

Commit 7f4ef6d

Browse files
authored
Fix logs overwriting issue for remote fs (#7889)
* Fix logs overwriting issue for remote fs * Add test
1 parent c310ce6 commit 7f4ef6d

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
@@ -267,14 +267,16 @@ def version(self) -> int:
267267
return self._version
268268

269269
def _get_next_version(self):
270-
root_dir = os.path.join(self.save_dir, self.name)
270+
root_dir = self.root_dir
271271

272-
if not self._fs.isdir(root_dir):
272+
try:
273+
listdir_info = self._fs.listdir(root_dir)
274+
except OSError:
273275
log.warning('Missing logger folder: %s', root_dir)
274276
return 0
275277

276278
existing_versions = []
277-
for listing in self._fs.listdir(root_dir):
279+
for listing in listdir_info:
278280
d = listing["name"]
279281
bn = os.path.basename(d)
280282
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
@@ -340,3 +341,15 @@ def test_tensorboard_with_symlink(log, tmpdir):
340341
_ = logger.version
341342

342343
log.warning.assert_not_called()
344+
345+
346+
def test_tensorboard_missing_folder_warning(tmpdir, caplog):
347+
"""Verify that the logger throws a warning for invalid directory"""
348+
349+
name = "fake_dir"
350+
logger = TensorBoardLogger(save_dir=tmpdir, name=name)
351+
352+
with caplog.at_level(logging.WARNING):
353+
assert logger.version == 0
354+
355+
assert 'Missing logger folder:' in caplog.text

0 commit comments

Comments
 (0)