Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logs overwriting issue for remote fs #7889

Merged
merged 2 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pytorch_lightning/loggers/tensorboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,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 @@ -340,3 +341,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