# hao-ai-lab/fastvideo architecture

> Architecture diagram of the GitHub repository hao-ai-lab/fastvideo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hao-ai-lab/fastvideo
- Repository: https://github.com/hao-ai-lab/fastvideo

## Overview

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: [`fastvideo/train`](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/train) (Training), [`fastvideo/models`](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/models) (Models), [`fastvideo/pipelines/pipeline_registry.py`](https://github.com/hao-ai-lab/fastvideo/blob/main/fastvideo/pipelines/pipeline_registry.py) (Pipeline registry), [`fastvideo/attention`](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/attention) (Attention)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core engine"]
  node_api_schema["API schema<br/>request/response types"]
  node_pipeline_registry["Pipeline registry<br/>routing layer"]
  node_pipelines_core["Pipeline core<br/>workflow orchestration"]
  node_stages["Stages"]
  node_model_pipelines["Model pipelines<br/>family-specific flows"]
  node_configs["Configs<br/>model presets"]
  node_models["Models<br/>architectures"]
  node_attention{{"Attention<br/>backend selector"}}
  node_distributed["Distributed<br/>parallel runtime"]
  node_worker["Workers<br/>execution runtime"]
  node_training["Training"]
  node_training_pipelines["Train pipelines<br/>training flows"]
  node_dataset[("Dataset<br/>data layer")]
  node_workflow_preprocess["Preprocess flow<br/>offline pipeline"]
end

subgraph group_native["Native acceleration"]
  node_kernel_python["Kernel Python<br/>native bindings"]
  node_kernel_csrc{{"Kernel C++/CUDA<br/>compiled ops"}}
end

subgraph group_surfaces["Entry surfaces"]
  node_entry_cli["CLI<br/>command entrypoint"]
  node_entry_openai["OpenAI server<br/>HTTP serving"]
  node_video_api["Video API<br/>generator API<br/>[video_generator.py]"]
  node_comfyui["ComfyUI<br/>node integration"]
  node_ui["Web UI<br/>job dashboard"]
end

subgraph group_tooling["Tooling"]
  node_benchmarks["Benchmarks<br/>evaluation suite"]
  node_scripts["Scripts<br/>ops recipes"]
end

node_entry_cli -->|"parses"| node_api_schema
node_entry_cli -->|"dispatches"| node_pipeline_registry
node_entry_openai -->|"validates"| node_api_schema
node_entry_openai -->|"routes"| node_pipeline_registry
node_video_api -->|"invokes"| node_pipeline_registry
node_pipeline_registry -->|"instantiates"| node_pipelines_core
node_pipelines_core -->|"composes"| node_stages
node_pipelines_core -->|"specializes"| node_model_pipelines
node_model_pipelines -->|"uses"| node_models
node_model_pipelines -->|"selects"| node_attention
node_configs -->|"drives"| node_pipeline_registry
node_configs -->|"maps"| node_models
node_configs -->|"configures"| node_attention
node_attention -->|"binds"| node_kernel_python
node_kernel_python -->|"executes"| node_kernel_csrc
node_distributed -->|"orchestrates"| node_worker
node_worker -->|"runs"| node_models
node_training -->|"consumes"| node_dataset
node_training -->|"fine-tunes"| node_models
node_training -->|"uses"| node_distributed
node_training_pipelines -->|"coordinates"| node_training
node_workflow_preprocess -->|"produces"| node_dataset
node_comfyui -->|"wraps"| node_video_api
node_ui -->|"manages"| node_workflow_preprocess
node_ui -->|"launches"| node_training
node_benchmarks -->|"evaluates"| node_models
node_benchmarks -->|"profiles"| node_attention
node_scripts -->|"drives"| node_workflow_preprocess
node_scripts -->|"launches"| node_training
node_scripts -->|"converts"| node_models

click node_api_schema "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/api"
click node_entry_cli "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/entrypoints/cli"
click node_entry_openai "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/entrypoints/openai"
click node_video_api "https://github.com/hao-ai-lab/fastvideo/blob/main/fastvideo/entrypoints/video_generator.py"
click node_pipeline_registry "https://github.com/hao-ai-lab/fastvideo/blob/main/fastvideo/pipelines/pipeline_registry.py"
click node_pipelines_core "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines"
click node_stages "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines/stages"
click node_model_pipelines "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines/basic"
click node_configs "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/configs"
click node_models "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/models"
click node_attention "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/attention"
click node_distributed "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/distributed"
click node_worker "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/worker"
click node_training "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/train"
click node_training_pipelines "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/training"
click node_dataset "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/dataset"
click node_workflow_preprocess "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/workflow/preprocess"
click node_kernel_python "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo-kernel/python/fastvideo_kernel"
click node_kernel_csrc "https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo-kernel/csrc"
click node_comfyui "https://github.com/hao-ai-lab/fastvideo/tree/main/comfyui"
click node_ui "https://github.com/hao-ai-lab/fastvideo/tree/main/ui"
click node_benchmarks "https://github.com/hao-ai-lab/fastvideo/tree/main/benchmarks"
click node_scripts "https://github.com/hao-ai-lab/fastvideo/tree/main/scripts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_schema,node_pipeline_registry,node_pipelines_core,node_stages,node_model_pipelines,node_configs,node_models,node_attention,node_distributed,node_worker,node_training,node_training_pipelines,node_dataset,node_workflow_preprocess toneBlue
class node_kernel_python,node_kernel_csrc toneAmber
class node_entry_cli,node_entry_openai,node_video_api,node_comfyui,node_ui toneMint
class node_benchmarks,node_scripts toneRose
```

## Components

### Core engine

Shared Python package for inference, training, data, and model orchestration.

- [API schema](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/api): request/response types · Parsers, schemas, errors, and result objects for external request handling. · `fastvideo/api`
- [Pipeline registry](https://github.com/hao-ai-lab/fastvideo/blob/main/fastvideo/pipelines/pipeline_registry.py): routing layer · Maps configs and request types to the appropriate composed pipeline. · `fastvideo/pipelines/pipeline_registry.py`
- [Pipeline core](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines): workflow orchestration · Shared pipeline base, batch metadata, and composition helpers. · `fastvideo/pipelines`
- [Stages](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines/stages): workflow stages · Reusable input, encoding, conditioning, denoising, and decoding stages. · `fastvideo/pipelines/stages`
- [Model pipelines](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/pipelines/basic): family-specific flows · Wan, Hunyuan, LTX2, Gen3C, LongCat, Cosmos, SD3, Gamecraft, and MatrixGame pipeline variants. · `fastvideo/pipelines/basic`
- [Configs](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/configs): model presets · Model, pipeline, sample, and backend configuration presets. · `fastvideo/configs`
- [Models](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/models): architectures · Implementation of encoders, VAEs, schedulers, DiTs, and domain-specific model code. · `fastvideo/models`
- [Attention](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/attention): backend selector · Backend abstraction and implementations for attention kernels. · `fastvideo/attention`
- [Distributed](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/distributed): parallel runtime · Sequence parallelism, device communicators, and distributed state. · `fastvideo/distributed`
- [Workers](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/worker): execution runtime · Local multiprocessing, GPU worker, and Ray-based execution backends. · `fastvideo/worker`
- [Training](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/train): training subsystem · Fine-tuning, LoRA, distillation, self-forcing, checkpoints, callbacks, and trainers. · `fastvideo/train`
- [Train pipelines](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/training): training flows · Higher-level training and distillation pipelines shared across methods and models. · `fastvideo/training`
- [Dataset](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/dataset): data layer · Parquet datasets, latent datasets, validation sets, schemas, and transforms. · `fastvideo/dataset`
- [Preprocess flow](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/workflow/preprocess): offline pipeline · Workflow layer for turning raw media into training-ready artifacts. · `fastvideo/workflow/preprocess`

### Native acceleration

Compiled kernels and their Python bindings.

- [Kernel Python](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo-kernel/python/fastvideo_kernel): native bindings · Python wrappers for CUDA/Triton/C++ acceleration ops. · `fastvideo-kernel/python/fastvideo_kernel`
- [Kernel C++/CUDA](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo-kernel/csrc): compiled ops · 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](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/entrypoints/cli): command entrypoint · Generate, serve, and benchmark commands for local use. · `fastvideo/entrypoints/cli`
- [OpenAI server](https://github.com/hao-ai-lab/fastvideo/tree/main/fastvideo/entrypoints/openai): HTTP serving · OpenAI-compatible inference server and protocol handlers. · `fastvideo/entrypoints/openai`
- [Video API](https://github.com/hao-ai-lab/fastvideo/blob/main/fastvideo/entrypoints/video_generator.py): generator API · Python-facing generation API used by scripts, CLI, and serving layers. · `fastvideo/entrypoints/video_generator.py`
- [ComfyUI](https://github.com/hao-ai-lab/fastvideo/tree/main/comfyui): node integration · Node-based local generation integration built on the same engine and configs. · `comfyui`
- [Web UI](https://github.com/hao-ai-lab/fastvideo/tree/main/ui): job dashboard · Browser-based interface for datasets, jobs, finetuning, inference, and settings. · `ui`

### Tooling

Examples, benchmarks, scripts, and quality gates.

- [Benchmarks](https://github.com/hao-ai-lab/fastvideo/tree/main/benchmarks): evaluation suite · FVD, similarity, performance, and parity checks used as quality gates. · `benchmarks`
- [Scripts](https://github.com/hao-ai-lab/fastvideo/tree/main/scripts): ops recipes · Inference, finetune, distill, preprocess, conversion, and Hugging Face utilities. · `scripts`

## Connections

- 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.
