You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fine-tuning retrains an existing large language model (LLM) by using example data. The result is a new, custom LLM that's optimized for the provided examples.
21
+
Fine-tuning refers to customizing a pre-trained generative AI model with additional training on a specific task or new dataset for enhanced performance, new skills, or improved accuracy. The result is a new, custom GenAI model that's optimized based on the provided examples.
22
22
23
-
This article can help you decide whether or not fine-tuning is the right solution for your use case. This article also describes how [Azure AI Studio](https://ai.azure.com) can support your fine-tuning needs.
23
+
Consider fine-tuning GenAI models to:
24
+
- Scale and adapt to specific enterprise needs
25
+
- Reduce false positives as tailored models are less likely to produce inaccurate or irrelevant responses
26
+
- Enhance the model's accuracy for domain-specific tasks
27
+
- Save time and resources with faster and more precise results
28
+
- Get more relevant and context-aware outcomes as models are fine-tuned for specific use cases
24
29
25
-
In this article, fine-tuning refers to *supervised fine-tuning*, not to continuous pretraining or reinforcement learning through human feedback (RLHF). Supervised fine-tuning is the process of retraining pretrained models on specific datasets. The purpose is typically to improve model performance on specific tasks or to introduce information that wasn't well represented when you originally trained the base model.
30
+
[Azure AI Foundry](https://ai.azure.com) offers several models across model providers enabling you to get access to the latest and greatest in the market. You can discover supported models for fine-tuning through our model catalog by using the **Fine-tuning tasks** filter and clicking into the model card to learn detailed information about each model. Specific models may be subjected to regional constraints, [view this list for more details](#supported-models-for-fine-tuning).
26
31
27
-
## Getting starting with fine-tuning
32
+
:::image type="content" source="../media/concepts/model-catalog-fine-tuning.png" alt-text="Screenshot of Azure AI Foundry model catalog and filtering by Fine-tuning tasks." lightbox="../media/concepts/model-catalog-fine-tuning.png":::
28
33
29
-
When you're deciding whether or not fine-tuning is the right solution for your use case, it's helpful to be familiar with these key terms:
34
+
This article will walk you through use-cases for fine-tuning and how this can help you in your GenAI journey.
30
35
31
-
-[Prompt engineering](../../ai-services/openai/concepts/prompt-engineering.md) is a technique that involves designing prompts for natural language processing models. This process improves accuracy and relevancy in responses, to optimize the performance of the model.
32
-
-[Retrieval-augmented generation (RAG)](../concepts/retrieval-augmented-generation.md) improves LLM performance by retrieving data from external sources and incorporating it into a prompt. RAG can help businesses achieve customized solutions while maintaining data relevance and optimizing costs.
33
-
34
-
Fine-tuning is a great way to get higher quality results while reducing latency. The following questions can help you better understand why fine-tuning and evaluate whether you're ready for fine-tuning through the process. You can use these questions to guide your next steps.
35
-
36
-
### Why do you want to fine-tune a model?
37
-
38
-
Before you begin fine-tuning a model, consider if you've identified shortcomings when using a base model. These shortcomings can include: an inconsistent performance on edge cases, inability to fit enough prompts in the context window to steer the model, or high latency.
39
-
40
-
Base models are already pre-trained on vast amounts of data, but most times you will add instructions and examples to the prompt to get the quality responses that you're looking for. This process of "few-shot learning" can be improved with fine-tuning.
41
-
42
-
Fine-tuning allows you to train a model with many more examples. You can tailor your examples to meet your specific use-case. This can help you reduce the number of tokens in the prompt leading to potential cost savings and requests with lower latency.
43
-
44
-
Use cases for fine-tuning a model can be:
45
-
- Steering the model to output content in a specific and customized style, tone, or format.
36
+
## Getting started with fine-tuning
46
37
47
-
If you identify cost as your primary motivator, proceed with caution. Fine-tuning might reduce costs for certain use cases by shortening prompts or allowing you to use a smaller model. But typically there's a higher upfront cost to training, and you have to pay for hosting your own custom model.
48
-
49
-
### What isn't working with alternate approaches?
50
-
51
-
Understanding where prompt engineering falls short should provide guidance on approaching your fine-tuning. Is the base model failing on edge cases or exceptions? Is the base model not consistently providing output in the right format, and you can't fit enough examples in the context window to fix it?
52
-
53
-
Examples of failure with the base model and prompt engineering can help you identify the data that they need to collect for fine-tuning, and how you should be evaluating your fine-tuned model.
54
-
55
-
Here's an example: A customer wants to use GPT-3.5 Turbo to turn natural language questions into queries in a specific, nonstandard query language. The customer provides guidance in the prompt ("Always return GQL") and uses RAG to retrieve the database schema. However, the syntax isn't always correct and often fails for edge cases. The customer collects thousands of examples of natural language questions and the equivalent queries for the database, including cases where the model failed before. The customer then uses that data to fine-tune the model. Combining the newly fine-tuned model with the engineered prompt and retrieval brings the accuracy of the model outputs up to acceptable standards for use.
56
-
57
-
### What have you tried so far?
58
-
59
-
Fine-tuning is an advanced capability, not the starting point for your generative AI journey. You should already be familiar with the basics of using LLMs. You should start by evaluating the performance of a base model with prompt engineering and/or RAG to get a baseline for performance.
38
+
When starting out on your generative AI journey, we recommend you begin with prompt engineering and RAG to familiarize yourself with base models and its capabilities.
39
+
-[Prompt engineering](../../ai-services/openai/concepts/prompt-engineering.md) is a technique that involves designing prompts using tone and style details, example responses, and intent mapping for natural language processing models. This process improves accuracy and relevancy in responses, to optimize the performance of the model.
40
+
-[Retrieval-augmented generation (RAG)](../concepts/retrieval-augmented-generation.md) improves LLM performance by retrieving data from external sources and incorporating it into a prompt. RAG can help businesses achieve customized solutions while maintaining data relevance and optimizing costs.
60
41
61
-
Having a baseline for performance without fine-tuning is essential for knowing whether or not fine-tuning improves model performance. Fine-tuning with bad data makes the base model worse, but without a baseline, it's hard to detect regressions.
42
+
As you get comfortable and begin building your solution, it's important to understand where prompt engineering falls short and that will help you realize if you should try fine-tuning.
43
+
- Is the base model failing on edge cases or exceptions?
44
+
- Is the base model not consistently providing output in the right format?
45
+
- Is it difficult to fit enough examples in the context window to steer the model?
46
+
- Is there high latency?
62
47
63
-
Before you begin fine-tuning a model, you need to ensure:
48
+
Examples of failure with the base model and prompt engineering can help you identify the data to collect for fine-tuning and establish a performance baseline that you can evaluate and compare your fine-tuned model against. Having a baseline for performance without fine-tuning is essential for knowing whether or not fine-tuning improves model performance.
64
49
65
-
- You can demonstrate evidence and knowledge of using prompt engineering and RAG-based approaches on your LLM.
66
-
- You can share specific experiences and challenges with techniques other than fine-tuning that you tried for your use case.
67
-
- You have quantitative assessments of baseline performance, whenever possible.
68
-
- You have a labeled dataset that corresponds with the specific usecase you want to train your LLM.
50
+
Here's an example:
69
51
70
-
### What data are you going to use for fine-tuning?
52
+
_A customer wants to use GPT-3.5 Turbo to turn natural language questions into queries in a specific, nonstandard query language. The customer provides guidance in the prompt ("Always return GQL") and uses RAG to retrieve the database schema. However, the syntax isn't always correct and often fails for edge cases. The customer collects thousands of examples of natural language questions and the equivalent queries for the database, including cases where the model failed before. The customer then uses that data to fine-tune the model. Combining the newly fine-tuned model with the engineered prompt and retrieval brings the accuracy of the model outputs up to acceptable standards for use._
71
53
72
-
Even with a great use case, fine-tuning is only as good as the quality of the data that you can provide. You need to be willing to invest the time and effort to make fine-tuning work. Different models require different data volumes, but you often need to be able to provide fairly large quantities of high-quality curated data. In supervised fine-tuning, a generic moddel is trained on a topic specific labeled dataset. The model with adjust it's parameters to the new data and apply pre-existing knowledge when outputting new content.
54
+
### Use cases
73
55
74
-
Another important point is that even with high-quality data, if your data isn't in the necessary format for fine-tuning, you need to commit engineering resources for the formatting.
56
+
Base models are already pre-trained on vast amounts of data and most times you'll add instructions and examples to the prompt to get the quality responses that you're looking for - this process is called "few-shot learning". Fine-tuning allows you to train a model with many more examples that you can tailor to meet your specific use-case, thus improving on few-shot learning. This can reduce the number of tokens in the prompt leading to potential cost savings and requests with lower latency.
75
57
76
-
You might be ready for fine-tuning if:
58
+
Turning natural language into a query language is just one use case where you can _show not tell_ the model how to behave. Here are some additional use cases:
59
+
- Improve the model's handling of retrieved data
60
+
- Steer model to output content in a specific style, tone, or format
61
+
- Improve the accuracy when you look up information
62
+
- Reduce the length of your prompt
63
+
- Teach new skills (i.e. natural language to code)
77
64
78
-
- You identified a dataset for fine-tuning.
79
-
- Your dataset is in the appropriate format for training on your existing model.
80
-
- You employed some level of curation to ensure dataset quality.
65
+
If you identify cost as your primary motivator, proceed with caution. Fine-tuning might reduce costs for certain use cases by shortening prompts or allowing you to use a smaller model. But there may be a higher upfront cost to training, and you have to pay for hosting your own custom model.
81
66
67
+
### Steps to fine-tune a model
68
+
Here are the general steps to fine-tune a model:
69
+
1. Based on your use case, choose a model that supports your task
70
+
2. Prepare and upload training data
71
+
3. (Optional) Prepare and upload validation data
72
+
4. (Optional) Configure task parameters
73
+
5. Train your model.
74
+
6. Once completed, review metrics and evaluate model. If the results don't meet your benchmark, then go back to step 2.
75
+
7. Use your fine-tuned model
82
76
83
-
### How will you measure the quality of your fine-tuned model?
77
+
It's important to call out that fine-tuning is heavily dependent on the quality of data that you can provide. It's best practice to provide hundreds, if not thousands, of training examples to be successful and get your desired results.
84
78
85
-
There isn't a single right answer to this question, but you should have clearly defined goals for what success with fine-tuning looks like. Ideally, this effort shouldn't just be qualitative. It should include quantitative measures of success, like using a holdout set of data for validation, in addition to user acceptance testing or A/B testing the fine-tuned model against a base model.
79
+
## Supported models for fine-tuning
86
80
87
-
## Supported models for fine-tuningin Azure AI Studio
81
+
Now that you know when to use fine-tuning for your use case, you can go to Azure AI Studio to find models available to fine-tune. Fine-tuning is available in specific Azure regions for some models. To fine-tune such models, a user must have a hub/project in the region where the model is available for fine-tuning. See [Region availability for models in serverless API endpoints | Azure AI Studio](../how-to/deploy-models-serverless-availability.md) for detailed information.
88
82
89
-
Now that you know when to use fine-tuning for your use case, you can go to Azure AI Studio to find models available to fine-tune. The following table describes models that you can fine-tune in Azure AI Studio, along with the regions where you can fine-tune them.
83
+
For details about Azure OpenAI models that are available for fine-tuning, see the [Azure OpenAI Service models documentation](../../ai-services/openai/concepts/models.md#fine-tuning-models) or the [Azure OpenAI models table](#fine-tuning-azure-openai-models) later in this guide.
90
84
91
-
| Model family | Model ID | Fine-tuning regions |
92
-
| --- | --- | --- |
93
-
|[Azure OpenAI models](../../ai-services/openai/how-to/fine-tuning.md?context=/azure/ai-studio/context/context)| Azure OpenAI Service models that you can fine-tune include among others `gpt-4` and `gpt-4o-mini`.<br/><br/>For details about Azure OpenAI models that are available for fine-tuning, see the [Azure OpenAI Service models documentation](../../ai-services/openai/concepts/models.md#fine-tuning-models) or the [Azure OpenAI models table](#fine-tuning-azure-openai-models) later in this guide. | Azure OpenAI Service models that you can fine-tune include among others North Central US and Sweden Central.<br/><br/>The supported regions might vary if you use Azure OpenAI models in an AI Studio project versus outside a project.<br/><br/>For details about fine-tuning regions, see the [Azure OpenAI Service models documentation](../../ai-services/openai/concepts/models.md#fine-tuning-models). |
94
-
|[Phi-3 family models](../how-to/fine-tune-phi-3.md)|`Phi-3-mini-4k-instruct`<br/>`Phi-3-mini-128k-instruct`<br/>`Phi-3-medium-4k-instruct`<br/>`Phi-3-medium-128k-instruct`| East US2 |
95
-
|[Meta Llama 2 family models](../how-to/fine-tune-model-llama.md)|`Meta-Llama-2-70b`<br/>`Meta-Llama-2-7b`<br/>`Meta-Llama-2-13b` <br/> `Llama-2-7B-chat` <br> `Llama-2-70B-chat`| West US3 |
96
-
|[Meta Llama 3.1 family models](../how-to/fine-tune-model-llama.md)|`Meta-Llama-3.1-70b-Instruct`<br/>`Meta-Llama-3.1-8b-Instruct`| West US3 |
97
85
98
-
This table provides more details about the Azure OpenAI Service models that support fine-tuning and the regions where fine-tuning is available.
86
+
For the Azure OpenAI Service models that you can fine tune, supported regions for fine-tuning include North Central US, Sweden Central, and more.
0 commit comments