Azure LLM Fine Tuning Strategies for Improved Results

Author

Reads 784

An artist’s illustration of artificial intelligence (AI). This image represents ethics research understanding human involvement in data labelling. It was created by Ariel Lu as part of the...
Credit: pexels.com, An artist’s illustration of artificial intelligence (AI). This image represents ethics research understanding human involvement in data labelling. It was created by Ariel Lu as part of the...

Fine tuning an Azure LLM can significantly improve its performance. This process involves adjusting the model's parameters to better fit your specific use case.

To start fine tuning, you'll need to choose a dataset that's relevant to your task. A dataset of 10,000 to 20,000 examples is a good starting point, as seen in the "Choosing the Right Dataset" section.

The type of dataset you choose will depend on the task you're trying to accomplish. If you're building a conversational AI, you'll want to use a dataset that's rich in dialogue examples. For example, the "Conversational AI Dataset" section highlights the importance of using a dataset with a diverse range of dialogue styles.

Fine tuning an Azure LLM can be a time-consuming process, but the results are well worth it. By following the strategies outlined in this article, you can significantly improve the performance of your Azure LLM.

Fine-Tuning Steps

Fine-tuning steps are crucial to achieve your desired results. You'll need hundreds, if not thousands, of training examples to be successful, as the quality of data is heavily dependent on the fine-tuning process.

Credit: youtube.com, Advancing AI - Fine Tuning LLMs with Azure OpenAI

To get started, choose a model that supports your task, such as gpt-35-turbo-0613 or davinci-002, which are both supported for fine-tuning. Prepare and upload your training data, and optionally, validation data to test your model's performance.

Here are the basic steps to fine-tune a model:

  1. Choose a model that supports your task
  2. Prepare and upload training data
  3. (Optional) Prepare and upload validation data
  4. (Optional) Configure task parameters
  5. Train your model
  6. Review metrics and evaluate model
  7. Use your fine-tuned model

Remember, the size of your dataset matters – attempting with at least 50 training examples is recommended for optimal results.

Requirements

To fine-tune your Large Language Model (LLM), you'll need to set up a suitable environment. Access to Azure OpenAI Service is a must-have.

You'll also need to connect to your Azure ML workspace and gather your workspace name, resource group, and subscription ID. This will help you get started with Azure ML.

For code development, a low-end instance without a GPU is recommended. Consider using the Standard_E2as_v4 instance, which comes with 2 AMD cores, 16GB RAM, and 32GB storage.

Alternatively, you can opt for the Standard_DS11_v2 instance, which has 2 Intel cores, 14GB RAM, and 28GB storage, but no GPUs.

Credit: youtube.com, Fine-tuning Large Language Models (LLMs) | w/ Example Code

If you're planning to fine-tune your LLM, you'll need a more powerful instance. A single NVIDIA A100 GPU is recommended for this task. You can use the Standard_NC24ads_A100_v4 instance, which comes with a single A100 GPU.

However, if you're on a tight budget or don't have a dedicated quota, you can choose a Low-priority VM instead.

To deploy your LLM, you'll need at least two NVIDIA V100 GPUs or two NVIDIA A100 GPUs. The Standard_NC6s_v3 instance is recommended for this task, with two V100 GPUs.

Remember to consider the quota requirements for your deployment. Azure ML reserves 20% of the quota for the deployment, so make sure you have enough quota available to avoid errors.

Model Fine-Tuning Steps

Fine-tuning a model is a crucial step in achieving the desired results. To fine-tune a model, start by choosing a model that supports your task. You'll need to prepare and upload training data, which should be hundreds, if not thousands, of examples to be successful.

Credit: youtube.com, Fine Tune a model with MLX for Ollama

Here are the steps to fine-tune a model in detail:

  1. Choose a model that supports your task
  2. Prepare and upload training data
  3. Optional: Prepare and upload validation data
  4. Optional: Configure task parameters
  5. Train your model
  6. Review metrics and evaluate model. If the results don't meet your benchmark, go back to step 2
  7. Use your fine-tuned model

