# Repository Briefing: Stability-AI/generative-models
> Source: https://repoforai.com/repo/Stability-AI/generative-models (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/Stability-AI/generative-models
- **Category**: Voice, Vision & Video (语音 / 视觉 / 视频生成)
- **Primary Language**: Python
- **License**: MIT
- **Engineering Health**: B (60/100 · Maintenance 6/35 · Adoption 23/25 · Releases 11/20 · License 20/20)
- **Latest Release**: 0.1.0 (2023-07-27) — https://github.com/Stability-AI/generative-models/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Local AI, GPU, CLI
- **Momentum**: 27,353 ★ total (+3 24h / +13 7d) · 3,091 forks
- **When to Use**: Best for: Teams running SDXL locally or experimenting with diffusion conditioning, sampling, and training at the component level. Skip if: You need a ready-made production image API, an installer that resolves all runtime dependencies, or weights covered by the same MIT license as the code.

## Overview
```text
### Architecture & Core Mechanics
Stability AI's `sgm` is a Python/PyTorch framework that assembles diffusion pipelines from YAML. `instantiate_from_config()` constructs the configured components: `network_config` selects the backbone, `loss_config` defines the training loss and its sigma sampler, and `sampler_config` selects the numerical solver, step count, discretization, and guidance wrapper independently of the model. That separation lets a team compare sampling strategies without changing the backbone implementation.

`GeneralConditioner` calls each configured `AbstractEmbModel` with the batch field named by its `input_key`, such as `txt` or `cls`. Each embedder can specify trainability and classifier-free guidance dropout. The conditioner combines 2D–4D outputs into vector, sequence, and spatial conditioning, with concatenation sensitive to embedder order. Extending the system means implementing or configuring Python components and keeping their batch and tensor interfaces compatible.

### Key Capabilities & Differentiators
The Streamlit entry point at `scripts/demo/sampling.py` supports text-to-image and image-to-image sampling with SDXL base and refiner variants in versions 1.0 and 0.9. The 1.0 checkpoints have both full-file SHA-256 and tensor-data hashes, so users can verify the download and the stored tensors separately. The image output path embeds an invisible watermark; `scripts/demo/detect.py` checks individual files or batches of files for that watermark, which differs from the one used in Stable Diffusion 1.x/2.x.

Training starts at `python main.py --base ...`; YAML files merge left to right, with later values taking precedence. Example configs range from class-conditional pixel diffusion on MNIST to latent diffusion and text-to-image training. The non-toy examples require dataset-specific edits for WebDataset tar files. The latent and text-to-image examples also require a VAE checkpoint path in place of `CKPT_PATH`, so those configs are starting points rather than turnkey training jobs.

### Trade-offs & Limitations
Choose `sgm` over a higher-level inference pipeline when the work involves changing conditioning, solvers, or training components. The flexibility comes with more integration work: configuration changes still have to respect input keys, embedder order, checkpoint compatibility, and dependency versions. The Streamlit entry point serves local experiments; teams building an application still need to provide their own serving and operational controls.

Local execution gives you control of checkpoints and configuration, but it also makes GPU capacity your responsibility. Profile VRAM at the intended resolution and batch size, then test the refiner and expected concurrency separately rather than extrapolating from a base-only run. License review is likewise checkpoint-specific: MIT covers code, SDXL 1.0 weights use CreativeML Open RAIL++-M, and SDXL 0.9 weights are gated under a separate research license.

### Hardware & Deployment Guide
Use a local Python environment with a compatible GPU stack. The package metadata allows Python 3.8 or later, but Python 3.10 is the tested baseline. The PyTorch 2.0 installation path uses CUDA 11.8 wheels for `torch`, `torchvision`, and `torchaudio`, followed by `requirements/pt2.txt` and `pip install .`. Hatch packages the YAML configs under `sgm/configs`, but the package does not declare runtime dependencies for the installer to resolve. Download model checkpoints separately, then run inference locally rather than through a hosted generation API.

For training, install `sdata` from Stability AI's `datapipelines` project. Training supports PyTorch 1.13 and 2.0, but the autoencoder training path is limited to 1.13, so validate the environment against the actual configuration. Release 0.0.1 introduced the reworked `sgm` codebase, separated samplers from guiders, and shipped SDXL 0.9 base and refiner; release 0.1.0, dated July 27, 2023, added the SDXL 1.0 pair.
```

## Key Capabilities
```text
- Composition: YAML and `instantiate_from_config()` wire the network, conditioner, sampler, and loss as separate components.
- Conditioning: `GeneralConditioner` combines vector, sequence, and spatial embeddings; embedder order matters.
- Sampling: `sampler_config` controls solver, step count, discretization, and classifier-free guidance independently of the model.
- Inference: `scripts/demo/sampling.py` runs a local Streamlit demo for text-to-image and image-to-image with SDXL base and refiner variants.
- Training: `main.py --base` merges YAML files left to right, so later files can override model, training, or data settings.
- Artifact verification: SDXL 1.0 checkpoints have full-file and tensor-data hashes; `scripts/demo/detect.py` checks for the output watermark.
```

## Quick Start / Clone
```bash
python3.10 -m venv .generativemodels
source .generativemodels/bin/activate
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # check CUDA version
pip3 install -r requirements/pt2.txt
pip3 install .
pip3 install -e git+https://github.com/Stability-AI/datapipelines.git@main#egg=sdata
```
