Implementation:AUTOMATIC1111 Stable diffusion webui CheckpointInfo
| Knowledge Sources | |
|---|---|
| Domains | Model Management, Checkpoint Merging, Reproducibility |
| Last Updated | 2026-02-08 00:00 GMT |
Overview
Concrete tool for representing and identifying model checkpoints provided by stable-diffusion-webui.
Description
The CheckpointInfo class encapsulates all identifying information about a Stable Diffusion model checkpoint file. Upon construction, it computes a legacy hash, reads SHA-256 from cache, derives a 10-character shorthash, resolves the display name relative to the model directory, extracts safetensors metadata, and registers the checkpoint under all of its aliases in the global checkpoints_list and checkpoint_aliases dictionaries. The companion function get_closet_checkpoint_match resolves a user-provided search string to a CheckpointInfo instance through exact alias lookup followed by substring matching.
Usage
Use CheckpointInfo when loading or referencing model checkpoints prior to merging. Use get_closet_checkpoint_match to resolve user-provided model identifiers (from UI dropdowns or API calls) to their corresponding checkpoint objects.
Code Reference
Source Location
- Repository: stable-diffusion-webui
- File:
modules/sd_models.py - Lines: L56-128 (CheckpointInfo class), L153-177 (list_models), L183-200 (get_closet_checkpoint_match)
Signature
class CheckpointInfo:
def __init__(self, filename):
...
def register(self):
...
def calculate_shorthash(self):
...
def get_closet_checkpoint_match(search_string):
...
Import
from modules import sd_models
# or directly:
from modules.sd_models import CheckpointInfo, get_closet_checkpoint_match
I/O Contract
Inputs
CheckpointInfo.__init__:
| Name | Type | Required | Description |
|---|---|---|---|
| filename | str | Yes | Absolute or relative path to the checkpoint file (.ckpt or .safetensors) |
get_closet_checkpoint_match:
| Name | Type | Required | Description |
|---|---|---|---|
| search_string | str | Yes | A model identifier: name, title, hash, shorthash, or substring of title |
Outputs
CheckpointInfo.__init__:
| Name | Type | Description |
|---|---|---|
| (instance) | CheckpointInfo | Object with properties: filename, name, name_for_extra, model_name, hash, sha256, shorthash, title, short_title, ids, metadata, is_safetensors |
get_closet_checkpoint_match:
| Name | Type | Description |
|---|---|---|
| return | CheckpointInfo or None | The matching checkpoint info, or None if no match found |
Properties
| Property | Type | Description |
|---|---|---|
| filename | str | Original filename passed to the constructor |
| name | str | Relative name within the model directory (e.g., v1-5-pruned.safetensors)
|
| name_for_extra | str | Base filename without extension for display purposes |
| model_name | str | Sanitized name with path separators replaced by underscores, without extension |
| hash | str | Legacy model hash (partial file hash) |
| sha256 | str or None | Full SHA-256 hex digest from cache, or None if not yet computed |
| shorthash | str or None | First 10 characters of sha256, or None |
| title | str | Display title: "name [shorthash]" or just name if shorthash is unavailable
|
| short_title | str | Short display title using name_for_extra |
| ids | list[str] | All aliases under which this checkpoint is registered |
| metadata | dict | Metadata extracted from safetensors header (empty dict for .ckpt files) |
| is_safetensors | bool | Whether the file uses safetensors format |
Usage Examples
Basic Usage
from modules.sd_models import CheckpointInfo, get_closet_checkpoint_match
# Create a CheckpointInfo from a file path
info = CheckpointInfo("/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors")
print(info.title) # "v1-5-pruned-emaonly.safetensors [6ce0161689]"
print(info.shorthash) # "6ce0161689"
print(info.sha256) # full SHA-256 hex string
info.register() # adds to global checkpoints_list and checkpoint_aliases
# Look up a checkpoint by search string
match = get_closet_checkpoint_match("v1-5-pruned")
if match:
print(match.filename)
Lookup Priority
# 1. Exact alias match (O(1) dict lookup)
match = get_closet_checkpoint_match("6ce0161689") # by shorthash
# 2. Substring match on title (sorted by title length)
match = get_closet_checkpoint_match("v1-5")
# 3. Substring match after stripping checksum bracket suffix
match = get_closet_checkpoint_match("v1-5-pruned [abc123]")