Implementation:AUTOMATIC1111 Stable diffusion webui WebuiSdModel Type
| Knowledge Sources | |
|---|---|
| Domains | Model Loading, Type System |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
Defines the WebuiSdModel type stub class that documents the runtime fields added to Stable Diffusion model instances by the web UI.
Description
The WebuiSdModel class extends LatentDiffusion from the underlying ldm library but is never directly instantiated. Instead, it serves as a type annotation stub whose fields are dynamically populated by the web UI at runtime. It declares typed annotations for model metadata such as hash, checkpoint path, architecture flags (is_sdxl, is_ssd, is_sd2, is_sd1, is_sd3), optimization state (lowvram), and latent channel count. This allows other modules to use WebuiSdModel as a type hint for shared.sd_model, enabling IDE autocompletion and static type checking across the codebase.
Usage
Use this type when you need to annotate a variable that holds the currently loaded Stable Diffusion model instance or when you need to check model architecture flags during conditional processing.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/sd_models_types.py
- Lines: 1-40
Signature
class WebuiSdModel(LatentDiffusion):
lowvram: bool
sd_model_hash: str
sd_model_checkpoint: str
sd_checkpoint_info: 'CheckpointInfo'
is_sdxl: bool
is_ssd: bool
is_sd2: bool
is_sd1: bool
is_sd3: bool
latent_channels: int
Import
from modules.sd_models_types import WebuiSdModel
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | N/A | N/A | This class is not instantiated; fields are set dynamically at runtime by the model loading pipeline. |
Outputs
| Name | Type | Description |
|---|---|---|
| lowvram | bool | True if lowvram/medvram optimizations are enabled. |
| sd_model_hash | str | Short hash (first 10 chars of SHA1) of the model file; may be None if --no-hashing is used. |
| sd_model_checkpoint | str | Path to the file on disk that model weights were obtained from. |
| sd_checkpoint_info | CheckpointInfo | Structure with additional information about the model weights file. |
| is_sdxl | bool | True if the model architecture is SDXL or SSD. |
| is_ssd | bool | True if the model is SSD. |
| is_sd2 | bool | True if the model architecture is SD 2.x. |
| is_sd1 | bool | True if the model architecture is SD 1.x. |
| is_sd3 | bool | True if the model architecture is SD 3. |
| latent_channels | int | Number of channels in the latent image representation (16 for SD3, 4 for others). |
Usage Examples
from modules import shared
from modules.sd_models_types import WebuiSdModel
model: WebuiSdModel = shared.sd_model
if model.is_sdxl:
print("Using SDXL architecture")
print(f"Model hash: {model.sd_model_hash}")
print(f"Latent channels: {model.latent_channels}")