本节由 AI 整理生成,仅供参考。

#examples、scripts 和评测组件

##1. examples/

目录:

text
<repo>/examples/
├── a2d/
├── bert/
├── dream/
├── editflow/
├── fastdllm/
├── llada/
├── llada2/
├── llada21/
└── rl/

这是面向使用者的入口层。它们负责把模型、数据、训练器和 sampler 组合起来。

底层实现主要位于:

text
<repo>/dllm/

##2. examples/llada/

典型文件包括:

text
chat.py
sample.py
pt.py
sft.py
eval.sh
README.md

职责:

##3. 其他 examples 目录

目录 用途
<repo>/examples/a2d/ 将自回归模型改造成扩散模型
<repo>/examples/bert/ BERT-Chat 训练和推理
<repo>/examples/dream/ Dream 训练、推理和评测
<repo>/examples/editflow/ Edit Flow 训练和采样
<repo>/examples/fastdllm/ Fast-dLLM 加速推理和评测
<repo>/examples/llada2/ LLaDA2.0 推理
<repo>/examples/llada21/ LLaDA2.1 推理
<repo>/examples/rl/ diffu-GRPO 强化学习训练

##4. scripts/

目录:

text
<repo>/scripts/
├── accelerate_configs/
├── tests/
└── train.slurm.sh

##5. scripts/accelerate_configs/

放置 Hugging Face Accelerate 配置,用于控制分布式训练方式。

README 中提到的训练方式包括:

text
ddp
zero-1
zero-2
zero-3
fsdp

这些配置决定:

例如 FSDP 配置中可以看到:

##6. scripts/train.slurm.sh

这是 Slurm 集群启动脚本。

它负责:

  1. 申请节点和 GPU
  2. 读取 Slurm 分配的节点信息
  3. 计算 GPU 总数
  4. 设置 master address 和 port
  5. 选择 Accelerate 配置
  6. 调用 accelerate launch
  7. 将其他参数转发给具体训练脚本
  8. 保存任务日志

因此它主要解决“如何在集群上启动训练”,而不是“模型如何学习”。

##7. scripts/tests/

<repo>/pyproject.toml 中将其配置为 pytest 测试目录:

toml
testpaths = ["scripts/tests"]
python_files = ["test_*.py"]

因此测试文件通常命名为:

text
test_*.py

##8. lm-evaluation-harness/

这是一个外部评测框架子模块。

dLLM 自己负责扩散模型的推理适配,lm-evaluation-harness 负责标准 benchmark 的任务定义和评测执行。

README 提到的使用场景包括:

两者的关系是:

text
扩散模型专用 Eval Harness
    ↓
将模型包装成标准评测接口
    ↓
lm-evaluation-harness
    ↓
执行 benchmark 并统计结果

##9. assets/

用于项目展示和文档资源,例如:

这些资源通常不参与训练和推理。

##10. pyproject.toml

这是 Python 项目配置文件,负责:

核心依赖涉及:

可选依赖包括:

##11. 推荐阅读顺序

如果想快速理解代码,建议按以下顺序阅读:

  1. <repo>/README.md
  2. <repo>/examples/llada/sft.py
  3. <repo>/dllm/utils/configs.py
  4. <repo>/dllm/utils/models.py
  5. <repo>/dllm/data/
  6. <repo>/dllm/core/trainers/
  7. <repo>/dllm/core/samplers/
  8. <repo>/dllm/pipelines/llada/
  9. <repo>/scripts/accelerate_configs/

这个顺序是从“用户入口”逐步进入“公共框架”和“模型细节”。