How hao-ai-lab/fastvideo works
1. What this repo is
FastVideo is a multi-surface video generation platform centered on one Python package (fastvideo) plus a native kernel package (fastvideo-kernel). It supports both inference/serving and post-training (fine-tuning, LoRA, distillation, self-forcing), with shared model, attention, dataset, and pipeline abstractions reused across all of those paths.
2. Core architectural boundary
The main package is split into clear layers: configuration, model implementations, pipeline orchestration, attention/backends, training, data, and runtime/distributed execution. Most model families (Wan, Hunyuan, LTX2, Gen3C, LongCat, Cosmos, SD3, MatrixGame, etc.) plug into the same pipeline/stage system rather than duplicating end-to-end application logic.
3. Inference request flow
Inference enters through the CLI, the Python VideoGenerator API, or the OpenAI-compatible server under fastvideo/entrypoints/openai. Requests are parsed into schema objects, routed through the pipeline registry, then executed by a model-specific pipeline that assembles text/image/video encoders, VAE, denoiser, scheduler, and decoding stages before returning video artifacts.
4. Pipeline/stage orchestration
fastvideo/pipelines is the central orchestration layer. It composes reusable stages for input validation, text/image encoding, latent preparation, conditioning, denoising, and decoding, with specialized variants for causal, I2V, V2V, SR, and model-specific behaviors. This is the best place to diagram “shared workflow skeleton” versus “model-specific branches.”
5. Model family implementations
fastvideo/models contains the actual architecture implementations for each supported family. The subtrees for dits, encoders, vaes, schedulers, upsamplers, and camera/world-model utilities define the learned components, while fastvideo/configs maps those components into concrete model/pipeline presets. The same loader/registry machinery is used to instantiate these components across models.
6. Attention and acceleration stack
Attention is a first-class boundary in this repo. fastvideo/attention/backends selects among multiple implementations such as FlashAttention, SDPA, Sage, Sliding Tile Attention, Video Sparse Attention, block-sparse attention, and VMOBA, while fastvideo-kernel provides compiled CUDA/Triton/C++ kernels for the performance-critical pieces. Python code usually selects the backend, and the native package executes the fast path.
7. Distributed execution and hardware abstraction
Distributed inference/training is handled by fastvideo/distributed and fastvideo/worker, with CPU/CUDA/MPS/ROCm/NPU platform abstractions in fastvideo/platforms. The repo supports both multi-GPU sequence parallelism and backend-specific communication paths, with executor implementations for local multiprocessing and Ray-based distributed runs.
8. Training subsystem
Training is a separate but aligned subsystem under fastvideo/train and fastvideo/training. It includes fine-tuning, LoRA, knowledge distillation, distribution matching/DMD2, and self-forcing pipelines, plus callbacks for EMA, gradient clipping, validation, checkpointing, and tracking. Training flows reuse many of the same model and pipeline components as inference, but add optimizer/config/checkpoint orchestration and distributed training mechanics.
9. Data and preprocessing flow
Data handling runs through fastvideo/dataset and fastvideo/workflow/preprocess. The repo supports Parquet-based datasets, latent/precomputed datasets, validation datasets, and record schemas, with preprocessing workflows that convert raw video/image/text inputs into training-ready artifacts. Scripts and examples show this as a separate offline pipeline feeding the training jobs.
10. Native and model-serving integrations
There are two additional integration surfaces: ComfyUI under comfyui/ for node-based local generation, and the web UI under ui/ for dataset/job management. These are not the core engine, but both depend on the same model/training/preprocessing concepts and expose them through different interaction models.
11. Benchmarks, evaluation, and quality gates
Evaluation is split into FVD benchmarking under benchmarks/fvd, similarity/SSIM tests, and a broad test suite for API, attention, distributed execution, inference, training, and VAE/model parity. This repo treats performance and correctness as part of the architecture, not just build metadata.
12. Tooling, examples, and release automation
examples/ and scripts/ provide concrete recipes for inference, finetuning, distillation, dataset prep, checkpoint conversion, and Hugging Face upload/download. CI/CD is handled by GitHub Actions and Buildkite, and the docs tree mirrors the same architecture so diagrams should reflect that the repo is designed as a platform with reusable components, not a single application.
Main entry points: train Training · models Models · pipeline_registry.py Pipeline registry · attention Attention
Components 23
Core engine
Shared Python package for inference, training, data, and model orchestration.
- API schema · Parsers, schemas, errors, and result objects for external request handling.
fastvideo/api - Pipeline registry · Maps configs and request types to the appropriate composed pipeline.
fastvideo/pipelines/pipeline_registry.py - Pipeline core · Shared pipeline base, batch metadata, and composition helpers.
fastvideo/pipelines - Stages · Reusable input, encoding, conditioning, denoising, and decoding stages.
fastvideo/pipelines/stages - Model pipelines · Wan, Hunyuan, LTX2, Gen3C, LongCat, Cosmos, SD3, Gamecraft, and MatrixGame pipeline variants.
fastvideo/pipelines/basic - Configs · Model, pipeline, sample, and backend configuration presets.
fastvideo/configs - Models · Implementation of encoders, VAEs, schedulers, DiTs, and domain-specific model code.
fastvideo/models - Attention · Backend abstraction and implementations for attention kernels.
fastvideo/attention - Distributed · Sequence parallelism, device communicators, and distributed state.
fastvideo/distributed - Workers · Local multiprocessing, GPU worker, and Ray-based execution backends.
fastvideo/worker - Training · Fine-tuning, LoRA, distillation, self-forcing, checkpoints, callbacks, and trainers.
fastvideo/train - Train pipelines · Higher-level training and distillation pipelines shared across methods and models.
fastvideo/training - Dataset · Parquet datasets, latent datasets, validation sets, schemas, and transforms.
fastvideo/dataset - Preprocess flow · Workflow layer for turning raw media into training-ready artifacts.
fastvideo/workflow/preprocess
Native acceleration
Compiled kernels and their Python bindings.
- Kernel Python · Python wrappers for CUDA/Triton/C++ acceleration ops.
fastvideo-kernel/python/fastvideo_kernel - Kernel C++/CUDA · Attention and turbo-diffusion kernels implemented in C++, CUDA, and Triton support code.
fastvideo-kernel/csrc
Entry surfaces
Command-line, API, and UI integration points.
- CLI · Generate, serve, and benchmark commands for local use.
fastvideo/entrypoints/cli - OpenAI server · OpenAI-compatible inference server and protocol handlers.
fastvideo/entrypoints/openai - Video API · Python-facing generation API used by scripts, CLI, and serving layers.
fastvideo/entrypoints/video_generator.py - ComfyUI · Node-based local generation integration built on the same engine and configs.
comfyui - Web UI · Browser-based interface for datasets, jobs, finetuning, inference, and settings.
ui
Tooling
Examples, benchmarks, scripts, and quality gates.
- Benchmarks · FVD, similarity, performance, and parity checks used as quality gates.
benchmarks - Scripts · Inference, finetune, distill, preprocess, conversion, and Hugging Face utilities.
scripts
Connections 30
- CLI → API schema: parses · CLI commands turn user inputs into typed request objects.
- CLI → Pipeline registry: dispatches · CLI generation and serving commands select the right pipeline.
- OpenAI server → API schema: validates · OpenAI endpoints normalize incoming requests into schema objects.
- OpenAI server → Pipeline registry: routes · Server requests are mapped to model-appropriate pipelines.
- Video API → Pipeline registry: invokes · Python API uses the same registry as CLI and server surfaces.
- Pipeline registry → Pipeline core: instantiates · Registry creates composed pipelines from configuration and request intent.
- Pipeline core → Stages: composes · Pipelines assemble reusable stage graphs for generation and preprocessing.
- Pipeline core → Model pipelines: specializes · Shared workflow skeleton branches into family-specific pipelines.
- Model pipelines → Models: uses · Pipelines call into the underlying model implementations.
- Model pipelines → Attention: selects · Pipelines and models choose an attention backend when executing.
- Configs → Pipeline registry: drives · Configuration presets determine which pipeline and components are loaded.
- Configs → Models: maps · Model presets bind names to concrete encoders, VAEs, schedulers, and DiTs.
- Configs → Attention: configures · Backend presets select attention implementations and fast paths.
- Attention → Kernel Python: binds · Python backend selection reaches compiled bindings when available.
- Kernel Python → Kernel C++/CUDA: executes · Bindings expose the native CUDA/Triton/C++ kernels.
- Distributed → Workers: orchestrates · Distributed state and communicators coordinate worker execution.
- Workers → Models: runs · Workers host model execution for local and distributed inference/training.
- Training → Dataset: consumes · Training methods use datasets, schemas, and preprocessing outputs.
- Training → Models: fine-tunes · Training methods reuse the same model components as inference.
- Training → Distributed: uses · Training can run with parallel and device-specific communication paths.
- Train pipelines → Training: coordinates · Higher-level pipelines organize method-specific training runs.
- Preprocess flow → Dataset: produces · Offline preprocessing creates training-ready records and artifacts.
- ComfyUI → Video API: wraps · ComfyUI nodes delegate to the shared generation API and loaders.
- Web UI → Preprocess flow: manages · Web UI surfaces dataset and preprocessing job workflows.
- Web UI → Training: launches · Web UI exposes job management for finetuning and related runs.
- Benchmarks → Models: evaluates · Benchmark and parity checks compare model outputs and performance.
- Benchmarks → Attention: profiles · Performance checks include attention backend behavior and speed.
- Scripts → Preprocess flow: drives · Scripts materialize preprocessing and dataset preparation recipes.
- Scripts → Training: launches · Scripts provide finetune, distill, and inference runbooks.
- Scripts → Models: converts · Checkpoint conversion and HF utilities target model artifacts.