Ludwig

LLM、AIGC、RAG 开发交流裙:377891973
在这里插入图片描述


一、关于 Ludwig 📖


Ludwig 是一个低代码框架,用于构建自定义AI 模型,如LLM和其他深度神经网络。

主要特征:

  • 🛠**轻松构建自定义模型:**声明式 YAML 配置文件就是您训练最先进的 LLM 所需的全部内容。支持多任务和多模态学习。全面的配置验证可检测无效的参数组合并防止运行时失败。
  • ⚡**针对规模和效率进行了优化:**自动批量大小选择、分布式训练(DDPDeepSpeed)、参数高效微调(PEFT)、4 位量化(QLoRA)、分页和 8 位优化器以及大于内存的数据集。
  • 📐**专家级控制:**保留对模型的完全控制,直至激活函数。支持超参数优化、可解释性和丰富的指标可视化。
  • 🧱**模块化和可扩展性:**只需在配置中更改几个参数,即可尝试不同的模型架构、任务、功能和模式。思考深度学习的构建模块。
  • 🚢**专为生产而设计:**预构建的Docker容器、对在Kubernetes上使用Ray 的原生支持、将模型导出到TorchscriptTriton 、使用一个命令上传到HuggingFace 。

Ludwig 由Linux 基金会 AI & Data托管 。

图片


二、 安装 💾

从 PyPi 安装。请注意,Ludwig 需要 Python 3.8+。

pip install ludwig

或者安装所有可选依赖项:

pip install ludwig[full]

请参阅贡献以获取更详细的安装说明。


三、入门 🚂

想要快速了解 Ludwig 0.8 的一些功能?查看这个 Colab Notebook 🚀外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 : https://colab.research.google.com/drive/1lB4ALmEyvcMycE3Mlnsd7I3bc0zxvk39

想要微调 Llama-2 或 Mistral?查看以下笔记本:

  1. 微调Llama-2-7b:外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
  2. 微调Llama-2-13b:外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
  3. 微调 Mistral-7b:外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传

如需完整教程,请查看官方入门指南,或查看端到端示例


四、大型语言模型微调

外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 https://colab.research.google.com/drive/1c3AO8l_H6V_x37RwQ8V7M6A-RmcBf2tG

让我们对预先训练的 LLaMA-2-7b 大型语言模型进行微调,使其像聊天机器人一样遵循指令(“指令调整”)。


先决条件


运行

我们将使用Stanford Alpaca数据集,该数据集将被格式化为如下所示的表格文件:

instructioninputoutput
Give three tips for staying healthy.1.Eat a balanced diet and make sure to include…
Arrange the items given below in the order to …cake, me, eatingI eating cake.
Write an introductory paragraph about a famous…Michelle ObamaMichelle Obama is an inspirational woman who r…

创建一个名为 model.yaml 的YAML 配置文件:

model_type: llm
base_model: meta-llama/Llama-2-7b-hf

quantization:
  bits: 4

adapter:
  type: lora

prompt:
  template: |
    Below is an instruction that describes a task, paired with an input that may provide further context.
    Write a response that appropriately completes the request.

    ### Instruction:
    {instruction}

    ### Input:
    {input}

    ### Response:

input_features:
  - name: prompt
    type: text

output_features:
  - name: output
    type: text

trainer:
  type: finetune
  learning_rate: 0.0001
  batch_size: 1
  gradient_accumulation_steps: 16
  epochs: 3
  learning_rate_scheduler:
    decay: cosine
    warmup_fraction: 0.01

preprocessing:
  sample_ratio: 0.1

backend:
  type: local

现在让我们训练模型:

export HUGGING_FACE_HUB_TOKEN = "<api_token>"

ludwig train --config model.yaml --dataset "ludwig://alpaca"

监督机器学习

让我们建立一个神经网络,预测 Rotten Tomatoes 上某位影评人的评价是正面的还是负面的。

我们的数据集将是一个如下所示的 CSV 文件:

