|
| 1 | +################## |
| 2 | +Weights and Biases |
| 3 | +################## |
| 4 | + |
| 5 | +`Weights & Biases (W&B) <https://wandb.ai>`_ allows machine learning practitioners to track experiments, visualize data, and share insights with a few lines of code. |
| 6 | + |
| 7 | +It integrates seamlessly with your Lightning ML workflows to log metrics, output visualizations, and manage artifacts. |
| 8 | +This integration provides a simple way to log metrics and artifacts from your Fabric training loop to W&B via the ``WandbLogger``. |
| 9 | +The ``WandbLogger`` also supports all features of the Weights and Biases library, such as logging rich media (image, audio, video), artifacts, hyperparameters, tables, custom visualizations, and more. |
| 10 | +`Check the official documentation here <https://docs.wandb.ai>`_. |
| 11 | + |
| 12 | + |
| 13 | +---- |
| 14 | + |
| 15 | + |
| 16 | +************************* |
| 17 | +Set Up Weights and Biases |
| 18 | +************************* |
| 19 | + |
| 20 | +First, you need to install the ``wandb`` package: |
| 21 | + |
| 22 | +.. code-block:: bash |
| 23 | +
|
| 24 | + pip install wandb |
| 25 | +
|
| 26 | +Then log in with your API key found in your W&B account settings: |
| 27 | + |
| 28 | +.. code-block:: bash |
| 29 | +
|
| 30 | + wandb login <your-api-key> |
| 31 | +
|
| 32 | +
|
| 33 | +You are all set and can start logging your metrics to Weights and Biases. |
| 34 | + |
| 35 | + |
| 36 | +---- |
| 37 | + |
| 38 | + |
| 39 | +************* |
| 40 | +Track metrics |
| 41 | +************* |
| 42 | + |
| 43 | +To start tracking metrics in your training loop, import the WandbLogger and configure it with your settings: |
| 44 | + |
| 45 | +.. code-block:: python |
| 46 | +
|
| 47 | + from lightning.fabric import Fabric |
| 48 | +
|
| 49 | + # 1. Import the WandbLogger |
| 50 | + from wandb.integration.lightning.fabric import WandbLogger |
| 51 | +
|
| 52 | + # 2. Configure the logger |
| 53 | + logger = WandbLogger(project="my-project") |
| 54 | +
|
| 55 | + # 3. Pass it to Fabric |
| 56 | + fabric = Fabric(loggers=logger) |
| 57 | +
|
| 58 | +
|
| 59 | +Next, add :meth:`~lightning.fabric.fabric.Fabric.log` calls in your code. |
| 60 | + |
| 61 | +.. code-block:: python |
| 62 | +
|
| 63 | + value = ... # Python scalar or tensor scalar |
| 64 | + fabric.log("some_value", value) |
| 65 | +
|
| 66 | +
|
| 67 | +To log multiple metrics at once, use :meth:`~lightning.fabric.fabric.Fabric.log_dict`: |
| 68 | + |
| 69 | +.. code-block:: python |
| 70 | +
|
| 71 | + values = {"loss": loss, "acc": acc, "other": other} |
| 72 | + fabric.log_dict(values) |
| 73 | +
|
| 74 | +
|
| 75 | +---- |
| 76 | + |
| 77 | + |
| 78 | +************************************************** |
| 79 | +Logging media, artifacts, hyperparameters and more |
| 80 | +************************************************** |
| 81 | + |
| 82 | +With ``WandbLogger`` you can also log images, text, tables, checkpoints, hyperparameters and more. |
| 83 | +For a description of all features, check out the official Weights and Biases documentation and examples. |
| 84 | + |
| 85 | + |
| 86 | +.. raw:: html |
| 87 | + |
| 88 | + <div class="display-card-container"> |
| 89 | + <div class="row"> |
| 90 | + |
| 91 | +.. displayitem:: |
| 92 | + :header: Official WandbLogger Lightning and Fabric Documentation |
| 93 | + :description: Learn about all features from Weights and Biases |
| 94 | + :button_link: https://docs.wandb.ai/guides/integrations/lightning |
| 95 | + :col_css: col-md-4 |
| 96 | + :height: 150 |
| 97 | + |
| 98 | +.. displayitem:: |
| 99 | + :header: Fabric WandbLogger Example |
| 100 | + :description: Official example of how to use the WandbLogger with Fabric |
| 101 | + :button_link: https://colab.research.google.com/github/wandb/examples/blob/master/colabs/pytorch-lightning/Track_PyTorch_Lightning_with_Fabric_and_Wandb.ipynb |
| 102 | + :col_css: col-md-4 |
| 103 | + :height: 150 |
| 104 | + |
| 105 | +.. displayitem:: |
| 106 | + :header: Lightning WandbLogger Example |
| 107 | + :description: Official example of how to use the WandbLogger with Lightning |
| 108 | + :button_link: wandb.me/lightning |
| 109 | + :col_css: col-md-4 |
| 110 | + :height: 150 |
| 111 | + |
| 112 | + |
| 113 | +.. raw:: html |
| 114 | + |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + |
| 118 | + |
| 119 | +| |
| 120 | +| |
0 commit comments