Skip to content

Commit 633946d

Browse files
committed
fix: optional tensorboard dependency
1 parent cf07b34 commit 633946d

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lantern/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from lantern.set_seeds import set_seeds
1515
from lantern.worker_init_fn import worker_init_fn
1616
from lantern.progress_bar import ProgressBar
17-
from lantern.early_stopping import EarlyStopping
17+
18+
try:
19+
from lantern.early_stopping import EarlyStopping
20+
except ImportError:
21+
pass
1822
from lantern.git_info import git_info
1923

2024
from pkg_resources import get_distribution, DistributionNotFound

lantern/early_stopping.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
import torch.utils.tensorboard
21
from typing import Optional
32

43
from lantern import FunctionalBase
54

5+
try:
6+
import torch.utils.tensorboard
7+
8+
SummaryWriter = torch.utils.tensorboard.SummaryWriter
9+
except ImportError:
10+
SummaryWriter = None
11+
pass
12+
613

714
class EarlyStopping(FunctionalBase):
815
"""Keeps track of the best score and how long ago it was calculated."""
916

10-
tensorboard_logger: torch.utils.tensorboard.SummaryWriter
17+
tensorboard_logger: SummaryWriter
1118
best_score: Optional[float] = None
1219
scores_since_improvement: int = -1
1320

0 commit comments

Comments
 (0)