Azure AI 微调:从基础到高级

Author

Reads 1.1K

AI Multimodal Model
Credit: pexels.com, AI Multimodal Model

Azure AI 微调提供了多种方式来微调模型,包括数据增强和超参数调优。数据增强可以通过旋转、翻转和裁剪等方式来增强数据的多样性,而超参数调优可以通过调整模型的超参数来提高模型的性能。

通过 Azure AI 微调,你可以根据自己的需求来选择微调的方式和范围。例如,你可以选择微调模型的特定层或微调整个模型。

准备数据

训练数据和验证数据集由输入和输出示例组成,这些示例代表了你希望模型如何执行。

不同模型类型需要不同格式的训练数据。

你使用的训练和验证数据必须格式化为 JSON 行 (JSONL) 文档。

对于 gpt-35-turbo(所有版本)、gpt-4、gpt-4o 和 gpt-4o-mini,必须以聊天补全 API 使用的对话格式来设置微调数据集的格式。

训练示例越多越好。 如果没有至少 10 个训练示例,微调作业将无法继续,但如此少的数量不足以显著影响模型响应。 最佳做法是提供数百个(如果不是数千个)训练示例来获得成功。

训练数据文件的格式必须设置为 JSONL 文件,采用 UTF-8 编码并带有字节顺序标记 (BOM)。 文件大小必须小于 512 MB。

以下是训练数据文件的要求:

  • 最多可以包含包含影像的 50,000 个範例(不包括文字範例)。
  • 每个範例最多可以有 64 个影像。
  • 每个映像最多可以 10 MB。

创建模型

To create a model in Azure AI Studio, you need to log in and select a project. If you don't have a project, create one first. Once you're in, click on "微调" (fine-tune) and then "+ 微调模型" (create a new fine-tuning model).

You'll then need to choose a base model to fine-tune. The model you choose will affect its performance and cost. In this example, we'll choose the gpt-35-turbo model. Make sure to confirm your selection.

If you have multiple Azure OpenAI connections enabled for fine-tuning, you'll need to choose which one to use. Note that all users with access to Azure OpenAI resources will be able to access this fine-tuned model.

If your training data is already in the project, select "Azure AI Studio 中的数据" (data in Azure AI Studio). If your training data is already uploaded to Azure OpenAI, select your Azure OpenAI connection. Alternatively, you can upload your training data to fine-tune the model.

Broaden your view: Azure Ai Training

Credit: youtube.com, AI模型理解误区:百万成本微调垂直行业达模型VS低成本建立企业专属知识库或ai助理

Once you've uploaded your file, you'll see a preview of your training data. Click "下一步" (next step) to continue.

You may also choose to provide validation data to fine-tune the model. If you don't want to use validation data, select "无" (no) and then click "下一步" to go to the advanced options for the model.

The following table lists the available base models for fine-tuning:

You can also choose to provide a suffix parameter to differentiate between different iterations of the fine-tuned model. The suffix parameter accepts a string and sets it as an identifier for the fine-tuned model. The OpenAI Python API supports up to 18 characters for the string.

For another approach, see: Create an Ai Model in My Azure Tenant

配置任务

Configuring the task is a crucial step in the Azure AI fine-tuning process. You can choose between "default" and "custom" options for the task parameters.

To configure the task parameters, you can select "custom" to display and edit the hyperparameter values. Alternatively, you can choose "default" to use the values determined by the algorithm based on the training data.

Credit: youtube.com, 使用 Azure AI Studio 构建你自己的副驾驶

The custom options include parameters such as batch size, learning rate multiplier, number of epochs, and seed. The batch size determines the number of training examples used for a single forward and backward pass, and larger batch sizes are often more suitable for larger datasets.

Here's a summary of the custom task parameters:

The learning rate multiplier is used to calculate the learning rate for training, and larger values can be more suitable for larger batch sizes. However, smaller values can be used to avoid overfitting.

The number of epochs determines the number of times the model is trained on the entire dataset, and a higher number of epochs can lead to better results but also increases the risk of overfitting.

You can choose the seed value to control the reproducibility of the job, and a specified seed value will produce the same results as a previous run with the same seed value.

If this caught your attention, see: Windows Azure Courses

部署模型

