Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
Ludwig 是一个声明式深度学习框架,让你通过 YAML 配置文件和零样板 Python 代码来训练、微调并部署 AI 模型——从 LLM 微调到表格分类均可覆盖。
# Fine-tune Llama-3.1 with LoRA in one config file
model_type: llm
base_model: meta-llama/Llama-3.1-8B
adapter:
type: lora
trainer:
type: finetune
epochs: 3
input_features:
- name: instruction
type: text
output_features:
- name: response
type: text
ludwig train --config model.yaml --dataset my_data.csv
技术栈: Python 3.12 · PyTorch 2.7+ · Pydantic 2 · Transformers 5 · Ray 2.54
Ludwig 由 Linux Foundation AI & Data. 托管。
| 功能 | 说明 |
|---|---|
| PatchTST 与 N-BEATS 编码器 | 配备 MASE/sMAPE 指标的最先进时间序列预测编码器 |
| 高级 PEFT 适配器 | PiSSA、EVA、CorDA/LoftQ 初始化器;TinyLoRA、OFT、HRA、WaveFT、LN-Tuning、VBLoRA、C3A 适配器类型 |
| VLM 微调 | 通过 is_multimodal: true,配合门控交叉注意力训练 LLaVA、Qwen2-VL、InternVL |
| HyperNetwork 组合器 | 基于条件的特征融合——由一个特征为其他特征生成权重 |
| Nash-MTL 与 Pareto-MTL | 基于博弈论与偏好的多任务损失平衡 |
| LLM 配置生成 | ludwig generate_config "describe your task" — 由 LLM 为你编写 YAML |
| ModelInspector | 架构分析、权重收集、特征重要性代理 |
| Ray Serve 与 KServe | 分布式与 Kubernetes 原生的模型部署适配层 |
| GRPO 对齐 | 通过 Group Relative Policy Optimization 实现无奖励模型的 RLHF |
| torchao 量化 + QAT | PyTorch 原生的 int4/int8/float8,支持量化感知训练(Quantization-Aware Training) |
| 多适配器 PEFT | 多个命名的 LoRA 适配器,支持加权合并(TIES、DARE、SVD) |
| 原生 Optuna 执行器 | GPT/TPE/CMA-ES 采样器、剪枝、可恢复的 SQLite/PostgreSQL 存储 |
| 时间序列预测 | model.forecast(dataset, horizon=N) API,配合 TimeseriesOutputFeature |
| Muon 与 ScheduleFreeAdamW | 面向大规模预训练与微调的新优化器 |
| 图像分割解码器 | 用于语义分割的 UNet、SegFormer、FPN 解码器 |
pip install ludwig # core
pip install ludwig[full] # all optional dependencies
pip install ludwig[llm] # LLM fine-tuning only
需要 Python 3.12+。完整依赖矩阵见 contributing。
Ludwig 支持完整的 LLM 微调技术谱系:
| 技术 | 配置键 |
|---|---|
| 监督微调(SFT) | trainer.type: finetune |
| DPO / KTO / ORPO / GRPO 对齐 | trainer.type: dpo(或 kto、orpo、grpo) |
| LoRA / DoRA / VeRA / PiSSA | adapter.type: lora(或 dora、vera、lora + init_weights: pissa) |
| 4-bit QLoRA(bitsandbytes) | quantization.bits: 4 |
| torchao + QAT | quantization.backend: torchao |
| 多适配器合并 | adapters: dict + merge: block |
| VLM(视觉-语言) | is_multimodal: true |
model_type: llm
base_model: meta-llama/Llama-3.1-8B
quantization:
bits: 4
adapter:
type: lora
prompt:
template: |
### 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
backend:
type: local
export HUGGING_FACE_HUB_TOKEN="<your_token>"
ludwig train --config model.yaml --dataset "ludwig://alpaca"
input_features:
- name: review_text
type: text
encoder:
type: bert
- name: star_rating
type: number
- name: product_image
type: image
encoder:
type: dinov2
output_features:
- name: recommended
type: binary
ludwig train --config model.yaml --dataset reviews.csv
ludwig generate_config "I have a CSV with age, income, education level, and I want to predict loan default"
ludwig predict --model_path results/experiment_run/model --dataset new_data.csv
ludwig serve --model_path results/experiment_run/model
# POST http://localhost:8000/predict
is_multimodal: true 微调 LLaVA、Qwen2-VL、InternVLmodel.forecast() APIludwig serve)torch.export .pt2 bundles、ONNXludwig upload hf_hub — 推送模型并自动生成 model cardModelInspector — 权重枚举、架构摘要、特征重要性代理(feature importance proxy)ludwig.automl.auto_train() — 提供数据集与时间预算;YAML 驱动的搜索空间会采样 encoder/combiner/decoder 组合,并在训练前进行验证from ludwig.utils.dataset_quality import check_dataset_quality — 在训练前验证 DataFrame(缺失值、类别不平衡、近重复列、ID 泄漏等)OpenMLLoader 按任务 ID 获取并本地缓存为 Parquetludwig generate_config "describe your task" — 由 LLM 编写 YAMLludwig experiment --k_fold Nludwig://mnist、ludwig://alpaca 等)| 用例 | 链接 |
|---|---|
| LLM 指令微调(LoRA + QLoRA) | examples/llm |
| DPO / GRPO 对齐 | examples/llm/alignment |
| 高级 PEFT(PiSSA、OFT、VBLoRA 等) | examples/llms/peft_advanced |
| VLM 微调(LLaVA、Qwen2-VL) | examples/vlm |
| 用例 | 链接 |
|---|---|
| 二分类(Titanic) | examples/titanic |
| 表格分类(census income) | examples/adult_census_income |
| 多模态分类 | examples/multimodal_classification |
| 多任务学习 | examples/multi_task |
| 用例 | 链接 |
|---|---|
| 时间序列预测(PatchTST、N-BEATS) | examples/forecasting |
| 天气预报 | examples/weather |
| 图像分类(MNIST) | examples/mnist |
| 语义分割 | examples/semantic_segmentation |
| 用例 | 链接 |
|---|---|
| 文本分类 | examples/text_classification |
| 命名实体识别 | examples/ner_tagging |
| 机器翻译 | examples/machine_translation |
| 语音识别 | examples/speech_recognition |
| 说话人验证 | examples/speaker_verification |
backend.type,从笔记本 → 多 GPU → Ray 集群无缝扩展。ludwig visualize 对比实验。