Skip to content

Commit 8bcb82d

Browse files
tshu-wBorda
authored andcommitted
Fixed WandbLogger save_dir is not set after creation (#12748) (#14326)
Co-authored-by: Jirka Borovec <[email protected]>
1 parent 2c4bd75 commit 8bcb82d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/pytorch_lightning/loggers/wandb.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def __init__(self, *args, **kwarg):
223223
224224
Args:
225225
name: Display name for the run.
226-
save_dir: Path where data is saved (wandb dir by default).
226+
save_dir: Path where data is saved.
227227
offline: Run offline (data can be streamed later to wandb servers).
228228
id: Sets the version, mainly used to resume a previous run.
229229
version: Same as id.
@@ -255,7 +255,7 @@ def __init__(self, *args, **kwarg):
255255
def __init__(
256256
self,
257257
name: Optional[str] = None,
258-
save_dir: Optional[str] = None,
258+
save_dir: str = ".",
259259
offline: bool = False,
260260
id: Optional[str] = None,
261261
anonymous: Optional[bool] = None,
@@ -300,7 +300,7 @@ def __init__(
300300
name=name,
301301
project=project,
302302
id=version or id,
303-
dir=save_dir,
303+
dir=save_dir or kwargs.pop("dir"),
304304
resume="allow",
305305
anonymous=("allow" if anonymous else None),
306306
)

tests/tests_pytorch/loggers/test_wandb.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ def test_wandb_logger_init(wandb, monkeypatch):
5858
wandb.init.reset_mock()
5959
WandbLogger(project="test_project").experiment
6060
wandb.init.assert_called_once_with(
61-
name=None, dir=None, id=None, project="test_project", resume="allow", anonymous=None
61+
name=None, dir=".", id=None, project="test_project", resume="allow", anonymous=None
6262
)
6363

64+
# test wandb.init set save_dir correctly after created
65+
wandb.run = None
66+
wandb.init.reset_mock()
67+
logger = WandbLogger(project="test_project")
68+
assert logger.save_dir is not None
69+
6470
# test wandb.init and setting logger experiment externally
6571
wandb.run = None
6672
run = wandb.init()

0 commit comments

Comments
 (0)