Skip to main content

SaddleLLM

SaddleLLM 是一个面向本地研究与工程实验的大语言模型训练工具包,覆盖数据检查、训练规划、SFT、偏好优化、RL/GRPO、评估、蒸馏、量化和部署等流程。

当前版本:2.31

建议先运行环境检查、数据检查和 dry-run,再启动真实训练。仓库包含稳定主线和实验性模块,并非所有功能都适合直接用于大规模生产训练。

主要能力

  • 训练工厂:领域工作区、Recipe、Orchestrator 和实验产物管理
  • 数据处理:SFT、DPO、ORPO、KTO、RL/GRPO 和 VLA 数据检查与规范化
  • 后训练:Full Fine-tuning、LoRA、QLoRA、SFT 和 preference optimization
  • 强化学习:native GRPO、可验证奖励和 source-frontier profiling
  • 模型实验:Dense、GQA、MoE、MLA、MTP 和 Long Context blueprint
  • 评估与诊断:Benchmark、训练报告、环境检查和 smoke test
  • 模型工程:蒸馏、量化、剪枝、部署和安全生成
  • 多模态/VLA:提供实验性的数据、模型和训练入口

环境要求

  • Python >=3.8;建议使用 Python 3.10+
  • PyTorch
  • Transformers
  • Datasets
  • PEFT
  • TRL
  • NVIDIA GPU(真实模型训练建议使用)

部分后端能力还需要 DeepSpeed、bitsandbytes、xFormers、flash-attn 或其他可选依赖。

安装

建议在独立虚拟环境中使用:

python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -e .

验证安装:

python -c "import saddle_llm; print(saddle_llm.__version__)"
saddle-llm --help

如果不安装 console script,也可以使用:

python -m saddle_llm.cli --help

最短上手流程

1. 检查环境

saddle-llm doctor
saddle-llm doctor --output build\doctor_report.json

2. 运行内置 smoke test

saddle-llm smoke-test --in-process --skip-doctor `
  --work-dir build\smoke_e2e_fast

只检查 fixture、数据和配置,不执行训练:

saddle-llm smoke-test --skip-training

3. 检查训练数据

saddle-llm inspect-data data\sft.jsonl --task sft
saddle-llm inspect-data data\preference.jsonl --task dpo
saddle-llm inspect-data data\rl.jsonl --task grpo

4. 检查并编译配置

仓库提供了以下模板:

  • configs/sft_lora.yaml
  • configs/dpo_qlora.yaml
  • configs/preflight.yaml
  • configs/vla_sft.yaml
  • configs/mopd_sft.yaml
saddle-llm validate-config configs\sft_lora.yaml
saddle-llm plan configs\sft_lora.yaml

5. Dry-run 和训练

saddle-llm train configs\sft_lora.yaml --dry-run
saddle-llm train configs\sft_lora.yaml

训练失败时显示完整 traceback:

saddle-llm train configs\sft_lora.yaml --debug

推荐顺序:

doctor
  -> smoke-test --skip-training
  -> inspect-data
  -> validate-config
  -> preflight
  -> plan
  -> train --dry-run
  -> train
  -> report

Python API

创建领域训练工厂

from saddle_llm import LLMTrainingFactory

factory = LLMTrainingFactory.for_domain(
    domain="general",
    root_dir="./llm_factory",
    base_model="Qwen/Qwen2.5-7B-Instruct",
    max_seq_length=2048,
    global_batch_size=16,
    num_gpus=1,
    gpu_memory_gb=24.0,
)

factory.create_workspace()
factory.save_plan()

创建 SFT 计划

plan = factory.create_post_training_plan(
    data_path="./data/sft.jsonl",
    stage="sft",
    method="qlora",
    max_steps=1000,
    save=True,
)

该调用会生成规范化数据、Recipe、Orchestrator config 和训练计划。

创建 DPO 计划

plan = factory.create_post_training_plan(
    data_path="./data/preference.jsonl",
    stage="dpo",
    method="qlora",
    beta=0.1,
    save=True,
)

执行 Orchestrator 配置

from saddle_llm import TrainingOrchestrator

orchestrator = TrainingOrchestrator.from_yaml("./configs/train.yaml")
result = orchestrator.run()

数据格式

SFT:Alpaca JSONL

{"instruction":"总结下面的政策意见","input":"...","output":"..."}

SFT:Messages JSONL

{"messages":[{"role":"user","content":"..."},{"role":"assistant","content":"..."}]}

Preference:DPO/ORPO JSONL

{"prompt":"...","chosen":"更好的回答","rejected":"较差的回答"}

在加载模型前运行 inspect-data,可以检查字段、重复样本、长度和 chosen == rejected 等问题。

测试

python -m pytest -q

当前项目级 pytest.ini 会排除 build/dist/external_research/,避免测试发现过程进入第三方研究仓库。

目录结构

configs/                    训练 Recipe 模板
experiments/                可执行实验
outputs/                    实验输出
saddle_llm/                 Python 包源码
tests/                      项目测试
SADDLE_LLM_FULL_DOCUMENTATION.md
SADDLE_LLM_CODE_GUIDE.md
TRAINING_GUIDE.md

文档导航

当前边界

  • CLI、数据检查、Recipe、Orchestrator 和 smoke-test 是推荐入口。
  • native GRPO 适合小规模研究和链路验证;大规模实验应进一步验证吞吐、分布式和 checkpoint 行为。
  • VLA、多模态、部分高级架构及部分第三方后端仍属于实验性能力。

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saddlellm-2.31-py3-none-any.whl (419.9 kB view details)

Uploaded Python 3

File details

Details for the file saddlellm-2.31-py3-none-any.whl.

File metadata

  • Download URL: saddlellm-2.31-py3-none-any.whl
  • Upload date:
  • Size: 419.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0rc2

File hashes

Hashes for saddlellm-2.31-py3-none-any.whl
Algorithm Hash digest
SHA256 8bca4a1a4bc7184bca5adea3916f9654d973354ddc493bfbd11c64cf3f3f2d21
MD5 2a58f57a025e75d7d35b1d5102b07b66
BLAKE2b-256 e55fafb71e14f1fa7d1aa52bf7e6126452c8946ddbda57420cb8e7b701cc90a2

See more details on using hashes here.

Release history Release notifications | RSS feed

2.33

1 file

2.32

1 file

This release

2.31 This release

1 file

2.30.0

1 file

2.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page