-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
from os import PathLike | ||
|
||
from pytorch_lightning.callbacks import Callback | ||
|
||
from wandb_osh.hooks import TriggerWandbSyncHook, _comm_default_dir | ||
|
||
|
||
class TriggerWandbSyncLightningCallback(Callback): | ||
def __init__(self, communication_dir: PathLike = _comm_default_dir): | ||
"""Hook to be used when interfacing wandb with pytorch lightning. | ||
Args: | ||
communication_dir: Directory used for communication with wandb-osh. | ||
Usage | ||
.. code-block:: python | ||
from wandb_osh.lightning_hooks import TriggerWandbSyncLightningCallback | ||
trainer = Trainer(callbacks=[TriggerWandbSyncLightningCallback()]) | ||
""" | ||
super().__init__() | ||
self._hook = TriggerWandbSyncHook(communication_dir=communication_dir) | ||
|
||
def on_validation_epoch_end( | ||
self, | ||
*args, | ||
): | ||
self._hook() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
|
||
from wandb_osh.util.log import logger | ||
|
||
logger.setLevel(logging.DEBUG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from __future__ import annotations | ||
|
||
import wandb | ||
|
||
from wandb_osh.lightning_hooks import TriggerWandbSyncLightningCallback | ||
|
||
|
||
def test_manual_trigger(tmp_path): | ||
wandb.init(project="test", mode="offline", dir=tmp_path) | ||
lh = TriggerWandbSyncLightningCallback(tmp_path) | ||
lh.on_validation_epoch_end(None, None) # type: ignore | ||
assert len([f for f in tmp_path.iterdir() if f.suffix == ".command"]) == 1 |