Credit: youtube.com, MVP 聚技站|企业级生成式 AI 应用构建实战(一):Azure AI Studio 模型选择与部署

部署自定义模型后,如果部署处于非活动状态的时间超过十五 (15) 天,则会删除部署。

删掉非活动状态的部署时,不会删除或影响基础自定义模型,并且可以随时重新部署自定义模型。

部署模型

To deploy a custom model, you must first deploy it from the "模型" window after a successful fine-tuning job. You can only deploy one custom model at a time, and if you try to deploy an already deployed custom model, you'll see an error message.

Once you've selected the custom model you want to deploy, click "部署模型" to open the "部署模型" dialog box. Here, you'll need to input a deployment name and click "创建" to start the deployment process.

You can monitor the deployment progress in the "部署" window of Azure AI Studio. Keep in mind that if a deployment is inactive for more than 15 days, it will be deleted, but the underlying custom model will remain intact and can be redeployed at any time.

Each deployed custom model incurs an hourly hosting cost, regardless of whether it's being used for completion or chat completion calls, as outlined in the Azure OpenAI service pricing. To plan and manage costs effectively, refer to the guidelines in the Azure OpenAI service pricing documentation.

Intriguing read: What Is Azure Openai

跨区域部署

Credit: youtube.com, Llama 3.1 一键本地部署!Meta 最强开源大模型,100%保证成功,无需GPU也能运行,可离线使用 | 零度解说

唯一的限制是新区域还必须支持微调。

你可以通过 Python 或 REST 来完成跨订阅/区域部署。

在跨订阅部署时,必须同时具有来源和目的地订阅的存取权。

你可以在 Azure AI Studio 的部署页面中监视部署进度。

分析模型

After completing the fine-tuning process, you can download a results.csv file from the "Details" tab of the fine-tuned model page. This file contains valuable information about your custom model's training and validation performance.

The results.csv file includes several key metrics, such as train_loss, train_mean_token_accuracy, valid_loss, and validation_mean_token_accuracy. These metrics provide insights into how well your model is performing on both training and validation data.

You can also view the data in the results.csv file as a graph in Azure AI Studio. By selecting the link to your trained model, you'll see three graphs: loss, mean token accuracy, and token accuracy. If you've provided validation data, both datasets will appear on the same graph.

分析模型

After you've completed a fine-tuning job, you can download a results.csv file that contains detailed information about your model's performance. This file is attached to the job and can be accessed from the "模型" window in Azure AI Studio.

Credit: youtube.com, 《数据分析自学指南》第二讲:分析模型篇:常见的数据分析模型有哪些?如何自学?

You can use the results.csv file to analyze your model's training and validation performance. The file contains several columns that provide insights into your model's behavior, including step, train_loss, train_mean_token_accuracy, valid_loss, validation_mean_token_accuracy, full_valid_loss, and full_valid_mean_token_accuracy.

Here are the columns you can expect to see in the results.csv file:

By analyzing these columns, you can gain insights into your model's performance and make adjustments to improve its accuracy.

Fine-Tuning Not Improving Model

Fine-tuning your model is a great way to improve its performance, but it's not a guarantee of success. The model may not improve if you're missing system messages during the fine-tuning process.

Providing the same system messages during both fine-tuning and model usage is crucial. If you use different system messages, the results may vary.

Data is another crucial factor. You need hundreds or thousands of data points to teach your model a new skill. Running the pipeline with the minimum of 10 data points won't be enough.

Credit: youtube.com, OpenAI fine-tuning(微调)无需编程使用办法,训练属于自己的专有模型,操作简单人人都可入手

Here are some common issues that can lead to poor model performance:

  • 数据点过少:可能导致过度拟合和泛化性能不佳
  • 错误的数据:策展不当或不具有代表性的数据集将生成低质量模型

These issues can lead to a model that performs well on the training data but poorly on other data. To get the best results, plan to prepare a data set with hundreds or thousands of data points.

Tiffany Kozey

Junior Writer

Tiffany Kozey is a versatile writer with a passion for exploring the intersection of technology and everyday life. With a keen eye for detail and a knack for simplifying complex concepts, she has established herself as a go-to expert on topics like Microsoft Cloud Syncing. Her articles have been widely read and appreciated for their clarity, insight, and practical advice.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.