Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:AUTOMATIC1111 Stable diffusion webui Webui Shared Globals

From Leeroopedia
Revision as of 14:05, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/AUTOMATIC1111_Stable_diffusion_webui_Webui_Shared_Globals.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Global State, Configuration
Last Updated 2025-05-15 00:00 GMT

Overview

Serves as the central shared namespace module that exposes global application state, configuration objects, and convenience re-exports used throughout the entire web UI codebase.

Description

The shared module acts as a single point of access for all globally shared state in the application. It exposes command-line options (cmd_opts, parser), the Gradio demo instance (demo), the currently loaded Stable Diffusion model (sd_model), application options (opts), processing state (state), prompt styles (prompt_styles), and many other global variables. It also re-exports convenience functions from other modules such as natural_sort_key, listfiles, html, walk_files, and ldm_print from util; reload_gradio_theme from shared_gradio_themes; and list_checkpoint_tiles, refresh_checkpoints, list_samplers, and reload_hypernetworks from shared_items. The module also defines latent upscale mode configurations and tracks UI settings components.

Usage

Import this module whenever you need to access global application state such as the current model, options, command-line arguments, or the Gradio interface instance. Nearly every module in the codebase imports from shared.

Code Reference

Source Location

Signature

# Key global variables
cmd_opts: argparse.Namespace
parser: argparse.ArgumentParser
demo: gr.Blocks
device: str
sd_model: WebuiSdModel
state: State
opts: Options
prompt_styles: StyleDatabase
face_restorers: list
sd_upscalers: list
hypernetworks: dict
latent_upscale_modes: dict

Import

from modules import shared
# or
from modules.shared import opts, cmd_opts, sd_model, state

I/O Contract

Inputs

Name Type Required Description
(none) N/A N/A This is a namespace module with global variables; values are set by other modules during initialization.

Outputs

Name Type Description
cmd_opts argparse.Namespace Parsed command-line options.
opts Options Application-wide options loaded from the settings file.
sd_model WebuiSdModel The currently loaded Stable Diffusion model.
state State The current processing state (job progress, interrupts, etc.).
demo gr.Blocks The Gradio Blocks instance for the web UI.
device str The device string for model computation.
latent_upscale_modes dict Mapping of latent upscale mode names to interpolation configurations.
hf_endpoint str The HuggingFace endpoint URL, defaulting to https://huggingface.co.

Usage Examples

from modules import shared

# Access the current model
model = shared.sd_model
if model.is_sdxl:
    print("SDXL model loaded")

# Check a user option
if shared.opts.live_previews_enable:
    print("Live previews are enabled")

# Use command-line flags
if shared.cmd_opts.api:
    print("API mode is active")

# Access latent upscale modes
mode_config = shared.latent_upscale_modes["Latent (bicubic)"]

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment