Integrating 3LC with PyTorch Lightning#
PyTorch Lightning users have the flexibility to integrate with 3LC within their Lightning modules manually, allowing for fine-tuned control over dataset registration and metrics collection. However, for those seeking a more streamlined approach, 3LC offers a simple yet powerful module decorator. This decorator automatically registers datasets and facilitates the collection of metrics directly from PyTorch Lightning modules and trainers. Here is an example demonstrating how to use this feature:
import pytorch_lightning as pl
import tlc
@tlc.lightning_module(
project_name=...,
run_name=...,
dataset_prefix=...,
metrics_collectors=...,
)
class MyLightningModule(pl.LightningModule):
"""Your PyTorch Lightning module definition.
Should include dataloader setup, training logic, etc.
The `tlc.lightning_module` decorator will automatically register datasets and collect metrics during training.
See the module documentation for more information.
"""
...
module = MyLightningModule()
trainer = pl.Trainer(max_epochs=10)
trainer.fit(module)
This example illustrates the ease with which 3LC can be incorporated into your PyTorch Lightning workflow, enhancing your project’s efficiency and insight into your models’ training and evaluation phases.