Skip to main content
This page shows you how to log your OpenAI GPT-3.5 or GPT-4 model’s fine-tuning metrics and configuration to W&B. By integrating W&B with OpenAI’s fine-tuning API, you can track your fine-tuning experiments, models, and datasets in one place and share results with your colleagues. Use this integration when you fine-tune OpenAI models and want centralized experiment tracking and version control over the training data and resulting models.
See the OpenAI documentation for a list of models that you can fine-tune.
See the W&B Integration section in the OpenAI documentation for supplemental information on how to integrate W&B with OpenAI for fine-tuning.

Install or update OpenAI Python API

Before you sync fine-tuning results, make sure you have a compatible version of the OpenAI Python client installed. The W&B OpenAI fine-tuning integration works with OpenAI version 1.0 or later. See the PyPI documentation for the latest version of the OpenAI Python API library. To install the OpenAI Python API, run:
If you already have the OpenAI Python API installed, update it with:

Sync your OpenAI fine-tuning results

This section shows you how to send the metrics and configuration from an OpenAI fine-tuning job to W&B so you can review them alongside your other experiments. To do this, use the WandbLogger class from the wandb.integration.openai.fine_tuning module.
OpenAI auto-scan feature

Sync your fine-tunes

Sync your results from your script. The following example shows both the minimal one-line call and the full set of optional parameters you can pass to control how the sync behaves.

Reference

The following table describes each argument accepted by WandbLogger.sync.

Dataset versioning and visualization

When you sync a fine-tuning job, W&B also captures the training and validation data so you can version it and explore it interactively. The following subsections describe what W&B tracks and how to view it.

Versioning

The training and validation data that you upload to OpenAI for fine-tuning are automatically logged as W&B Artifacts for easier version control. The following image shows a view of the training file in Artifacts. You can see the W&B run that logged this file, when it was logged, the version of the dataset, the metadata, and DAG lineage from the training data to the trained model.
W&B Artifacts with training datasets

Visualization

W&B visualizes the datasets as W&B Tables, which lets you explore, search, and interact with the dataset. The following image shows training samples visualized in W&B Tables.
OpenAI data

The fine-tuned model and model versioning

OpenAI doesn’t expose the underlying weights of a fine-tuned model, so W&B tracks the model by capturing its metadata instead. OpenAI gives you an ID of the fine-tuned model. Since you don’t have access to the model weights, the WandbLogger creates a model_metadata.json file with all the details (hyperparameters, data file IDs, and so on) of the model along with the fine_tuned_model ID, and logs it as a W&B Artifact. You can link this model (metadata) artifact to a model in the W&B Registry.
OpenAI model metadata

Frequently asked questions

The following sections answer common questions about sharing, organizing, and recovering fine-tuning runs synced from OpenAI.

Share fine-tune results with your team

Log your fine-tune jobs to your team account with:

Organize your runs

W&B automatically organizes your runs. You can filter and sort them based on any configuration parameter such as job type, base model, learning rate, training filename, and any other hyperparameter. You can also rename your runs, add notes, or create tags to group them. Once you’re satisfied, save your workspace and use it to create a report, importing data from your runs and saved artifacts (training and validation files).

Access your fine-tuned model

W&B logs the fine-tuned model ID as artifacts (model_metadata.json) and as config.
The <version> placeholder is one of the following:
  • A version number such as v2.
  • The fine-tune ID such as ft-xxxxxxxxx.
  • An alias added automatically such as latest, or added manually.
You can then access the fine_tuned_model ID by reading the downloaded model_metadata.json file.

Recover a fine-tune that didn’t sync

If a fine-tune wasn’t logged to W&B successfully, use overwrite=True and pass the fine-tune job ID:

Track datasets and models with W&B

W&B logs the training and validation data automatically as artifacts. W&B also logs the metadata, including the ID for the fine-tuned model, as artifacts. You can also control the pipeline with low-level wandb APIs like wandb.Artifact, wandb.Run.log, and so on. This gives you full traceability of your data and models.
OpenAI tracking FAQ

Resources

For deeper background and end-to-end examples, see the following resources.