AUTOMATIC1111/stable-diffusion-webui
Data models
The repository's "domain types" — the dataclasses and protocols the rest of the code revolves around. Everything below is a Python class; there are no SQL tables, no GraphQL schemas, no Protocol Buffers in this codebase.
StableDiffusionProcessing (and friends)
The single most central type. Every generation request is a populated StableDiffusionProcessing (or one of the two subclasses). It's a dataclass with ~50 fields covering prompts, sizes, sampler choice, batch parameters, scripts, hires-fix, refiner, masks, and infotext extras.
@dataclass
class StableDiffusionProcessing:
sd_model: object = None
outpath_samples: str = ''
outpath_grids: str = ''
prompt: str = ''
prompt_for_display: str = None
negative_prompt: str = ''
styles: list = field(default_factory=list)
seed: int = -1
subseed: int = -1
subseed_strength: float = 0
seed_resize_from_h: int = -1
seed_resize_from_w: int = -1
sampler_name: str = None
scheduler: str = None
batch_size: int = 1
n_iter: int = 1
steps: int = 50
cfg_scale: float = 7.0
width: int = 512
height: int = 512
restore_faces: bool = None
tiling: bool = None
do_not_save_samples: bool = False
do_not_save_grid: bool = False
extra_generation_params: dict = field(default_factory=dict)
overlay_images: list = None
eta: float = None
do_not_reload_embeddings: bool = False
denoising_strength: float = None
ddim_discretize: str = None
s_min_uncond: float = 0.0
s_churn: float = 0.0
s_tmax: float = None
s_tmin: float = 0.0
s_noise: float = None
override_settings: dict = field(default_factory=dict)
override_settings_restore_afterwards: bool = True
sampler_index: int = None
refiner_checkpoint: str = None
refiner_switch_at: float = None
token_merging_ratio: float = 0
token_merging_ratio_hr: float = 0
disable_extra_networks: bool = False
firstpass_image: PIL.Image = None
scripts_value: ScriptRunner = field(default=None, init=False)
script_args_value: list = field(default_factory=list, init=False)
scripts_setup_complete: bool = field(default=False, init=False)
cached_uc: list = field(default_factory=list) # cached uncond conditioning
cached_c: list = field(default_factory=list)Subclasses add fields:
StableDiffusionProcessingTxt2Img—enable_hr,hr_scale,hr_upscaler,hr_second_pass_steps,hr_resize_x/y,hr_sampler_name,hr_scheduler,hr_prompt,hr_negative_prompt,hr_cfg,hr_distilled_cfg,firstphase_width/height. See features/hires-fix.md.StableDiffusionProcessingImg2Img—init_images,resize_mode,denoising_strength,image_cfg_scale,mask,mask_blur_x/y,mask_blur,inpainting_fill,inpaint_full_res,inpaint_full_res_padding,inpainting_mask_invert,initial_noise_multiplier,latent_mask,image_mask. See features/img2img.md.
Processed
The result returned from process_images(p):
class Processed:
images: list[PIL.Image]
prompt: str
negative_prompt: str
seed: int
subseed: int
info: str # primary infotext (first image)
comments: str # warnings/notes accumulated during processing
width: int
height: int
sampler_name: str
cfg_scale: float
steps: int
batch_size: int
restore_faces: bool
face_restoration_model: str
sd_model_name: str
sd_model_hash: str
sd_vae_name: str
sd_vae_hash: str
seed_resize_from_w: int
seed_resize_from_h: int
denoising_strength: float
extra_generation_params: dict
index_of_first_image: int
infotexts: list[str] # one per image
styles: list[str]
job_timestamp: str
clip_skip: int
token_merging_ratio: float
token_merging_ratio_hr: floatCheckpointInfo
Per-checkpoint record:
| Field | Type | Notes |
|---|---|---|
filename |
str | Absolute path |
name |
str | Filename portion (no path) |
name_for_extra |
str | Display name for extra-networks browser |
model_name |
str | Without extension |
hash |
str (legacy) | First 9 chars of sha256(first 8KB) — legacy |
sha256 |
str | Full SHA-256, computed lazily |
shorthash |
str | First 10 chars of sha256 |
title |
str | name [shorthash] — the dropdown label |
model_type |
ModelType enum |
SD1 / SD2 / SDXL / SSD / SD3 |
ids |
list[str] | All forms the user might type to pick this checkpoint |
metadata |
dict | Sidecar metadata (.safetensors __metadata__) |
ModelType is the enum used by every code path that needs to branch on architecture:
class ModelType(Enum):
SD1 = 1
SD2 = 2
SDXL = 3
SSD = 4
SD3 = 5SamplerData
class SamplerData:
name: str
constructor: callable # (model) -> Sampler instance
aliases: list[str]
options: dictoptions keys you may encounter: scheduler (default scheduler for this sampler), no_sdxl (bool), default_eta_is_0, solver_type, uses_ensd. Used by find_sampler_config() and the create_sampler() factory in modules/sd_samplers.py.
Scheduler
@dataclass
class Scheduler:
name: str
label: str
function: Callable[[int, float, float, torch.device], torch.Tensor]
default_rho: float = -1
need_inner_model: bool = False
aliases: list[str] | None = Nonefunction returns the sigma sequence. need_inner_model is set for schedules that depend on the underlying model (used by AYS).
Network and NetworkOnDisk
extensions-builtin/Lora/networks.py
class NetworkOnDisk:
name: str
filename: str
metadata: dict
sha256: str
is_v2: bool
network_type: type[Network]
alias: str
sd_version: SdVersion enumclass Network:
name: str
network_on_disk: NetworkOnDisk
te_multiplier: float
unet_multiplier: float
dyn_dim: int
modules: dict[str, NetworkModule] # per-target-layer module
bundle_embeddings: dict # textual-inversion embeddings packaged inside this LoraEmbedding
modules/textual_inversion/textual_inversion.py
class Embedding:
vec: torch.Tensor # the actual learned vectors
name: str
step: int # last training step (or None if not trained)
sd_checkpoint: str # checkpoint hash this was trained on (informational)
sd_checkpoint_name: str
cached_checksum: str # sha256 of `vec`
sd_version: SdVersion enum
filename: str
shape: int # number of tokensExtension
class Extension:
name: str
path: str # filesystem path
enabled: bool
is_builtin: bool
metadata: ExtensionMetadata
canonical_name: str
remote: str | None # git remote URL
branch: str | None
commit_hash: str | None
commit_date: int | None
version: str | None
have_info_from_repo: boolExtensionMetadata reads metadata.ini's [Extension] Name, Requires, and [callbacks/<name>] Before/After blocks.
OptionInfo
class OptionInfo:
default: Any
label: str
component: type[gr.Component]
component_args: Callable | dict | None
onchange: Callable | None
section: tuple[str, str] # (key, display)
refresh: Callable | None # populates dropdown choices
comment_before: str | None
comment_after: str | None
infotext: str | None # the infotext key this option roundtrips with
restrict_api: bool # if True, /sdapi/v1/options can't write itPydantic API models
For each *Processing* dataclass, a *ProcessingAPI Pydantic class is generated by introspection. Hand-written response models cover everything else:
TextToImageResponse,ImageToImageResponse,ExtrasSingleImageResponse,ExtrasBatchImagesResponse,PNGInfoResponse,ProgressResponseOptionsModel,FlagsModelSamplerItem,SchedulerItem,UpscalerItem,LatentUpscalerModeItem,SDModelItem,SDVaeItem,HypernetworkItem,FaceRestorerItem,RealesrganItem,PromptStyleItemEmbeddingsResponse,MemoryResponse,ScriptsList,ScriptInfo,ExtensionItemCreateResponse,TrainResponse
These are listed via add_api_route(..., response_model=...) in modules/api/api.py.
State
shared.state is a State instance — process-wide progress and control:
class State:
skipped: bool
interrupted: bool
job: str # human-readable job description
job_no: int
job_count: int
processing_has_refined_job_count: bool
job_timestamp: str
sampling_step: int
sampling_steps: int
current_latent: torch.Tensor
current_image: PIL.Image
current_image_sampling_step: int
id_live_preview: int
textinfo: str
time_start: float
server_start: float
server_command: str # "stop", "restart"The progress bar polls this; interrupt()/skip() set the boolean flags; the sampler loop checks them every step.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
Configuration
Next
Dependencies