# decentralised-ai/wan2gp architecture

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

- Interactive diagram: https://gitdiagram.com/decentralised-ai/wan2gp
- Repository: https://github.com/decentralised-ai/wan2gp

## Overview

WanGP is a multi-model generative inference host, not a single model app. Its architecture is centered on one launcher (`wgp.py`) that can either start the full web UI or run in headless batch mode from a saved queue/settings file.

The top-level system is split by capability rather than by UI layer: `models/` contains the model-specific runtimes and pipelines for each family; `shared/` contains cross-model orchestration, media utilities, downloads, prompt handling, scheduling, and common math/attention code; `preprocessing/` and `postprocessing/` wrap the tools used before and after generation; `plugins/` adds optional UI/app extensions; and `docs/`, `defaults/`, and `profiles/` hold user-facing configuration and presets.

The main runtime boundary is the model-family handlers. Each family has its own entry modules and often its own handler/pipeline stack: Wan, Hunyuan, Flux, Qwen, Z-Image, LongCat, Kandinsky 5, LTX Video/LTX2, and Chatterbox. These are not thin wrappers; each family has distinct transformer, VAE, scheduler, and conditioning code, which means the repo is effectively a federation of model implementations under one orchestration shell.

The application flow starts with a user request built in the UI or from a saved queue. That request is normalized by shared utilities, routed to the selected model handler, then passed into the model’s pipeline along with media inputs such as start images, reference images, masks, control videos, audio tracks, or trajectories. Output artifacts are written to local storage and then fed through optional postprocessing.

Media control is a major subsystem. The repo includes preprocessing for depth, pose, canny, flow, face encoding/alignment, scribble/mask tools, audio extraction, and specialized motion tooling. These preprocessors produce conditioning assets used by the generation pipelines, especially for video models that accept control frames, motion trajectories, or audio-driven guidance.

Postprocessing is equally explicit and separate from generation. It includes frame interpolation, audio/video alignment, film grain, and MMAudio-based audio-related workflows. This separation matters because the generator can emit raw video, intermediate latents, or preview outputs, while postprocessing turns those into deliverable media files.

The configuration model is file-driven. `defaults/` contains a large catalog of model presets, and `profiles/` contains named operational profiles such as step-count/distillation/accelerator combinations. These presets are the main way the app encodes model choice, quantization mode, VRAM profile, and generation behavior without hardcoding them into the UI.

Model customization is treated as first-class data, not code. `finetunes/` and the lora-related folders are intended for user-provided additions, while the shared utilities handle LoRA loading, multiplier logic, and text-encoder caching. In architecture terms, this makes the core pipelines parameterized by external artifacts stored on disk, rather than compiled into the program.

The plugin system is a separate extension boundary. Plugins under `plugins/` register additional tabs or tools in the UI, such as gallery browsing, downloads, model management, motion design, or mask creation. The plugin mechanism is important architecturally because it lets the UI grow without changing the core generation pipeline.

There is a clear operational split between interactive and batch processing. The Gradio-based web interface is used for composing requests, editing queues, and managing assets, while headless mode replays saved settings or queues directly through the same back-end path. That means the UI and CLI are different fronts on the same generation engine.

The repo is designed for local inference on consumer GPUs, with support for NVIDIA and AMD, multiple quantization formats, and memory-saving variants. Docker and the entrypoint scripts wrap environment setup, but the core architecture assumes local GPU execution with heavy use of PyTorch, CUDA/ROCm-specific dependencies, and media tooling like ffmpeg.

External dependencies are mostly model and asset distribution services rather than SaaS APIs. Hugging Face-style model downloads are a central part of the system’s bootstrap flow, and the repository is structured to auto-fetch checkpoints, VAE weights, encoders, and finetunes into local model directories. Generated assets, caches, and metadata remain on the local filesystem.

For a diagram, the key boundaries are: user interface and plugin layer; shared orchestration/utilities; family-specific model pipelines; preprocessing/postprocessing toolchains; and local persistence for models, presets, queues, outputs, and metadata. The overall shape is a modular inference platform that unifies many specialized generative models under one local GPU workflow.

