xDiT Unified Runner

July 9, 2026 · View on GitHub

The xDiT Unified Runner provides a single entry point for running all supported diffusion models with proper benchmarking and profiling support.

Overview

The unified runner provides:

  • Single CLI interface for all supported models
  • Programmatic API for integration into custom code
  • Built-in benchmarking with timing measurements
  • Profiling support via PyTorch profiler
  • Automatic validation of model capabilities and arguments
  • Parallelization across all supported models

Quick Start

Basic Usage

Run any supported model using xdit:

xdit --model FLUX.1-dev \
    --prompt "A cat running in a garden" \
    --ulysses_degree 8

This will generate an image with Flux.1-dev and uses the model-specific values for any parameters that were not provided.

Architecture

The unified runner consists of three main components:

1. Runner (xfuser/runner.py)

The main entry point that users interact with. It handles:

  • Argument parsing and validation
  • Model selection from the registry
  • Execution flow (initialization → run/profile → save → cleanup)
# api_example.py
# Usage: torchrun --nproc_per_node=4 api_example.py

from xfuser.runner import xFuserModelRunner

# Programmatic usage
config = {
    "model": "FLUX.1-dev",
    "prompt": "A cat running",
    "ulysses_degree": 4,
}
runner = xFuserModelRunner(config)
input_args = runner.preprocess_args(config)
runner.initialize(input_args)
output, timings = runner.run(input_args)
runner.save(output=output, timings=timings)
runner.cleanup()

2. Base Model (xfuser/model_executor/models/runner_models/base_model.py)

Contains all shared logic for model operations, e.g:

  • Model loading and initialization
  • Benchmarking and timing
  • Profiling with PyTorch profiler
  • Output saving
  • Torch compilation
  • Warmup calls
  • All other generic features

3. Model Implementations

Individual model classes that inherit from xFuserModel:

  • Define model-specific loading logic
  • Implement the inference pipeline
  • Specify default values and capabilities
  • Override base methods when needed for custom features

Supported Models

ModelValid Model Name(s)
FLUX.1-devFLUX.1-dev, black-forest-labs/FLUX.1-dev
FLUX.1-KontextFLUX.1-Kontext-dev, black-forest-labs/FLUX.1-Kontext-dev
FLUX.2FLUX.2-dev, black-forest-labs/FLUX.2-dev
FLUX.2-kleinFLUX.2-klein-9B, black-forest-labs/FLUX.2-klein-9B
HunyuanVideoHunyuanVideo, tencent/HunyuanVideo
HunyuanVideo-1.5HunyuanVideo-1.5, tencent/HunyuanVideo-1.5
Wan 2.1/2.2 I2VWan2.1-I2V, Wan2.2-I2V, Wan-AI/Wan2.1-I2V-14B-720P-Diffusers, Wan-AI/Wan2.2-I2V-A14B-Diffusers
Wan 2.2 Distilled I2V (LightX2V 4-step)Wan2.2-Distilled-I2V
Wan 2.1/2.2 T2VWan2.1-T2V, Wan2.2-T2V, Wan-AI/Wan2.1-T2V-14B-720P-Diffusers, Wan-AI/Wan2.2-T2V-A14B-Diffusers
Wan 2.1 VACEWan2.1-VACE-14B, Wan2.1-VACE-1.3B, Wan-AI/Wan2.1-VACE-14B, Wan-AI/Wan2.1-VACE-1.3B
Stable Diffusion 3SD3.5, stabilityai/stable-diffusion-3.5-large
Z-Image-TurboZ-Image-Turbo, Tongyi-MAI/Z-Image-Turbo
LTX-2LTX-2, Lightricks/LTX-2
Qwen-ImageQwen-Image, Qwen/Qwen-Image, Qwen-Image-2512, Qwen/Qwen-Image-2512
Qwen-Image-EditQwen-Image-Edit, Qwen/Qwen-Image-Edit, Qwen-Image-Edit-2509, Qwen/Qwen-Image-Edit-2509, Qwen-Image-Edit-2511, Qwen/Qwen-Image-Edit-2511
Krea2-Rawkrea/krea-2-raw, krea/Krea-2-Raw, Krea-2-Raw
Krea2-Turbokrea/krea-2-turbo, krea/Krea-2-Turbo, Krea-2-Turbo

CLI Arguments

Note: not all models support all of the features.

Model Selection

ArgumentDescription
--modelModel name or HuggingFace path (required)
--taskTask type for multi-task models

Parallelization

ArgumentDescriptionDefault
--ulysses_degreeUlysses sequence parallel degree1
--ring_degreeRing sequence parallel degree1
--pipefusion_parallel_degreePipeFusion pipeline stages1
--tensor_parallel_degreeTensor parallel degree1
--data_parallel_degreeData parallel degree1
--use_cfg_parallelEnable CFG parallelFalse
--use_parallel_vaeEnable parallel VAEFalse
--fully_shard_degreeFSDP sharding degree; set to number of GPUs to shard across. 1 disables sharding.1
--no_reshard_after_forwardKeep parameters gathered after each block forward; trades memory for latencyFalse
--memory_efficient_shardingLoad transformer blocks one at a time during init to reduce peak GPU memory; requires --fully_shard_degree > 1False

