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

# Fine-Tuning

Fine-tuning is incredibly powerful. PromptLayer lets you build and iterate models in a few clicks.

If you are already logging your `gpt-4` requests in PromptLayer, it only takes a few clicks to fine-tune a `gpt-3.5-turbo` model on those requests! ✨

## What is fine-tuning?

Fine-tuning is a technique to specialize a pre-trained large language model (LLM) for a specific task. It involves training the LLM on a small dataset of examples, where the input is the text to be processed and the output is the desired output, such as a classification label, a translation, or a generated text.

Fine-tuning is powerful because it allows developers to create a model that is tailored to their specific needs. This could be used to improve model output quality, shorten a system prompt without degrading performance, or to decrease latency by building off of a smaller model.

Here are some examples of how fine-tuning can be used:

* **Reduce latency and cost:** Fine-tune `gpt-3.5-turbo` on `gpt-4` outputs to achieve `gpt-4`-quality results on a faster and cheaper model.
* **Save on tokens:** Generate training data using a long and complex prompt. When fine-tuning, change the prompt to something shorter and save on tokens.
* **Improve output format:** Generate synthetic training data to teach a base model to only output text in JSON.

## Create training data

The first step to fine-tuning is preparing the training data you want the model to learn from. Training data in this case are just LLM requests.

### Log in the background

The simplest way to do this is to just connect your application to PromptLayer and start logging requests. Just wait a week and your production users will have created tons of training data for you!

### Batch run prompts

Alternatively, you can use PromptLayer to generate these training requests. Visit the [Evaluations page](/features/evaluations/overview) to run batch jobs of your prompts.

For example, to generate fine-tuning data you can run a prompt template from the [Prompt Registry](/features/prompt-registry) against 200 test cases on `gpt-4`. Then just filter the sidebar based its specific test run tag.

<img src="https://mintcdn.com/promptlayer/4xCQDros0B-lHSut/images/fine-tuning/generate.png?fit=max&auto=format&n=4xCQDros0B-lHSut&q=85&s=26745383e78ffa98ebecec334e7b17c2" alt="Generate Training Data" width="2114" height="1554" data-path="images/fine-tuning/generate.png" />

## Select training data

Use the sidebar search area to filter for your training data. All the data that appears from that search query will be used to fine-tune.

[Learn more about search filters](/why-promptlayer/advanced-search)

<div style={{width: '70%'}}>
  <img src="https://mintcdn.com/promptlayer/4xCQDros0B-lHSut/images/fine-tuning/select-training.gif?s=2892dfbf1ff25e5c72dcd1984cde4b58" alt="Select Training Data" width="800" height="720" data-path="images/fine-tuning/select-training.gif" />
</div>

## Start the fine-tune job

Click "Fine-Tune" in the sidebar, follow the steps, and kick off a job.

## Test out your new model

**Success!** 🎉 Now you have a new fine-tuned model. Let's see if it's any good...

<div style={{width: '70%'}}>
  <img src="https://mintcdn.com/promptlayer/4xCQDros0B-lHSut/images/fine-tuning/success.png?fit=max&auto=format&n=4xCQDros0B-lHSut&q=85&s=3be76ebaa27e1fff8060a9c5ec347f8d" alt="Successful fine-tuning" width="1156" height="1468" data-path="images/fine-tuning/success.png" />
</div>

### Try it in Playground

Copy the model name and navigate to the PromptLayer Playground. There you can run an arbitrary request on the new model. See how it does!

<div style={{width: '70%'}}>
  <img src="https://mintcdn.com/promptlayer/4xCQDros0B-lHSut/images/fine-tuning/request.png?fit=max&auto=format&n=4xCQDros0B-lHSut&q=85&s=de4eaff35eba350bf92bf02c48cd97f4" alt="Try out Fine-Tuned Model" width="728" height="406" data-path="images/fine-tuning/request.png" />
</div>

### Try it in Evaluations

It's important to test your fine-tune model a little more rigorously than one-off Playground requests. Navigate to the [Evaluations page](/features/evaluations/overview) and run some batch tests. See how the fine-tuned candidate compares to a standard `gpt-4` candidate.

<img src="https://mintcdn.com/promptlayer/4xCQDros0B-lHSut/images/fine-tuning/evaluate.png?fit=max&auto=format&n=4xCQDros0B-lHSut&q=85&s=f0f72722d47c2c422abeb108aa08a9bc" alt="Evaluate fine-tuned model" width="2014" height="1428" data-path="images/fine-tuning/evaluate.png" />