Main entry points: [`models/__init__.py`](https://github.com/decentralised-ai/wan2gp/blob/main/models/__init__.py) (Model router), [`shared/gradio`](https://github.com/decentralised-ai/wan2gp/tree/main/shared/gradio) (Web UI), [`shared/utils`](https://github.com/decentralised-ai/wan2gp/tree/main/shared/utils) (Shared core), [`wgp.py`](https://github.com/decentralised-ai/wan2gp/blob/main/wgp.py) (wgp.py)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & runtime"]
  node_wgp["wgp.py<br/>launcher<br/>[wgp.py]"]
end

subgraph group_orchestration["Shared core"]
  node_gradio_ui["Web UI<br/>gradio frontend"]
  node_shared_core["Shared core<br/>orchestration utils"]
  node_model_dispatch{{"Model router<br/>dispatch boundary<br/>[__init__.py]"}}
end

subgraph group_models["Model families"]
  node_wan_model["Wan<br/>video family"]
  node_hyvideo_model["Hunyuan<br/>video family"]
  node_flux_model["Flux<br/>image family"]
  node_qwen_model["Qwen Image<br/>image family"]
  node_zimage_model["Z-Image<br/>image family"]
  node_kandinsky_model["Kandinsky 5<br/>video/image family"]
  node_ltxvideo_model["LTX Video<br/>video family"]
  node_ltx2_model["LTX2<br/>video family"]
  node_longcat_model["LongCat<br/>talking-head family"]
  node_chatterbox_model["Chatterbox<br/>tts/vc family"]
end

subgraph group_media["Media tooling"]
  node_preprocess["Preprocess<br/>conditioning tools"]
  node_postprocess["Postprocess<br/>delivery tools"]
end

subgraph group_ext["Extensions"]
  node_plugins["Plugins<br/>ui extensions"]
  node_finetunes["Finetunes<br/>user assets"]
end

subgraph group_data["Config & storage"]
  node_defaults_profiles["Presets<br/>config catalogs"]
  node_local_store[("Local storage<br/>filesystem cache")]
end

node_wgp -->|"interactive mode"| node_gradio_ui
node_wgp -->|"batch mode"| node_model_dispatch
node_gradio_ui -->|"submit request"| node_model_dispatch
node_model_dispatch -->|"normalize"| node_shared_core
node_model_dispatch -->|"route"| node_wan_model
node_model_dispatch -->|"route"| node_hyvideo_model
node_model_dispatch -->|"route"| node_flux_model
node_model_dispatch -->|"route"| node_qwen_model
node_model_dispatch -->|"route"| node_zimage_model
node_model_dispatch -->|"route"| node_kandinsky_model
node_model_dispatch -->|"route"| node_ltxvideo_model
node_model_dispatch -->|"route"| node_ltx2_model
node_model_dispatch -->|"route"| node_longcat_model
node_model_dispatch -->|"route"| node_chatterbox_model
node_preprocess -->|"conditioning assets"| node_model_dispatch
node_model_dispatch -->|"artifacts"| node_postprocess
node_plugins -->|"extend UI"| node_gradio_ui
node_finetunes -->|"load adapters"| node_shared_core
node_defaults_profiles -->|"preset config"| node_model_dispatch
node_shared_core -->|"download/cache"| node_local_store
node_wan_model -->|"weights & outputs"| node_local_store
node_hyvideo_model -->|"weights & outputs"| node_local_store
node_flux_model -->|"weights & outputs"| node_local_store
node_qwen_model -->|"weights & outputs"| node_local_store
node_zimage_model -->|"weights & outputs"| node_local_store
node_kandinsky_model -->|"weights & outputs"| node_local_store
node_ltxvideo_model -->|"weights & outputs"| node_local_store
node_ltx2_model -->|"weights & outputs"| node_local_store
node_longcat_model -->|"weights & outputs"| node_local_store
node_chatterbox_model -->|"weights & outputs"| node_local_store

click node_wgp "https://github.com/decentralised-ai/wan2gp/blob/main/wgp.py"
click node_gradio_ui "https://github.com/decentralised-ai/wan2gp/tree/main/shared/gradio"
click node_shared_core "https://github.com/decentralised-ai/wan2gp/tree/main/shared/utils"
click node_model_dispatch "https://github.com/decentralised-ai/wan2gp/blob/main/models/__init__.py"
click node_wan_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/wan"
click node_hyvideo_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/hyvideo"
click node_flux_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/flux"
click node_qwen_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/qwen"
click node_zimage_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/z_image"
click node_kandinsky_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/kandinsky5"
click node_ltxvideo_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/ltx_video"
click node_ltx2_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/ltx2"
click node_longcat_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/longcat"
click node_chatterbox_model "https://github.com/decentralised-ai/wan2gp/tree/main/models/chatterbox"
click node_preprocess "https://github.com/decentralised-ai/wan2gp/tree/main/preprocessing"
click node_postprocess "https://github.com/decentralised-ai/wan2gp/tree/main/postprocessing"
click node_plugins "https://github.com/decentralised-ai/wan2gp/tree/main/plugins"
click node_finetunes "https://github.com/decentralised-ai/wan2gp/tree/main/finetunes"
click node_defaults_profiles "https://github.com/decentralised-ai/wan2gp/tree/main/defaults"

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_wgp toneBlue
class node_gradio_ui,node_shared_core,node_model_dispatch toneAmber
class node_wan_model,node_hyvideo_model,node_flux_model,node_qwen_model,node_zimage_model,node_kandinsky_model,node_ltxvideo_model,node_ltx2_model,node_longcat_model,node_chatterbox_model toneMint
class node_preprocess,node_postprocess toneRose
class node_plugins,node_finetunes toneIndigo
class node_defaults_profiles,node_local_store toneTeal
```

## Components

### Entry & runtime

Launcher and execution modes

- [wgp.py](https://github.com/decentralised-ai/wan2gp/blob/main/wgp.py): launcher · Main entrypoint that starts UI or headless batch execution · `wgp.py`

### Shared core

Cross-model orchestration, UI helpers, downloads, and common math

- [Web UI](https://github.com/decentralised-ai/wan2gp/tree/main/shared/gradio): gradio frontend · Interactive request composition, queue editing, and asset management · `shared/gradio`
- [Shared core](https://github.com/decentralised-ai/wan2gp/tree/main/shared/utils): orchestration utils · Prompt parsing, downloads, motion/media helpers, LoRA handling, schedulers, and common math · `shared/utils`
- [Model router](https://github.com/decentralised-ai/wan2gp/blob/main/models/__init__.py): dispatch boundary · Normalizes requests and routes them to the selected family handler · `models/__init__.py`

### Model families

Family-specific runtimes, handlers, and pipelines

- [Wan](https://github.com/decentralised-ai/wan2gp/tree/main/models/wan): video family · Primary multi-mode Wan pipelines and specialized variants · `models/wan`
- [Hunyuan](https://github.com/decentralised-ai/wan2gp/tree/main/models/hyvideo): video family · Hunyuan video pipelines, audio conditioning, and prompt rewrite path · `models/hyvideo`
- [Flux](https://github.com/decentralised-ai/wan2gp/tree/main/models/flux): image family · Flux and Flux2 inference stack with adapters, sampling, and text encoders · `models/flux`
- [Qwen Image](https://github.com/decentralised-ai/wan2gp/tree/main/models/qwen): image family · Qwen image generation and edit pipelines · `models/qwen`
- [Z-Image](https://github.com/decentralised-ai/wan2gp/tree/main/models/z_image): image family · Z-Image transformer, sampler, and output pipeline · `models/z_image`
- [Kandinsky 5](https://github.com/decentralised-ai/wan2gp/tree/main/models/kandinsky5): video/image family · Kandinsky pipelines for text-to-image, image-to-image, and video generation · `models/kandinsky5`
- [LTX Video](https://github.com/decentralised-ai/wan2gp/tree/main/models/ltx_video): video family · LTX video pipelines, autoencoders, schedulers, and prompt enhancement · `models/ltx_video`
- [LTX2](https://github.com/decentralised-ai/wan2gp/tree/main/models/ltx2): video family · LTX2 core model, loaders, conditioning, and multi-stage pipelines · `models/ltx2`
- [LongCat](https://github.com/decentralised-ai/wan2gp/tree/main/models/longcat): talking-head family · LongCat avatar and video models with audio process and sparse attention · `models/longcat`
- [Chatterbox](https://github.com/decentralised-ai/wan2gp/tree/main/models/chatterbox): tts/vc family · Speech generation, voice conversion, and TTS pipelines · `models/chatterbox`

### Media tooling

Preprocessing and postprocessing toolchains for conditioning and delivery

- [Preprocess](https://github.com/decentralised-ai/wan2gp/tree/main/preprocessing): conditioning tools · Depth, pose, canny, flow, face, scribble, audio extraction, and motion preparation · `preprocessing`
- [Postprocess](https://github.com/decentralised-ai/wan2gp/tree/main/postprocessing): delivery tools · Frame interpolation, audio/video alignment, film grain, and MMAudio workflows · `postprocessing`

### Extensions

Optional UI and app plugins plus custom model artifacts

- [Plugins](https://github.com/decentralised-ai/wan2gp/tree/main/plugins): ui extensions · Optional tabs and tools such as gallery, downloads, model management, mask creation, and motion design · `plugins`
- [Finetunes](https://github.com/decentralised-ai/wan2gp/tree/main/finetunes): user assets · User-provided finetune artifacts and LoRAs consumed by shared loaders · `finetunes`

### Config & storage

File-driven presets, profiles, checkpoints, outputs, and local metadata

- [Presets](https://github.com/decentralised-ai/wan2gp/tree/main/defaults): config catalogs · Model defaults and named profiles defining behavior, quantization, and step settings · `defaults`
- **Local storage**: filesystem cache · Downloaded checkpoints, outputs, caches, queues, and metadata on disk

## Connections

- wgp.py → Web UI: interactive mode · Launches the web UI for request composition and queue management
- wgp.py → Model router: batch mode · Replays saved queue/settings directly through the back-end path
- Web UI → Model router: submit request · UI-built generation requests are normalized and routed to a handler
- Model router → Shared core: normalize · Uses shared orchestration, prompt, download, and scheduling utilities
- Model router → Wan: route · Selects Wan family pipelines and specialized variants
- Model router → Hunyuan: route · Selects Hunyuan family pipelines
- Model router → Flux: route · Selects Flux family pipelines
- Model router → Qwen Image: route · Selects Qwen image pipelines
- Model router → Z-Image: route · Selects Z-Image pipelines
- Model router → Kandinsky 5: route · Selects Kandinsky 5 pipelines
- Model router → LTX Video: route · Selects LTX Video pipelines
- Model router → LTX2: route · Selects LTX2 pipelines
- Model router → LongCat: route · Selects LongCat avatar/video pipelines
- Model router → Chatterbox: route · Selects speech and voice-conversion pipelines
- Preprocess → Model router: conditioning assets · Produces depth, pose, masks, flow, audio, and other conditioning inputs
- Model router → Postprocess: artifacts · Sends raw outputs to delivery-oriented postprocessing
- Plugins → Web UI: extend UI · Registers extra tabs and tools without changing the core engine
- Finetunes → Shared core: load adapters · External LoRAs and finetunes are loaded through shared utilities
- Presets → Model router: preset config · Feeds model choice, quantization, and generation behavior into routing
- Shared core → Local storage: download/cache · Manages local model downloads, caches, metadata, and generated files
- Wan → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Hunyuan → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Flux → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Qwen Image → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Z-Image → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Kandinsky 5 → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- LTX Video → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- LTX2 → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- LongCat → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
- Chatterbox → Local storage: weights & outputs · Reads checkpoints and writes generated media artifacts locally