Input Parameters

ArgumentDescriptionDefault
--promptText prompt(s) for generation-
--negative_promptNegative prompt(s)-
--heightOutput heightModel-specific
--widthOutput widthModel-specific
--num_framesNumber of frames for video modelsModel-specific
--num_inference_stepsDenoising stepsModel-specific
--guidance_scaleClassifier-free guidance scaleModel-specific
--max_sequence_lengthMaximum sequence lengthModel-specific
--seedRandom seed for reproducibility42
--input_imagesInput image paths for image-to-image/video[]

Optimization Options

ArgumentDescriptionDefault
--use_torch_compileEnable torch.compile accelerationFalse
--use_fp8_gemmsEnable FP8 GEMM quantizationFalse
--enable_tilingEnable VAE tilingFalse
--enable_slicingEnable VAE slicingFalse
--enable_model_cpu_offloadEnable model CPU offloadFalse
--enable_sequential_cpu_offloadEnable sequential CPU offloadFalse
--attention_backendAttention backend selectionNone

Model-specific Arguments

ArgumentDescriptionRequired for
--distilled_transformer_pathPath to the high-noise distilled transformer safetensorsWan2.2-Distilled-I2V
--distilled_transformer_2_pathPath to the low-noise distilled transformer safetensorsWan2.2-Distilled-I2V

Benchmarking

ArgumentDescriptionDefault
--num_iterationsNumber of benchmark iterations1
--warmup_callsWarmup iterations before timing0
--batch_sizeBatch size for dataset inferenceNone
--dataset_pathPath to prompt dataset csvNone
--output_directoryOutput save directory.

Profiling

ArgumentDescriptionDefault
--profileEnable PyTorch profilerFalse
--profile_waitProfiler wait steps2
--profile_warmupProfiler warmup steps2
--profile_activeProfiler active steps1

Examples

Multi-GPU Image Generation

xdit --model FLUX.1-dev \
    --prompt "A majestic mountain landscape at sunset" \
    --height 1024 \
    --width 1024 \
    --ulysses_degree 4 \
    --num_inference_steps 50

Video Generation

xdit --model HunyuanVideo \
    --prompt "A cat playing with a ball" \
    --height 720 \
    --width 1280 \
    --num_frames 49 \
    --ulysses_degree 8

Distilled Video Generation

xdit --model Wan2.2-Distilled-I2V \
    --distilled_transformer_path   /path/to/wan2.2_i2v_A14b_high_noise_lightx2v_4step_720p_260412.safetensors \
    --distilled_transformer_2_path /path/to/wan2.2_i2v_A14b_low_noise_lightx2v_4step_720p_260412.safetensors \
    --input_images /path/to/image.jpg \
    --prompt "A cat walking in a garden" \
    --ulysses_degree 8

Benchmarking with Multiple Iterations

xdit --model FLUX.1-dev \
    --prompt "Benchmark test image" \
    --ulysses_degree 8 \
    --num_iterations 5 \
    --output_directory ./benchmark_results

Profiling

xdit --model FLUX.1-dev \
    --prompt "Profile test" \
    --ulysses_degree 8 \
    --profile \
    --output_directory ./profile_results

With Torch Compile

xdit --model FLUX.1-dev \
    --prompt "Compiled inference test" \
    --ulysses_degree 4 \
    --use_torch_compile

Dataset Inference

xdit --model FLUX.1-dev \
    --dataset_path ./prompts.csv \  # CSV file with at least column "prompt"
    --batch_size 4 \
    --ulysses_degree 8 \
    --output_directory ./dataset_outputs

Programmatic Usage

The runner can be imported and used programmatically:

from xfuser.runner import xFuserModelRunner

# Configuration dictionary
config = {
    "model": "FLUX.1-dev",
    "prompt": "A beautiful garden with flowers",
    "height": 1024,
    "width": 1024,
    "ulysses_degree": 4,
    "num_inference_steps": 50,
    "seed": 42,
    "output_directory": "./outputs",
}

# Create runner
runner = xFuserModelRunner(config)

# Preprocess arguments (applies model defaults)
input_args = runner.preprocess_args(config)

# Initialize model
runner.initialize(input_args)

# Run inference
output, timings = runner.run(input_args)

# Save outputs
runner.save(output=output, timings=timings)

# Cleanup
runner.cleanup()

Profiling Programmatically

runner = xFuserModelRunner(config)
input_args = runner.preprocess_args(config)
runner.initialize(input_args)

# Profile instead of run
output, timings, profile = runner.profile(input_args)
runner.save(profile=profile)

runner.cleanup()

Output Files

The runner saves outputs to the specified --output_directory:

FileDescription
{model}_u{ulysses}r{ring}_tc_{compile}_{height}x{width}_{index}.pngGenerated images
{model}_u{ulysses}r{ring}_tc_{compile}_{height}x{width}_{index}.mp4Generated videos
timings.jsonTiming measurements for each iteration
profile_trace_rank_{rank}.jsonChrome trace file for profiling

Saved outputs depend on the input arguments used.