The quality of your data is crucial for fine-tuning. A small dataset of 15 examples, like in the example, may not be enough to achieve the desired results. The OpenAI documentation recommends attempting with at least 50 examples.

Finetuning for Stock Prices

Finetuning for Stock Prices is a crucial step in building a chatbot that retrieves stock prices from an external API. This process involves fine-tuning a base model to improve its accuracy and performance.

The first challenge in building such a chatbot is distinguishing real companies from fake ones. The base model performs poorly in this task.

A real-world case study demonstrates the utility of function calling with fine-tuned models. The study involves building a chatbot that retrieves stock prices from an external API.

Fine-tuning with function calling can significantly improve the model's accuracy and performance. This is achieved by creating a training dataset and comparing the fine-tuned model to the base model.

The fine-tuned model is developed through three phases: establishing a baseline, creating a training dataset, and comparing the fine-tuned model to the base model.

Fine Tuning and Function Calling

Credit: youtube.com, Finetune Mistral 7B | Function Calling | LM Studio | FAST Local LLM Inference On Mac & iPhone

Fine tuning with function calling is a powerful technique that allows your model to learn how and when to call external APIs, making it a game-changer for tasks like retrieving stock prices.

You can use fine tuning to teach your model new skills, such as when to make function calls or what to do with the results. Fine tuning also offers cost savings by shortening function call descriptions and signatures, reducing prompt length and token usage.

Fine tuning with function calling is currently available for the gpt-35-turbo (0613) and gpt-35-turbo-16k (1106) models, which support function calling in both training data and inferencing.

To get the most out of fine tuning, it's essential to provide adequate training examples, with at least 100 high-quality examples for optimal performance. Consistency in function definitions between training and inference is also crucial for accurate and reliable responses.

Experimenting with different parameter combinations, such as adjusting the learning rate multiplier and number of epochs, can help improve performance. Refining function definitions to enhance clarity and distinctiveness is also essential for improved accuracy.

Credit: youtube.com, Fine Tuning LLMs for Function Calling w/Pawel Garbacki

Here are some key benefits of fine tuning with function calling:

  • New Skills: Teach your model when to make function calls, or what to do with the results.
  • Cost savings: Shorten the descriptions and signatures for function calls to reduce prompt length.
  • Enhanced accuracy, reliability and responsiveness: elevate the precision and reliability of model outputs.

Remember to be mindful of token usage and explore strategies to stay within token limits, such as omitting descriptions or entire functions. It's also essential to validate function calls, use trusted data sources, and follow the Principle of Least Privilege to ensure responsible usage.

Supported Models

Azure OpenAI models support fine-tuning in various regions, including North Central US, Sweden Central, and Switzerland West. These regions are crucial to consider when fine-tuning models.

To fine-tune Azure OpenAI models, you'll need to have a hub/project in the region where the model is available for fine-tuning. This ensures that your model is trained on the right data and in the right environment.

Some Azure OpenAI models that support fine-tuning include gpt-35-turbo-0613, gpt-35-turbo-1106, babbage-002, and davinci-002. These models are specifically designed for fine-tuning and can be customized to meet your needs.

You can find more information about supported models and regions on the Azure AI Foundry website, which provides detailed information on region availability for models in serverless API endpoints.

Credit: youtube.com, Fine-tune and deploy foundation models with Azure Machine Learning

Here's a list of some Azure OpenAI models that support fine-tuning, along with their supported regions and other relevant information:

Optimization and Evaluation

Fine-tuning with Azure OpenAI requires a well-structured approach to achieve optimal results. You need to provide your training dataset as a JSON Lines (JSONL) document, with a minimum of 10 examples for training, but OpenAI recommends generating at least 50 different example interactions.

The file must be encoded in UTF-8 and include a byte-order mark (BOM), and should not exceed 100 MB in size. This is because you're trying to teach the model a new way to interact or respond, not feed it new knowledge.

To evaluate the model's performance, you can test it with various paragraphs to ensure it generates accurate structured JSON outputs. The Azure AI studio offers the chat playground as a friendly way to interact with the custom model and test how it behaves during an interaction.

Credit: youtube.com, To Fine Tune or Not Fine Tune? That is the question

