Fine-tuning ChatGPT can be a game-changer for your application. By adapting the model to your specific needs, you can unlock its full potential and create a more personalized experience for your users.
To start, you'll need to choose a specific task or domain to fine-tune ChatGPT for. This could be anything from customer service to medical diagnosis. According to the article, the model's performance can be improved by up to 20% with just a few hours of fine-tuning.
The first step is to collect a dataset relevant to your chosen task or domain. This dataset will serve as the foundation for fine-tuning the model. The article notes that a dataset of at least 1,000 examples is recommended for optimal results.
With your dataset in hand, you can begin the fine-tuning process. This typically involves training the model on the new data, which can be done using a variety of techniques such as transfer learning or supervised learning.
Prerequisites
Before you start fine-tuning ChatGPT, you'll need to meet some prerequisites.
You should first read the guide on when to use Azure OpenAI fine-tuning.
To get started, you'll need an Azure subscription, which you can create for free.
Make sure your Azure OpenAI resource is located in a region that supports fine-tuning of the Azure OpenAI model. You can check the Model summary table and region availability for the list of available models by region and supported functionality.
You'll also need Cognitive Services OpenAI Contributor access for fine-tuning.
If you don't already have access to view quota and deploy models in Azure AI Studio, you'll need to request additional permissions.
Here are the specific requirements in a concise list:
- Read the guide on when to use Azure OpenAI fine-tuning.
- Have an Azure subscription.
- Have an Azure OpenAI resource in a supported region.
- Have Cognitive Services OpenAI Contributor access.
- Have access to view quota and deploy models in Azure AI Studio (if needed).
Data Preparation
Your training data and validation data sets must be formatted as a JSON Lines (JSONL) document. This is a specific format that OpenAI requires for fine-tuning.
To prepare your data, you can use OpenAI's CLI data preparation tool, which validates, gives suggestions, and reformats your training data into a JSONL file ready for fine-tuning. This tool is available for models that work with the completion API, such as babbage-002 and davinci-002.
The tool accepts files in various data formats, including CSV, TSV, XLSX, JSON, and JSONL, as long as they contain a prompt and a completion column/key. You can install the OpenAI CLI by running a Python command, and then analyze your training data with the data preparation tool by running another Python command.
For large data files, it's recommended to import from an Azure Blob store to avoid instability during upload.
To create your training and validation datasets, you'll need to have at least 10 training examples, but it's best practice to provide hundreds, if not thousands, of high-quality examples. The more training examples you have, the better the model will perform.
Here's a summary of the data formats accepted by the data preparation tool:
- Comma-separated values (CSV)
- Tab-separated values (TSV)
- Microsoft Excel workbook (XLSX)
- JavaScript Object Notation (JSON)
- JSON Lines (JSONL)
Make sure your training data files are formatted as JSONL files, encoded in UTF-8 with a byte-order mark (BOM), and are less than 512 MB in size.
Model Selection
Model selection is a crucial step in fine-tuning ChatGPT. You have seven base models to choose from: babbage-002, davinci-002, gpt-35-turbo (0613), gpt-35-turbo (1106), gpt-35-turbo (0125), gpt-4 (0613), and gpt-4o (2024-08-06).
These models are currently in public preview, and fine-tuning for them is available. The performance and cost of your custom model will be influenced by the base model you choose.
To create a custom model, select a base model from the Base model type dropdown, and then select Next to continue.
Models
When selecting a model, it's essential to know which ones support fine-tuning. The following models can be fine-tuned: babbage-002, davinci-002, gpt-35-turbo (0613), gpt-35-turbo (1106), gpt-35-turbo (0125), gpt-4 (0613), gpt-4o (2024-08-06), and gpt-4o-mini (2024-07-18).
Fine-tuning for these models is currently in public preview, and you can also fine-tune a previously fine-tuned model, formatted as base-model.ft-{jobid}. To check which regions currently support fine-tuning, consult the models page.
You can also create a custom model from one of the following available base models: babbage-002, davinci-002, gpt-35-turbo (0613), gpt-35-turbo (1106), gpt-35-turbo (0125), or gpt-4 (0613).
Here are the models that support fine-tuning:
- babbage-002
- davinci-002
- gpt-35-turbo (0613)
- gpt-35-turbo (1106)
- gpt-35-turbo (0125)
- gpt-4 (0613)
- gpt-4o (2024-08-06)
- gpt-4o-mini (2024-07-18)
Fine-tuning allows you to elevate model performance and adaptability, and it's a great way to optimize your model for specific tasks.
GPT-3.5
GPT-3.5 is a fine-tuned version of the GPT-3 model, which can be created using the OpenAI fine-tuning endpoints. This process involves uploading a dataset in JSON lines format to the OpenAI API.
The dataset should be stored on Hugging Face datasets and downloaded using the following command: pip install openai==0.27.9. The dataset is then uploaded to the OpenAI API using the openai.File.create function.
A file ID is generated by OpenAI, which can take some time to process. Once complete, the fine-tuning job can be checked using the openai.FineTuningJob.create function.
The fine-tuned model is not available for use until the fine-tuning job is complete, at which point the model ID can be found in the "fine_tuned_model" field. This ID can then be used to call the fine-tuned model, replacing "get-3.5-tubo" in the code.
Here's a step-by-step summary of the fine-tuning process:
Comparison of LLMs
So, you're trying to decide between Hugging Face and OpenAI for your Large Language Model (LLM) needs. Let's break down the key differences.
Hugging Face is known for its user-friendly interface, but it does require a strong machine learning background to get the most out of it.
OpenAI, on the other hand, is straightforward and requires some machine learning familiarity.
If you need a wide range of pre-trained models, Hugging Face has got you covered with its BERT, GPT, and other models.
OpenAI mainly focuses on GPT variants, but it does offer some other models like Jurassic-1 Jumbo and Codex.
Here's a quick comparison of the two:
Ultimately, the choice between Hugging Face and OpenAI will depend on your specific needs and use case.
Chat Format
Chat Format is a crucial aspect of fine-tuning ChatGPT. You can have multiple turns of a conversation in a single line of your jsonl training file.
This allows for more efficient training data storage and organization. You can include multiple responses in a single line, which can be helpful when working with large datasets.
To skip fine-tuning on specific assistant messages, you can add an optional weight key value pair. This can be set to 0 or 1.
Wizard and Parameters
The Create custom model wizard shows the parameters for training your fine-tuned model on the Task parameters pane. The batch size to use for training is the number of training examples used to train a single forward and backward pass. In general, we've found that larger batch sizes tend to work better for larger datasets.
You can choose to select Default to use the default values for the fine-tuning job, or select Custom to display and edit the hyperparameter values. The default value as well as the maximum value for the batch size are specific to a base model.
The following parameters are available:
If you don't specify a seed, one will be generated for you. A smaller learning rate may be useful to avoid overfitting.
Create Your
To fine-tune an Azure OpenAI model in an existing Azure AI Studio project, follow these steps: sign in to Azure AI Studio and select your project, then from the collapsible left menu, select Fine-tuning > + Fine-tune model.
You can choose a base model to fine-tune, which influences both the performance and the cost of your model. For example, you can choose the gpt-35-turbo model.
You'll need to choose a version of the base model to fine-tune, such as (0301). You can also include a suffix parameter to make it easier to distinguish between different iterations of your fine-tuned model.
You'll need to choose which Azure OpenAI connection to use, and if your training data is already in your project, you can select Data in Azure AI Studio. If your training data is already uploaded to the Azure OpenAI service, select your Azure OpenAI connection under Azure OpenAI Connection.
Here are the steps to upload your training data:
- Select Upload data and then select Upload file.
- After uploading files, you will see a preview of your training data.
- Select Next to continue.
You can also choose to provide validation data to fine-tune your model. If you don't want to use validation data, you can select None and select Next to continue to the advanced options for the model.
Review your choices and select Submit to start training your new fine-tuned model.
Configure Task Parameters
You can configure task parameters to fine-tune your model on the Task parameters pane in the Create custom model wizard.
The batch size to use for training is an important parameter, and it's set to an integer value. A larger batch size tends to work better for larger datasets, but it means that model parameters are updated less frequently, with lower variance.
You can also set the learning rate multiplier, which is a number that multiplies the original learning rate used for pre-training. Larger learning rates tend to perform better with larger batch sizes, but experimenting with values in the range 0.02 to 0.2 is recommended.
The number of epochs to train the model for is another crucial parameter, set to an integer value. An epoch refers to one full cycle through the training dataset.
The seed controls the reproducibility of the job, and it's an integer value. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases.
Here's a summary of the task parameters:
You can select Default to use the default values for the fine-tuning job, or select Custom to display and edit the hyperparameter values. When defaults are selected, the correct value is determined algorithmically based on your training data.
Configure Your Parameters
The parameters for fine-tuning a model are crucial to its performance. You can configure these parameters to suit your needs.
You can choose to use the default configuration or customize the values to your preference. The default values are determined algorithmically based on your training data.
The batch size is a key parameter to consider. A larger batch size tends to work better for larger datasets, but it means that model parameters are updated less frequently. The default value as well as the maximum value for this property are specific to a base model.
The learning rate multiplier is another important parameter. Larger learning rates tend to perform better with larger batch sizes, but a smaller learning rate may be useful to avoid overfitting.
You can also set the number of epochs to train the model for. An epoch refers to one full cycle through the training dataset.
Here's a summary of the parameters you can configure:
If you set a parameter to -1, its value will be calculated dynamically based on the input data. For example, if you set batch_size to -1, it will be calculated as 0.2% of the examples in the training set, with a maximum of 256.
Frequently Asked Questions
How much data is needed for fine-tuning?
Fine-tuning typically requires only a small amount of labeled data, often just 100 samples or less, to achieve competitive performance. This surprisingly low data requirement can lead to impressive results, even surpassing other models.
Sources
- Customize a model with Azure OpenAI Service (microsoft.com)
- chains.py (github.com)
- OpenAI just released fine tuning for the ChatGPT 3.5 Turbo model. (openai.com)
- OpenAI’s documentation for fine-tuning. (openai.com)
- How to Fine-Tune an LLM Using OpenAI (myscale.com)
- Preparing your dataset (openai.com)
Featured Images: pexels.com