How decentralised-ai/wan2gp works
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: __init__.py Model router · gradio Web UI · utils Shared core · wgp.py wgp.py
Components 20
Entry & runtime
Launcher and execution modes
- wgp.py · Main entrypoint that starts UI or headless batch execution
wgp.py
Shared core
Cross-model orchestration, UI helpers, downloads, and common math
- Web UI · Interactive request composition, queue editing, and asset management
shared/gradio - Shared core · Prompt parsing, downloads, motion/media helpers, LoRA handling, schedulers, and common math
shared/utils - Model router · Normalizes requests and routes them to the selected family handler
models/__init__.py
Model families
Family-specific runtimes, handlers, and pipelines
- Wan · Primary multi-mode Wan pipelines and specialized variants
models/wan - Hunyuan · Hunyuan video pipelines, audio conditioning, and prompt rewrite path
models/hyvideo - Flux · Flux and Flux2 inference stack with adapters, sampling, and text encoders
models/flux - Qwen Image · Qwen image generation and edit pipelines
models/qwen - Z-Image · Z-Image transformer, sampler, and output pipeline
models/z_image - Kandinsky 5 · Kandinsky pipelines for text-to-image, image-to-image, and video generation
models/kandinsky5 - LTX Video · LTX video pipelines, autoencoders, schedulers, and prompt enhancement
models/ltx_video - LTX2 · LTX2 core model, loaders, conditioning, and multi-stage pipelines
models/ltx2 - LongCat · LongCat avatar and video models with audio process and sparse attention
models/longcat - Chatterbox · Speech generation, voice conversion, and TTS pipelines
models/chatterbox
Media tooling
Preprocessing and postprocessing toolchains for conditioning and delivery
- Preprocess · Depth, pose, canny, flow, face, scribble, audio extraction, and motion preparation
preprocessing - Postprocess · Frame interpolation, audio/video alignment, film grain, and MMAudio workflows
postprocessing
Extensions
Optional UI and app plugins plus custom model artifacts
Config & storage
File-driven presets, profiles, checkpoints, outputs, and local metadata
- Presets · Model defaults and named profiles defining behavior, quantization, and step settings
defaults - Local storage · Downloaded checkpoints, outputs, caches, queues, and metadata on disk
Connections 30
- 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