Overview
Thesglang generate command runs inference on multimodal diffusion models. This command is currently supported only for diffusion models and provides a convenient way to generate images, videos, or other outputs without starting a server.
Basic Usage
Required Arguments
string
required
Path or name of the diffusion model to use. Can be:
- HuggingFace model ID (e.g.,
stabilityai/stable-diffusion-xl-base-1.0) - Local path to model directory
- ModelScope model ID (when using
SGLANG_USE_MODELSCOPE=1)
string
required
Text prompt describing what to generate.
Model Configuration
string
Path to a JSON or YAML configuration file containing model and generation parameters. When provided,
--model-path and --prompt become optional.string
Explicit model ID override (e.g., “Qwen-Image”).
string
default:"auto"
Model backend to use. Options:
auto: Automatically select backend (prefer sglang native, fallback to diffusers)sglang: Use sglang’s native optimized implementationdiffusers: Use vanilla diffusers pipeline (supports all diffusers models)
boolean
default:"false"
Trust remote code from HuggingFace.
string
Model revision (branch/tag name or commit ID).
Sampling Parameters
Generation Settings
string
Negative prompt to guide what not to generate.
integer
default:"50"
Number of denoising steps. More steps generally produce higher quality but take longer.
float
default:"7.5"
Guidance scale for classifier-free guidance. Higher values follow the prompt more closely.
integer
Output height in pixels.
integer
Output width in pixels.
integer
Random seed for reproducibility.
Batch Generation
integer
default:"1"
Number of samples to generate.
Parallelism Options
integer
default:"1"
Number of GPUs to use for inference.
integer
Tensor parallelism size.
integer
Sequence parallelism degree.
integer
Ulysses sequence parallelism degree for long sequences.
integer
Ring sequence parallelism degree.
integer
default:"1"
Data parallelism size (number of data parallel groups).
integer
default:"1"
Number of GPUs in a data parallel group.
boolean
default:"false"
Enable classifier-free guidance parallelism.
Attention Backend
string
Attention backend to use for the model.
string
Additional configuration for the attention backend (JSON format).
string
Cache-DIT configuration for diffusers backend.
CPU Offloading
boolean
Offload DiT (Diffusion Transformer) model to CPU to save GPU memory.
boolean
Enable layer-wise offloading for DiT model.
boolean
Offload text encoder to CPU.
boolean
Offload image encoder to CPU.
boolean
Offload VAE (Variational AutoEncoder) to CPU.
LoRA Adapters
string
Path to LoRA adapter weights.
string
default:"default"
Nickname for the LoRA adapter (for swapping adapters in the pipeline).
float
default:"1.0"
LoRA scale for merging (e.g., 0.125 for Hyper-SD).
string
List of module names to apply LoRA to (e.g., “q_proj,k_proj”).
Quantization
string
Path to pre-quantized transformer weights (single .safetensors file or directory).
string
Nunchaku SVDQuant configuration for model quantization.
Performance Options
boolean
default:"false"
Enable PyTorch compilation for faster inference.
boolean
default:"false"
Run warmup iterations before generation.
integer
default:"1"
Number of warmup steps to run.
boolean
Disable automatic mixed precision.
Output Options
string
default:"outputs/"
Directory path to save generated outputs.
string
Path to dump performance metrics (JSON) for the run.
Advanced Options
string
Additional keyword arguments to pass to the diffusers pipeline (JSON format).Example:
--diffusers-kwargs '{"eta": 0.5, "use_karras_sigmas": true}'string
Override paths for specific pipeline components (JSON format).Example:
--component-paths '{"vae": "path/to/custom/vae"}'string
Override the pipeline class from model_index.json.
Examples
Basic Image Generation
High-Quality Generation with Custom Settings
Multi-GPU Inference
Batch Generation
Using LoRA Adapters
CPU Offloading for Large Models
Using Configuration File
Create a config filegeneration_config.json:
Performance Benchmarking
Output
Generated outputs are saved to the specified output directory (default:outputs/). The command will display generation progress and save:
- Generated images/videos in the output directory
- Performance metrics (if
--perf-dump-pathis specified)
Limitations
Help
To see all available options:Related Commands
- sglang serve - Launch the SGLang server
- sglang version - Show version information