If the results don't meet your benchmark, you should go back to step 2 and refine your training examples. This is because fine-tuning is heavily dependent on the quality of data that you can provide.

Here are the key steps to fine-tune a model:

  1. Based on your use case, choose a model that supports your task
  2. Prepare and upload training data
  3. (Optional) Prepare and upload validation data
  4. (Optional) Configure task parameters
  5. Train your model.
  6. Once completed, review metrics and evaluate model. If the results don't meet your benchmark, then go back to step 2.
  7. Use your fine-tuned model

Use Cases and Examples

Fine-tuning your Azure LLM can be a game-changer for various use cases. By adding instructions and examples to the prompt, you can achieve high-quality responses through few-shot learning.

Fine-tuning allows you to train a model with many more examples, tailoring it to meet your specific use-case and 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.

Some examples of use cases where fine-tuning can be beneficial include:

  • Improving the model's handling of retrieved data
  • Steering the model to output content in a specific style, tone, or format
  • Improving the accuracy when looking up information
  • Reducing the length of your prompt
  • Teaching new skills, such as natural language to code

Keep in mind that while fine-tuning might reduce costs for certain use cases, there may be a higher upfront cost to training, and you'll need to pay for hosting your own custom model.

Use Cases

Credit: youtube.com, Understanding Use-Cases & User Stories | Use Case vs User Story | Object Oriented Design | Geekific

Fine-tuning is a powerful tool that can help you achieve exceptional performance in specific tasks. It allows you to train a model with many more examples, tailoring it to meet your specific use-case and improving on few-shot learning.

You can use fine-tuning to steer the model to output content in a specific style, tone, or format, which can be particularly useful for tasks that demand structured, multifaceted responses. This can include tasks like JSON outputs from paragraphs.

Fine-tuning can also be used to teach new skills, such as natural language to code, by providing the model with examples of the desired output. This can help you achieve high accuracy and reduce the length of your prompt.

Some examples of use cases where fine-tuning excels include tasks that require specific, structured outputs, custom behavior, multimodal tasks, and task-specific training. These are all areas where fine-tuning can help you achieve exceptional performance.

An artist’s illustration of artificial intelligence (AI). This image depicts how AI tools can democratise education and make learning more efficient. It was created by Martina Stiftinger a...
Credit: pexels.com, An artist’s illustration of artificial intelligence (AI). This image depicts how AI tools can democratise education and make learning more efficient. It was created by Martina Stiftinger a...

Here are some examples of use cases where fine-tuning can be particularly useful:

  • Complex Outputs: fine-tuning is ideal for tasks that demand structured, multifaceted responses, like JSON outputs from paragraphs.
  • Custom Behaviour: you can tailor the model's behaviour to your exact requirements, defining specific output formats and content.
  • Multimodal Tasks: for tasks involving both text and structured data, fine-tuning is the preferred choice.
  • Task-Specific Training: fine-tuning allows you to refine the model's understanding for domain-specific applications.

Scenario 1: Hallucination

Hallucinations are a common problem with large language models, where they provide plausible but false responses. This can happen when the model calls a function in the wrong context or provides incorrect information to the function call.

A test dataset of 10 samples, consisting of 5 fake and 5 real companies, was used to evaluate the base model's ability to correctly identify fake companies. The base model struggled to differentiate between fake and real companies accurately, despite a clear system message not to make assumptions.

In fact, the base model generated a fake symbol for Titan Robotics and output a function, demonstrating its tendency to hallucinate. The test dataset was used to create a training dataset with function calling capabilities to address this issue.

Fine-tuning the model was key in addressing hallucinations and enhancing accuracy. A training dataset with 96 samples was created, including fake company examples with appropriate responses, to teach the model how to identify and respond to fake requests.

Rosemary Boyer

Writer

Rosemary Boyer is a skilled writer with a passion for crafting engaging and informative content. With a focus on technical and educational topics, she has established herself as a reliable voice in the industry. Her writing has been featured in a variety of publications, covering subjects such as CSS Precedence, where she breaks down complex concepts into clear and concise language.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.