movie_titlecontent_ratinggenresruntimetop_criticreview_contentrecommended
Deliver Us from EvilRAction & Adventure, Horror117.0TRUEDirector Scott Derrickson and his co-writer, Paul Harris Boardman, deliver a routine procedural with unremarkable frights.0
BarbaraPG-13Art House & International, Drama105.0FALSESomehow, in this stirring narrative, Barbara manages to keep hold of her principles, and her humanity and courage, and battles to save a dissident teenage girl whose life the Communists are trying to destroy.1
Horrible BossesRComedy98.0FALSEThese bosses cannot justify either murder or lasting comic memories, fatally compromising a farce that could have been great but ends up merely mediocre.0

下载数据集样本:https://ludwig.ai/latest/data/rotten_tomatoes.csv

wget https://ludwig.ai/latest/data/rotten_tomatoes.csv

接下来创建一个 YAML 配置文件,model.yaml其名称如下:

input_features:
  - name: genres
    type: set
    preprocessing:
      tokenizer: comma
  - name: content_rating
    type: category
  - name: top_critic
    type: binary
  - name: runtime
    type: number
  - name: review_content
    type: text
    encoder:
      type: embed
output_features:
  - name: recommended
    type: binary

就这样!现在让我们训练模型:

ludwig train --config model.yaml --dataset rotten_tomatoes.csv

五、为什么你应该使用 Ludwig ❓

  • 最少的机器学习样板
    Ludwig 开箱即用地解决了机器学习的工程复杂性,使研究科学家能够专注于构建最高抽象级别的模型。数据预处理、超参数优化、设备管理和 torch.nn.Module模型的分布式训练完全免费。
  • 轻松建立基准
    创建最先进的基线并将其与新模型进行比较是一个简单的配置更改。
  • 轻松将新架构应用于多个问题和数据集
    在 Ludwig 支持的大量任务和数据集中应用新模型。Ludwig 包含一个 可供任何用户使用的完整基准测试工具包,只需进行简单的配置即可在多个数据集上使用多个模型运行实验。
  • 高度可配置的数据预处理、建模和指标
    可以将模型架构、训练循环、超参数搜索和后端基础架构的任何方面作为声明性配置中的附加字段进行修改,以自定义管道以满足您的要求。有关可配置内容的详细信息,请查看 Ludwig 配置 文档。
  • 开箱即用的多模式、多任务学习
    无需编写代码,即可将表格数据、文本、图像甚至音频混合并匹配到复杂的模型配置中。
  • 丰富的模型导出和追踪
    使用 Tensorboard、Comet ML、Weights & Biases、MLFlow 和 Aim Stack 等工具自动跟踪所有试验和指标。
  • 自动将训练扩展到多 GPU、多节点集群
    无需更改代码,即可从本地机器上的训练转移到云端。
  • 适用于最先进模型的低代码接口,包括预先训练的 Huggingface Transformers
    Ludwig 还原生集成了预训练模型,例如Huggingface Transformers中提供的模型。用户可以从大量最先进的预训练 PyTorch 模型中进行选择,而无需编写任何代码。例如,使用 Ludwig 训练基于 BERT 的情绪分析模型非常简单:
ludwig train --dataset sst5 --config_str "{input_features: [{name: sentence, type: text, encoder: bert}], output_features: [{name: label, type: category}]}"
  • AutoML 的低代码界面
    Ludwig AutoML 允许用户仅提供数据集、目标列和时间预算即可获得训练有素的模型。
auto_train_results = ludwig.automl.auto_train(dataset=my_dataset_df, target=target_column_name, time_limit_s=7200)
  • 轻松实现生产化
    Ludwig 可轻松为深度学习模型(包括 GPU)提供服务。为经过训练的 Ludwig 模型启动 REST API。
ludwig serve --model_path=/path/to/model

ludwig 支持将模型导出到高效的 Torchscript 包。

ludwig export_torchscript -–model_path=/path/to/model

六、详细教程 📚


七、使用示例 🔬


八、更多信息 💡

阅读我们关于Ludwig声明式 MLLudwig 的 SoTA 基准的出版物。

进一步了解Ludwig 的工作原理如何开始使用以及了解更多示例

如果您有兴趣做出贡献,有问题、意见或想法要分享,或者您只是想知道最新情况,请考虑加入我们的社区 Discord并在X上关注我们!


2024-05-24(五)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程乐园

请我喝杯伯爵奶茶~!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值