> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-hivemind-launch.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# fastai v1

> Use the W&B callback with fastai v1 to log model topology, losses, metrics, weights, gradients, and predictions.

<Note>
  This documentation is for fastai v1.
  If you use the current version of fastai, you should refer to [fastai page](../).
</Note>

For scripts using fastai v1, we have a callback that can automatically log model topology, losses, metrics, weights, gradients, sample predictions and best trained model.

```python theme={null}
import wandb
from wandb.fastai import WandbCallback

wandb.init()

learn = cnn_learner(data, model, callback_fns=WandbCallback)
learn.fit(epochs)
```

Requested logged data is configurable through the callback constructor.

```python theme={null}
from functools import partial

learn = cnn_learner(
    data, model, callback_fns=partial(WandbCallback, input_type="images")
)
```

It is also possible to use WandbCallback only when starting training. In this case it must be instantiated.

```python theme={null}
learn.fit(epochs, callbacks=WandbCallback(learn))
```

Custom parameters can also be given at that stage.

```python theme={null}
learn.fit(epochs, callbacks=WandbCallback(learn, input_type="images"))
```

## Example code

We've created a few examples for you to see how the integration works:

**Fastai v1**

* [Classify Simpsons characters](https://github.com/borisdayma/simpsons-fastai)[: ](https://app.wandb.ai/jxmorris12/huggingface-demo/reports/A-Step-by-Step-Guide-to-Tracking-Hugging-Face-Model-Performance--VmlldzoxMDE2MTU)A simple demo to track and compare Fastai models
* [Semantic Segmentation with Fastai](https://github.com/borisdayma/semantic-segmentation): Optimize neural networks on self-driving cars

## Options

`WandbCallback()` class supports a number of options:

| Keyword argument | Default   | Description                                                                                                |
| ---------------- | --------- | ---------------------------------------------------------------------------------------------------------- |
| learn            | N/A       | the fast.ai learner to hook.                                                                               |
| save\_model      | True      | save the model if it's improved at each step. It will also load best model at the end of training.         |
| mode             | auto      | `min`, `max`, or `auto`: How to compare the training metric specified in `monitor` between steps.          |
| monitor          | None      | training metric used to measure performance for saving the best model. None defaults to validation loss.   |
| log              | gradients | `gradients`, `parameters`, `all`, or None. Losses & metrics are always logged.                             |
| input\_type      | None      | `images` or `None`. Used to display sample predictions.                                                    |
| validation\_data | None      | data used for sample predictions if `input_type` is set.                                                   |
| predictions      | 36        | number of predictions to make if `input_type` is set and `validation_data` is `None`.                      |
| seed             | 12345     | initialize random generator for sample predictions if `input_type` is set and `validation_data` is `None`. |
