> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wandb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> Fine-tune Cohere models with W&B experiment tracking to log training metrics and monitor model performance.

# Cohere fine-tuning

With W\&B, you can log your Cohere model's fine-tuning metrics and configuration to analyze your model performance and share results with your colleagues. Connect a Cohere fine-tuning run to a W\&B project, and W\&B automatically captures training and validation metrics, hyperparameters, and run metadata in your workspace. Use this guide if you are already fine-tuning Cohere models and want centralized experiment tracking.

For a full example of how to start a fine-tuning run, see the [Cohere fine-tuning guide](https://docs.cohere.com/page/convfinqa-finetuning-wandb), and refer to the [Cohere API reference for the `wandb` setting](https://docs.cohere.com/reference/createfinetunedmodel#request.body.settings.wandb).

## Log Cohere fine-tuning results

To add Cohere fine-tuning logging to your W\&B workspace, do the following:

1. Create a `WandbConfig` with your W\&B API key, W\&B `entity`, and `project` name. The API key authenticates the Cohere job with W\&B, and the entity and project determine where W\&B logs your runs. Create an API key in your [W\&B user settings](https://wandb.ai/settings). Replace `<wandb-api-key>` in the following example with your API key.

2. Pass this config to the `FinetunedModel` object along with your model name, dataset, and hyperparameters to start your fine-tuning run. The `wandb` setting configures Cohere to stream metrics to your W\&B project during the run.

   ```python theme={null}
   from cohere.finetuning import WandbConfig, FinetunedModel

   # create a config with your W&B details
   wandb_ft_config = WandbConfig(
       api_key="<wandb-api-key>",
       entity="my-entity", # must be a valid entity associated with the provided API key
       project="cohere-ft",
   )

   ...  # set up your datasets and hyperparameters

   # start a fine-tuning run on cohere
   cmd_r_finetune = co.finetuning.create_finetuned_model(
     request=FinetunedModel(
       name="command-r-ft",
       settings=Settings(
         base_model=...
         dataset_id=...
         hyperparameters=...
         wandb=wandb_ft_config  # pass your W&B config here
       ),
     ),
   )
   ```

3. View your model's fine-tuning training and validation metrics and hyperparameters in the W\&B project that you created.

   <Frame>
     <img src="https://mintcdn.com/wb-21fd5541/mVjDwbx0mC8gYx-b/images/integrations/cohere_ft.png?fit=max&auto=format&n=mVjDwbx0mC8gYx-b&q=85&s=c21d1f2b47e67f741523bc9c9f157b19" alt="Cohere fine-tuning dashboard" width="2180" height="586" data-path="images/integrations/cohere_ft.png" />
   </Frame>

After the run starts, your Cohere fine-tuning job reports metrics to W\&B in real time, giving you a single place to compare runs and inspect training progress.

## Organize runs

W\&B organizes your runs automatically. You can filter and sort them by any configuration parameter such as job type, base model, learning rate, and any other hyperparameter.

You can also rename your runs, add notes, or create tags to group them.

## Resources

For a complete example, see the [Cohere fine-tuning example notebook](https://github.com/cohere-ai/notebooks/blob/kkt_ft_cookbooks/notebooks/finetuning/convfinqa_finetuning_wandb.ipynb).
