A DiT video-generation acceleration framework for 265× faster inference
English | 简体中文
News
Overview
SparkDiffusion is a video-generation acceleration framework for Diffusion
Transformer (DiT) models. It combines sparse low-rank attention (RoLa),
few-step distillation (CrossDistill), and custom high-performance operators to deliver 200×+ end-to-end inference speedups over the dense multi-step baseline, while preserving generation quality.
The framework targets the Wan 2.1 and Wan 2.2 video diffusion models and provides
an end-to-end pipeline: sparse-attention finetuning, few-step distillation, and
optimized single-case T2V/I2V inference. It also ships optional weight-activation
quantization and self-developed inference operators that require no external
sparse-attention checkout.
Demo
Resources
Model Weights
All released checkpoints are available in the
SparkDiffusion Hugging Face collection:
Highlights
- 200×+ inference acceleration through joint sparse attention, low-rank
factorization, and few-step distillation.
- RoLa sparse low-rank attention — an efficient attention design usable for
both training (finetuning/distillation) and inference.
- CrossDistill few-step distillation — trajectory-level hybrid distillation
that balances generation quality and diversity.
- Custom high-performance operators under
sparkdiffusion/ops/,
self-developed and dependency-free at inference time.
- Wan 2.1 & Wan 2.2 support for both T2V and I2V, with dense/sparse/distilled
checkpoints comparable through the same inference wrappers.
- Pluggable sparse-attention registry so custom attention variants integrate
without touching the core training/distillation/inference code.
Repository Layout
| Path |
Purpose |
sparkdiffusion/ |
Model, sampler, dataset, checkpoint, inference, and operator code |
imaginaire/ |
Training framework and configuration utilities |
scripts/sparse_finetune/ |
Wan 2.1/2.2 sparse finetuning launchers |
scripts/distill/ |
Distillation launchers for supported configurations |
scripts/inference/ |
Single-case shell wrappers for inference |
datasets/distill/ |
Local distillation dataset mount point |
datasets/rola/ |
Local sparse-finetuning dataset mount point |
pretrain_weights/ |
Local pretrained model mount point |
outputs/distill/ |
Distillation outputs |
outputs/rola/ |
Sparse-finetuning outputs |
Weights, datasets, checkpoints, and generated videos are intentionally not
included in the repository.
Requirements
- Linux with a CUDA-capable GPU
- Python 3.10 or newer
- A CUDA-compatible PyTorch installation
- Triton,
flash-attn, and the packages listed in requirements.txt
Install the Python dependencies after installing the CUDA-matched PyTorch:
pip install -r requirements.txt
source scripts/env.sh
scripts/env.sh adds the repository to PYTHONPATH, enables offline defaults
for Hugging Face and W&B, and defines repository-relative data/output roots.
Override any root when local storage is elsewhere:
PRETRAIN_ROOT=/path/to/pretrain_weights \
DISTILL_DATA_ROOT=/path/to/distill_data \
ROLA_DATA_ROOT=/path/to/rola_data \
DISTILL_OUTPUT_ROOT=/path/to/distill_outputs \
ROLA_OUTPUT_ROOT=/path/to/rola_outputs \
source scripts/env.sh
Quick Start
The inference examples below use Wan 2.1 T2V at 480p. You need:
- A native Wan 2.1 T2V model repository containing the VAE, T5 encoder,
tokenizer, and base DiT assets.
- A compatible SparkDiffusion checkpoint from the
SparkDiffusion Hugging Face collection,
such as
SparkWan2.1-T2V-14B-480P-0.90Sparsity.
- A CUDA-capable GPU. Use
fp8 on GPUs with FP8 Tensor Core support; use
bf16 otherwise.
Clone the repository and install a CUDA-matched PyTorch and a compatible
flash-attn build before installing the remaining dependencies:
git clone git@github.com:AlibabaResearch/SparkDiffusion.git
cd SparkDiffusion
pip install -r requirements.txt
source scripts/env.sh
Place the native Wan assets under pretrain_weights/, for example:
pretrain_weights/
└── Wan2.1-T2V-14B/
├── Wan2.1_VAE.pth
├── models_t5_umt5-xxl-enc-bf16.pth
├── google/umt5-xxl/
└── diffusion_pytorch_model-*.safetensors
Download the SparkDiffusion checkpoint separately and set DIT_PATH to its
checkpoint file or directory. Then run three sequential samples in one process
to see the warmup and steady-state timings:
NUM_SAMPLES=3 SEED=0 \
DIT_PATH=/path/to/SparkWan2.1-T2V-14B-480P-0.90Sparsity \
bash scripts/inference/eval_student_2pt1_distilled.sh \
pretrain_weights/Wan2.1-T2V-14B \
outputs/inference/quickstart \
4 fp8 14B_rola 0.1 "" \
"A cat playing in the garden under the sun."
The first sample is labeled warmup and may include compilation or kernel
autotuning. Later samples are labeled after warmup and are the appropriate
ones for steady-state latency comparisons. Generated videos are saved under
outputs/inference/quickstart; with NUM_SAMPLES=3, each sample is saved
separately with a _sample_<index>_seed_<seed> suffix.
Community Integrations
- ComfyUI-SparkDiffusion:
An independently maintained ComfyUI integration that runs the official
SparkDiffusion inference entry points in an isolated Python runtime, with
T2V/I2V nodes and example workflows. Tested on an RTX 5090 with WSL2 and an
experimental Windows-native compatibility backend. See the linked repository
for installation, validated model/backend combinations, and limitations.
Data and Weights
Use the following layout convention:
pretrain_weights/
Wan2.1-T2V-14B/
Wan2.1-I2V-14B-480P/
Wan2.2-T2V-A14B/
datasets/
distill/
rola/
outputs/
distill/
rola/
Wan 2.1 native repositories keep the DiT safetensors, Wan2.1_VAE.pth,
models_t5_umt5-xxl-enc-bf16.pth, and google/umt5-xxl directly under the
model root; I2V repositories additionally contain the native CLIP .pth.
Wan 2.2 native repositories keep shared assets at the root and the two DiT
experts under high_noise_model/ and low_noise_model/.
The exact dataset shard names are experiment-specific. Set DATASET for sparse
finetuning or DATASET_ROOT for distillation when using a different layout.
Sparse Finetuning
Wan 2.1:
SLA_SRC=path/to/SLA MAX_ITER=250 SAVE_ITER=50 \
bash scripts/sparse_finetune/run_finetune_2pt1.sh
Wan 2.2 high-noise and low-noise experts with a native model repository:
export SLA_SRC=path/to/SLA
MAX_ITER=250 SAVE_ITER=50 EXPERT=high bash scripts/sparse_finetune/run_finetune_2pt2.sh
MAX_ITER=250 SAVE_ITER=50 EXPERT=low bash scripts/sparse_finetune/run_finetune_2pt2.sh
Use EXPERT=joint for the joint two-expert training path. Use
EXPERT=both to launch high-noise and low-noise training sequentially.
RoLa training requires SLA_SRC to point to the external SLA checkout before
launch; every training launcher validates it before starting torchrun.
Important overrides include PRETRAINED_CKPT, DATASET, NUM_GPUS,
MAX_ITER, SAVE_ITER, BATCH_SIZE, LR, and EXPERIMENT.
MAX_ITER sets the total number of optimizer update steps, and SAVE_ITER
sets the checkpoint interval in optimizer steps. Override these variables to
choose your own training length and save interval.
Pretrained checkpoint (PRETRAINED_CKPT)
The finetuning loader auto-detects the checkpoint format and adapts the state
dict. Point PRETRAINED_CKPT at the path required by your format:
| Format |
Required path |
| Native Wan 2.1 (default) |
The model repository directory, e.g. pretrain_weights/Wan2.1-T2V-1.3B, containing diffusion_pytorch_model.safetensors (optionally sharded with a *.index.json). You may also pass the .safetensors file directly. |
| Native Wan 2.2 |
The required expert directory, e.g. pretrain_weights/Wan2.2-T2V-A14B/high_noise_model or low_noise_model, each containing native sharded safetensors. |
.pth / .pt |
A Wan-official or SparkDiffusion training checkpoint file. |
| DCP |
A distributed-checkpoint directory containing *.distcp shards. |
By default the launchers load the native Wan repository directory. If the
path or format is wrong, loading fails fast: when a checkpoint matches zero
backbone parameters the loader raises an error (instead of silently training
from random weights), and a partial match logs a warning.
Note: RoLa sparse parameters (proj_q, proj_k, gate_proj, gate_bias)
are newly added and are expected to be missing from a stock checkpoint; they
start at random init and are trained during finetuning. Only missing
backbone weights indicate a wrong path/format.
Distillation
The supported distillation launchers are grouped under scripts/distill/:
export SLA_SRC=path/to/SLA
bash scripts/distill/wan2.1_14b_t2v_480p.sh
bash scripts/distill/wan2.1_14b_i2v_480p.sh
STUDENT_CKPT=path/to/high_noise_student.pth \
STUDENT_CKPT_LOW=path/to/low_noise_student.pth \
DATASET_ROOT=path/to/distillation_dataset \
bash scripts/distill/wan2.2_a14b_t2v_480p_joint.sh
Each launcher uses repository-relative defaults. Override WAN_REPO,
STUDENT_CKPT, TEACHER_CKPT, DATASET_ROOT, NEG_EMBED, and
OUTPUT_ROOT for a different local layout. The Wan 2.2 joint launcher loads
both noise experts in one process (also TEACHER_CKPT_LOW / STUDENT_CKPT_LOW).
The VAE, text encoder, tokenizer, and DiT paths can be overridden independently: