使用 AutoTrain 微调 Mixtral 8x7B
在这篇博文中,我将向你展示如何使用 AutoTrain 在你自己的数据集上微调 Mixtral 8x7B。这篇博文使用的编码量会非常少。我们将编写 零 行代码!
由于 Mixtral 是一个相当大的模型,微调它需要相当大的硬件。在本文中,我们将使用 Hugging Face 最新提供的服务:在 DGX Cloud 上训练。但请注意,你也可以使用本文中的流程,在你自己的硬件(或其他云提供商)上进行训练!本文也提供了在本地/自定义硬件上进行训练的步骤。
注意:DGX Cloud 上的训练服务仅对企业用户开放。
要在你的自定义数据集上微调 mixtral-8x7b-instruct,你可以点击这里,然后点击“Train”按钮,你会看到一些选项,你需要选择“NVIDIA DGX cloud”。
完成后,系统会为你创建一个 AutoTrain Space,你可以在其中上传你的数据、选择参数并开始训练。
如果在本地运行,你只需要安装 AutoTrain 并启动应用即可。
$ pip install -U autotrain-advanced
$ export HF_TOKEN=your_huggingface_write_token
$ autotrain app --host 127.0.0.1 --port 8080
完成后,你可以在浏览器中访问 127.0.0.1:8080,现在你就可以在本地进行微调了。
如果在 DGX Cloud 上运行,你会在硬件下拉菜单中看到选择 8xH100 的选项。如果在本地运行,此下拉菜单将被禁用。
如你所见,AutoTrain UI 为不同类型的任务、数据集和参数提供了许多选项。用户可以使用 AutoTrain 在自己的数据集上训练几乎任何类型的模型 💥 如果你是高级用户,并且想要调整更多参数,你只需点击训练参数下的 Full
即可!
参数越多,最终用户就越容易混淆。今天,我们只讨论基本参数。99% 的情况下,你只需要调整基本参数就能得到一个最终性能非常出色的模型 😉 提供超出需求的功能只会让最终用户感到困惑。
今天,我们选择 Hugging Face H4 团队的 no_robots
数据集。你可以在这里查看该数据集。以下是该数据集的一个样本示例
[ { "content": "Please summarize the goals for scientists in this text:\n\nWithin three days, the intertwined cup nest of grasses was complete, featuring a canopy of overhanging grasses to conceal it. And decades later, it served as Rinkert’s portal to the past inside the California Academy of Sciences. Information gleaned from such nests, woven long ago from species in plant communities called transitional habitat, could help restore the shoreline in the future. Transitional habitat has nearly disappeared from the San Francisco Bay, and scientists need a clearer picture of its original species composition—which was never properly documented. With that insight, conservation research groups like the San Francisco Bay Bird Observatory can help guide best practices when restoring the native habitat that has long served as critical refuge for imperiled birds and animals as adjacent marshes flood more with rising sea levels. “We can’t ask restoration ecologists to plant nonnative species or to just take their best guess and throw things out there,” says Rinkert.", "role": "user" }, { "content": "Scientists are studying nests hoping to learn about transitional habitats that could help restore the shoreline of San Francisco Bay.", "role": "assistant" } ]
这个数据集几乎是 SFT 训练的标准。如果你想在自己的自定义数据集上训练你自己的对话机器人,这就是需要遵循的格式! 🤗 感谢 H4 团队!
现在,我们已经准备好了数据集和运行中的 AutoTrain UI。我们现在需要做的就是将 UI 指向数据集,调整参数,然后点击“Start”按钮。这是点击“Start”按钮前的 UI 界面。
我们选择了 Hugging Face Hub 数据集,并更改了以下内容
- 数据集名称:
HuggingFaceH4/no_robots
- 训练集拆分:
train_sft
,这是该特定数据集中拆分的命名方式。 - 列映射:
{"text": "messages"}
。这将 AutoTrain 的 text 列映射到数据集中的文本列,在我们的例子中是messages
。
对于参数,以下设置效果很好
{
"block_size": 1024,
"model_max_length": 2048,
"mixed_precision": "bf16",
"lr": 0.00003,
"epochs": 3,
"batch_size": 2,
"gradient_accumulation": 4,
"optimizer": "adamw_bnb_8bit",
"scheduler": "linear",
"chat_template": "zephyr",
"target_modules": "all-linear",
"peft": false
}
在这里,我们使用了 adamw_bnb_8bit 优化器和 zephyr 聊天模板。根据你的数据集,你可以使用 zephyr
、chatml
或 tokenizer
聊天模板。或者你也可以将其设置为 none
,并在上传到 AutoTrain 之前按你喜欢的方式格式化数据:可能性是无穷无尽的。
请注意,对于这个特定的模型,我们没有使用量化,PEFT 已被禁用 💥
完成后,点击“Start”按钮,然后就可以去喝杯咖啡,放松一下了。
当我使用相同的参数和数据集在 8xH100 上尝试时,训练耗时约 45 分钟(3 个 epoch),我的模型被推送到了 Hub 上作为一个私有模型,供我立即试用 🚀 如果你想看看训练好的模型,可以在这里查看。
太棒了!我们已经在自己的自定义数据集上微调了 mixtral 8x7b-instruct 模型,并且该模型已经准备好使用 Hugging Face 的推理端点进行部署。
彩蛋:如果你喜欢命令行界面,这里是运行命令
autotrain llm \
--train \
--trainer sft \
--model mistralai/Mixtral-8x7B-Instruct-v0.1 \
--data-path HuggingFaceH4/no_robots \
--train-split train_sft \
--text-column messages \
--chat-template zephyr \
--mixed-precision bf16 \
--lr 2e-5 \
--optimizer adamw_bnb_8bit \
--scheduler linear \
--batch-size 2 \
--epochs 3 \
--gradient-accumulation 4 \
--block-size 1024 \
--max-length 2048 \
--padding right \
--project-name autotrain-xva0j-mixtral8x7b
--username abhishek \
--push-to-hub
如有疑问,请通过 autotrain@hf.co 或 Twitter 联系:@abhi1thakur