pipelines
src/diffusers/pipelines/ 数百文件,几十个 pipeline 子目录 | 推理/训练入口,把 text encode、循环去噪、image/audio decode 编排成端到端 pipeline;每个模型族一个子目录(stable_diffusion、flux、qwen_image、hunyuan_video、cosmos 等) 入口:DiffusionPipeline(base pipeline)、StableDiffusionPipeline、FluxPipeline、QwenImagePipeline、HunyuanVideoPipeline、CosmosPredict25Pipeline、各 pipeline 子类的 __call__ / call() 依赖:schedulers, models, utils, loaders README 与 release 0.41.0(QwenImage 2.1)、0.40.0(tensor-parallel support)、0.39.0(new image and video pipelines)都以此为核心;tests/pipelines/、tests/modular_pipelines/ 是回归重点;提交热点 docs/source 主要就是 pipeline 文档 |
schedulers
src/diffusers/schedulers/ 数十文件 | 噪声调度抽象,定义 timestep、noise scale、step() 更新规则;是 Diffusers 三大可插拔组件之一 入口:SchedulerMixin / DiffusionScheduler、DDPMScheduler、DDIMScheduler、FlowMatchEulerDiscreteScheduler、AmusedScheduler、UnCLIPScheduler 依赖:utils FlowMatchEulerDiscreteScheduler 在 Flux/SD3 等新模型中大量使用;scripts/convert_*.py 常直接引用具体 scheduler 类做验证;CONTRIBUTING 列出「New scheduler」是官方贡献路径 |
models
src/diffusers/models/ 数百文件,是 src 中最大子目录 | 所有扩散模型 backbone:UNet、DiT、Transformer、VAE/Autoencoder、prior;按 unets/、transformers/、autoencoders/ 分目录 入口:UNet2DConditionModel、FluxTransformer2DModel、QwenImageTransformer2DModel、HunyuanVideoTransformer3DModel、AutoencoderKL、AutoencoderKLQwenImage 依赖:utils, quantization tests/models 提交热点 9 次;新模型(QwenImage 2.1、Anima、Cosmos、CogVideo)都在此新增;attention pattern、LoRA target module 命名都从这里定义 |
modular_pipelines
src/diffusers/modular_pipelines/ 数十文件 | Modular Diffusers 机制,把 pipeline 拆成可组合子图(blocks),支持跨模型复用与自动组装 入口:ModularPipeline、BasePipelineBlock、各 block 子类 依赖:pipelines, models, schedulers docs/source 重点模块,tests/modular_pipelines 单独测试套件,0.39+ 持续投入;AGENTS.md 引用 references/modular.md |
loaders
src/diffusers/loaders/ 数十文件 | LoRA、LoKr、IP-Adapter、Textual Inversion、ControlNet 等权重注入与合并;是扩展已有 pipeline 而不改模型本体的关键层 入口:LoraLoaderMixin、LoKrLoaderMixin、IPAdapterMixin、PeftAdapterMixin 等 mixin 依赖:models, utils 最近提交「[LoRA] add LoKr adapter support (Z-Image, Flux2/Klein)」(#14163) 和「Fix active adapter detection for text encoders」(#14961) 都在此 |
quantization
src/diffusers/quantization/ 数十文件 | 8-bit / 4-bit 量化后端(bitsandbytes、GGUF 等),让大模型在有限显存下运行 入口:BitsAndBytesConfig、GGUFQuantizationConfig、PipelineQuantizationMixin 依赖:models, utils tests/quantization/ 独立测试;examples/research_projects/flux_lora_quantization/ 有端到端示例;与端侧部署(TensorRT、量化)直接相关 |
utils
src/diffusers/utils/ 数十文件 | 设备映射(device_map)、动态 import、dummy 对象、日志、hub 调用等横切基础设施 入口:is_torch_cuda_available、get_device_map、logging、push_to_hub、BaseOutput 依赖:无(底层) 最近提交「Make Stable Diffusion device-map comparisons deterministic」(#15010) 在此;dummy_*.py 让 CPU 环境可 import |
hooks
src/diffusers/hooks/ 数十文件 | pipeline/model 行为注入点:回调、注册、替换子模块前/后处理;用于性能优化、Profiler、自定义调度 入口:HookRegistry、register_pipeline_hook、register_model_hook 依赖:pipelines, models examples/profiling/ 使用;是扩展 pipeline 不改源码的官方方式 |
attention_processor
src/diffusers/models/attention_processor.py 单文件但核心 | 注意力实现调度中心:xformers、FlashAttention、SDPA、Triton 等 backend 都通过这里挂入 入口:AttentionProcessor、AttnProcessor2_0、XFormersAttnProcessor、FlashAttnProcessor 依赖:models 对 GPU kernel 工程师是最接近「kernel 层」的入口;TensorRT/FlashAttention 适配都改这里 |
training_scripts
examples/ 464 文件 | DreamBooth、ControlNet、LoRA、Cosmos、CogVideo 等训练/推理模板,覆盖 SD1.5/SDXL/Flux/SD3/QwenImage 等主流模型 入口:train_dreambooth_lora_flux.py、train_controlnet.py、train_text_to_image.py、train_cogvideox_lora.py、train_cosmos_predict25_lora.py 依赖:pipelines, models, loaders examples 目录是「没有 GPU 也能读」的最佳入口;advanced_diffusion_training/、research_projects/ 有高级优化 |
conversion_scripts
scripts/ 96 文件 | 把外部 checkpoint(原始训练格式)转成 Diffusers 目录结构;96 个脚本几乎覆盖所有主流扩散模型 入口:convert_flux_to_diffusers.py、convert_sd3_to_diffusers.py、convert_cogvideox_to_diffusers.py、convert_qwen_image_to_diffusers.py(需验证) 依赖:pipelines, models, schedulers 新增模型必先走这里;脚本头部有完整命令行示例,可直接在 CPU 跑 |
tests
tests/ 628 文件 | 回归防线:按 models/、pipelines/、schedulers/、quantization/、modular_pipelines/ 分套件 入口:tests/models/、tests/pipelines/、tests/schedulers/、tests/quantization/、conftest.py 依赖:所有 src 模块 提交热点 tests/models 9 次、tests/pipelines 2 次;conftest.py 有 dummy device 支持 CPU 运行 |
benchmarks
benchmarks/ 10 文件 | 推理性能对比:Flux、LTX、SDXL、Wan 等模型的标准 benchmark 入口:benchmarking_flux.py、benchmarking_ltx.py、benchmarking_sdxl.py、benchmarking_wan.py、run_all.py 依赖:pipelines 对性能工程师友好;可在 Colab T4 上做最终确认 |
docker
docker/ 8 文件 | 预构建镜像:CPU、CUDA、ONNX Runtime、TensorRT、xformers 等组合 入口:diffusers-pytorch-cuda、diffusers-onnxruntime-cuda、diffusers-pytorch-cpu 等 Dockerfile 依赖:pipelines 端侧部署(TensorRT、ONNX)参考;无 GPU 可用 diffusers-pytorch-cpu |
ai_agent_skills
src/diffusers/commands/ 与 .ai/skills 数十文件 | diffusers-cli 与 AI agent(Claude Code、Codex、Cursor)的 skills 系统,把贡献规范、模型集成、pipeline 编写等封装成可调用技能 入口:diffusers-cli skills list/add/update、SKILL.md、AGENTS.md 依赖:所有 src 模块 AGENTS.md 明确指向 references/ 下的 code_style.md、models.md、pipelines.md、modular.md、testing.md |
docs
docs/source/ 512 文件 | Sphinx 文档源;提交热点 24 次,是全仓库最活跃目录 入口:_toctree.yml、各 pipeline/model/scheduler 的 md/rst 依赖:pipelines, models, schedulers Modular Diffusers、Optimization、Training 等章节是深入理解架构的最佳读物 |