Weights & Biases handler for MonAI
Features Contributed
-
WandbStatsHandlerdefines a set of Ignite Event-handlers for all the Weights & Biases logging logic. It can be used for any Ignite Engine(trainer, validator, and evaluator) and support both epoch level and iteration level. The expected data source is Igniteengine.state.outputandengine.state.metrics. Default behaviors:- When
EPOCH_COMPLETED, write each dictionary item inengine.state.metricsto Weights & Biases. - When
ITERATION_COMPLETED, write each dictionary item inself.output_transform(engine.state.output)to Weights & Biases.
- When
The following colab notebook and Weights & Biases run demonstrate the usage of these handlers and their results respectively:
Some additional Weights & Biases features:
- When
TensorBoardStatsHandlerandTensorBoardImageHandlerare used inside a wandb run, Weights & Biases automatically hosts the Tensorboard instance inside the run if duringwandb.init(),sync_tensorboardis set toTrue. - When used with
TensorBoardImageHandler, the images and videos are automatically logged to Weights & Biases media panel if duringwandb.init(),sync_tensorboardis set toTrue.
Types of changes
- [x] Non-breaking change (fix or new feature that would not break existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing functionality to change).
- [x] New tests added to cover the changes.
- [ ] Integration tests passed locally by running
./runtests.sh -f -u --net --coverage. - [ ] Quick tests passed locally by running
./runtests.sh --quick --unittests --disttests. - [x] In-line docstrings updated.
- [x] Documentation updated, tested
make htmlcommand in thedocs/folder.
@SachidanandAlle Can help share more concerns about multi-thread running of the hander.
Thanks.
When running with the multithread code shown below, the wandb handler records the thread results into one run as shown in the pic. However, I think several indiviual runs should be created to record different threads.
from __future__ import annotations
import unittest
import wandb
import torch
from concurrent.futures import ThreadPoolExecutor
from ignite.engine import Engine
from monai.handlers import WandbStatsHandler
def dummy_train(start):
# set up engine
def _train_func(engine, batch):
return batch + 1.0
engine = Engine(_train_func)
# set up testing handler
handler = WandbStatsHandler(
output_transform=lambda x: x,
)
handler.attach(engine)
engine.run(torch.tensor([start]), max_epochs=5)
class TestHandlerWB(unittest.TestCase):
def test_multi_thread(self):
wandb.init(
project="multithread-handlers", save_code=True, sync_tensorboard=True
)
with ThreadPoolExecutor(2, "Training") as executor:
for t in range(2):
executor.submit(dummy_train, t + 2)
if __name__ == "__main__":
unittest.main()
Hi @soumik12345 ,
Do you still plan to complete this PR?
Thanks.
Hi @soumik12345 ,
Do you still plan to complete this PR?
Thanks.
Hi @Nic-Ma I will be completing this PR soon, thanks for being patient :)