... | @@ -65,5 +65,33 @@ for epoch in range(num_epochs): |
... | @@ -65,5 +65,33 @@ for epoch in range(num_epochs): |
|
```
|
|
```
|
|
|
|
|
|
## PyTorch Lightning Integration Example
|
|
## PyTorch Lightning Integration Example
|
|
|
|
**Step 1: Import W&B logger**
|
|
|
|
|
|
## Uploading Model Checkpoints to W&B |
|
```python
|
|
\ No newline at end of file |
|
from lightning.pytorch.loggers import WandbLogger
|
|
|
|
```
|
|
|
|
|
|
|
|
**Step 2: Initialize W&B logger**
|
|
|
|
|
|
|
|
- Instantiate the `WandbLogger` and pass it to Lightning's `Trainer`. Make sure to save data locally during training by setting the mode to `offline`
|
|
|
|
|
|
|
|
```python
|
|
|
|
wandb_logger = WandbLogger(project="my_project", entity="my_entity", mode="offline")
|
|
|
|
trainer = lightning.Trainer(**config["trainer"],
|
|
|
|
logger=wandb_logger)
|
|
|
|
```
|
|
|
|
|
|
|
|
**Step 3: Training Step**
|
|
|
|
|
|
|
|
```python
|
|
|
|
def training_step(self, batch, batch_idx):
|
|
|
|
data, target = batch
|
|
|
|
output = self.forward(data)
|
|
|
|
loss = criterion(output, target)
|
|
|
|
# Log training metrics to W&B
|
|
|
|
self.log("train/loss", loss, on_step=False, on_epoch=True)
|
|
|
|
return loss
|
|
|
|
```
|
|
|
|
|
|
|
|
## Model Checkpointing using W&B
|
|
|
|
[TBD] |
|
|
|
\ No newline at end of file |