Papers

13 - 最终成果说明

已完成内容汇总

本项目在 6 周(2026-06-06 至 2026-06-07)内完成了计划中的 17/18 个任务。以下按分类列出所有产出。

知识库 (docs/) - 13 页 + 首页

编号页面内容状态
-index.html知识库首页导航已完成
0101_任务总览.html项目目标、路线选择、成果总览已完成
0202_老引擎审计.htmlminivLLM 复用决策(T3)已完成
0303_现代diffusion推理最小背景.html推理数据流入门(T5)已完成
0404_rectified_flow和flow_matching.htmlRectified Flow 理论 + toy 实现(T8)已完成
0505_diffusion_transformer架构.htmlDiT 架构(T8)已完成
0606_stable_diffusion_3_mmdit.htmlSD3 MMDiT 详解(T8)已完成
0707_flux和现代文生图推理.htmlFLUX 推理系统(T8)已完成
0808_sana高效高分辨率生成.htmlSana 高效架构(T8)已完成
0909_sora_style视频生成架构.htmlSora-style 视频架构(T15)已完成
1010_wan_hunyuan_cogvideox_ltx视频模型.html视频模型对比(T15)已完成
1111_diffusion推理系统优化.html系统优化技术 + 与 LLM 差异(T18)已完成
1212_diffusion_gemma.htmlDiffusionGemma 架构与推理已完成
1313_最终成果说明.html本页,成果汇总(T18)已完成

学习资料 - 20 篇

自写引擎 - 10 个模块 + 36 个测试

实验 - 5 个实验目录

报告 - 8 份

如何运行

Toy Rectified Flow

# 2D 矢量场仿真,输出 trajectory PNG + JSON
python experiments/toy_rectified_flow/infer_toy_flow.py --seed 0 --steps 8 --output_dir results

Toy DiT Inference

# 最小 DiT denoising loop,输出 64x64 图像
python experiments/toy_dit_inference/infer_tiny_dit.py --device cpu --steps 8

Reference Image Inference(环境就绪后)

# Sana 0.6B(首选验证项,Apache 2.0,无需授权)
python experiments/reference_image_inference/run_sana_if_possible.py \
  --prompt "一只柴犬在樱花树下"

# SD3 Medium(需 HF token + license accept)
python experiments/reference_image_inference/run_sd3_medium_if_possible.py \
  --prompt "一只柴犬在樱花树下" --no_t5

# FLUX.1-schnell(需 HF token + license accept,4 steps)
python experiments/reference_image_inference/run_flux_schnell_if_possible.py \
  --prompt "一只柴犬在樱花树下"

Reference Video Inference(环境就绪后)

# CogVideoX-2B(首选验证项,Apache 2.0)
python experiments/reference_video_inference/run_cogvideox_if_possible.py \
  --prompt "一只猫在草地上奔跑" --num_frames 16 --width 256 --height 256

# LTX-Video 2B distilled(备选验证项,开放协议)
python experiments/reference_video_inference/run_ltx_video_if_possible.py \
  --prompt "一只猫在草地上奔跑" --num_frames 16 --width 256 --height 256

系统优化 Benchmark

python experiments/diffusion_inference_optimization/run_all_benchmarks.py

测试

python -m pytest diffusion_engine/tests -q

已知限制

环境限制

模型与显存限制

实现限制

下一步计划

短期(环境就绪后)

  1. 在远程 CUDA GPU 上安装 Python 3.13 + torch + diffusers
  2. 跑通 run_sana_if_possible.py(Sana 0.6B,无授权障碍,显存友好)
  3. 跑通 run_cogvideox_if_possible.py(CogVideoX-2B,小规格 16f×256²)
  4. 用真实 GPU 数据替换 T14/T15 的 blocker 文件

中期(优化集成)

  1. 接入 xformers 或 flash-attn,实测 memory-efficient attention 在一块可用的 CUDA GPU 上的加速比
  2. 测试 torch.compile 对 DiT transformer block 的加速效果
  3. 评估 MPS 后端在 Apple M5 上的 attention 性能(能否达到 toy 实验可用)

长期(生产化)

  1. 自定义 kernel(Triton):为 DiT/MMDiT 写针对 Blackwell 架构优化的 attention kernel
  2. TensorRT 部署:将 DiT 模型导出为 TensorRT engine,实现低延迟 serving
  3. 服务框架:参考 vLLM 的 serving 架构,为扩散模型设计类似的服务系统(Ray Serve 或其他)
  4. 多 GPU / 模型并行:探索如何将单个扩散模型的推理分布在多张 GPU 上

结论

6 周内完成了 17/18 个任务,包括 13 页静态文档、20 篇学习资料、10 个模块(36 个测试)、5 组实验目录和 8 份报告。远程 GPU 环境尚未就绪,真实 reference inference 因此没有运行;执行脚本已经准备好。系统实验记录了 prompt embedding cache(52% hit)、latent buffer(91.8% allocation 节省)和 CFG batching(1.01-1.02× 加速)。attention memory 按 O(N²) 增长,显存受限时生成高分辨率图像需要 memory-efficient attention。

和我的 diffusion_engine 的关系

本页汇总全部产出并提供运行命令。扩散引擎的实现细节分布在 02-11 各页中:02(为什么新建)、03(数据流)、04-05(算法)、06-08(模型对比)、09-10(视频)、11(系统优化);README.md 提供快速运行命令。