Principle:AUTOMATIC1111 Stable diffusion webui Network file discovery
| Knowledge Sources | |
|---|---|
| Domains | Stable Diffusion, LoRA, File Management, UI |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Network file discovery is the process of scanning local directories for LoRA, LyCORIS, and other network adapter files, extracting metadata, and presenting them to the user for selection and activation.
Description
In Stable Diffusion WebUI systems, network adapter files (such as LoRA, LoHa, LoKr, and other low-rank adaptation variants) are stored as safetensors, checkpoint, or PyTorch files on disk. The file discovery system is responsible for:
Directory scanning: Recursively walking configured directories (typically models/Lora/ and a backwards-compatible LyCORIS directory) to find files with supported extensions (.pt, .ckpt, .safetensors).
Metadata extraction: Safetensors files embed training metadata in their headers. Key metadata fields include ss_sd_model_name, ss_resolution, ss_clip_skip, ss_num_train_images, ss_tag_frequency, ss_base_model_version, and ss_v2. This metadata is cached to avoid repeated file reads.
SD version detection: Each network file targets a specific Stable Diffusion architecture version (SD1, SD2, or SDXL). The discovery system detects this from metadata: if ss_base_model_version starts with "sdxl_" it is SDXL; if ss_v2 is "True" it is SD2; otherwise, if metadata exists, it is SD1. Files with no metadata are marked as Unknown.
Compatibility filtering: When displaying networks to the user, the system filters out networks incompatible with the currently loaded model. An SDXL model only shows SDXL networks; an SD1 model only shows SD1 networks. Networks with Unknown version can optionally be hidden via user settings (lora_hide_unknown_for_versions).
Hash computation: Each file receives a SHA256-based hash and a 12-character short hash used for identification, deduplication, and infotext embedding. Hashes are cached to avoid recomputation.
Alias management: Networks can have an alias derived from the ss_output_name metadata field. When aliases collide between multiple files, they are added to a forbidden list, forcing the use of the actual filename as the identifier.
Usage
Network file discovery is used whenever the Extra Networks UI panel is opened or refreshed, whenever a prompt containing <lora:...> tags references a network by name, and during startup to populate the list of available networks. It provides the bridge between raw files on disk and the interactive UI that allows users to browse, filter, and select networks for image generation.
Theoretical Basis
The discovery pattern follows a registry-with-lazy-loading architecture:
1. SCAN: Walk directories for files matching allowed extensions
2. REGISTER: For each file, create a NetworkOnDisk entry:
a. Read safetensors metadata from file header (cached)
b. Compute or retrieve cached SHA256 hash
c. Detect SD version from metadata fields
d. Determine alias (ss_output_name or filename)
3. INDEX: Store in available_networks (by name) and available_network_aliases (by name and alias)
4. PRESENT: For each registered network, create a UI item dict:
a. Resolve preview image (sidecar image or embedded preview)
b. Resolve description text
c. Filter by SD version compatibility with current model
d. Construct prompt syntax string: <lora:alias:weight>
5. YIELD: Emit item dicts to the UI for rendering as cards
The compatibility filtering uses an enumerated version type:
class SdVersion(enum.Enum):
Unknown = 1
SD1 = 2
SD2 = 3
SDXL = 4
Version detection logic:
if ss_base_model_version starts with "sdxl_" -> SDXL
elif ss_v2 == "True" -> SD2
elif metadata exists -> SD1
else -> Unknown