Spandrel
Load and run pre-trained PyTorch super-resolution and restoration models with automatic architecture detection.
Repository Health
Technical Analysis
Spandrel is a Python library for loading and running pre-trained PyTorch models, with a focus on AI super-resolution, restoration, and inpainting architectures. It automatically detects a model’s architecture and hyperparameters from its state-dict file and exposes a single unified interface for running any supported model, so projects don’t have to reimplement per-architecture loading logic.
Born from chaiNNer’s extensive model support, Spandrel centralizes that architecture handling into a reusable package. Instead of hand-wiring each network (ESRGAN, SwinIR, and many more), you point Spandrel at a model file and receive a ready-to-run wrapper that knows the model’s scale, input requirements, and tags.
What You Get
- Automatic detection of model architecture and hyperparameters from a state dict
- A unified interface for loading and running many PyTorch model types
- Support for a large catalog of super-resolution, restoration, and inpainting architectures
- ModelDescriptor metadata such as scale, channels, and purpose tags
- An optional extra-architectures package for less permissively licensed models
Common Use Cases
- Running community ESRGAN/SwinIR-style super-resolution models in your own app
- Building image restoration and upscaling pipelines without per-model loaders
- Supporting user-supplied model files whose architecture is unknown ahead of time
Under The Hood
Architecture - Spandrel maintains a registry of architecture implementations, each with a detector that recognizes a matching state dict; a top-level ModelLoader iterates registered architectures to identify a file, builds the network, loads weights, and wraps it in a ModelDescriptor that standardizes metadata and the run interface.
Tech Stack - It is a pure-Python PyTorch library supporting Python 3.8+, packaged as core spandrel plus an optional spandrel_extra_arches module for architectures with more restrictive licenses.
Code Quality - The project has a CI test suite and documentation site and is widely depended upon in the generative-imaging ecosystem, though recent maintenance activity has slowed relative to its earlier pace.
API Design - The API is deliberately minimal and consistent: load a model with one call and run it through a uniform descriptor, which greatly reduces the boilerplate of supporting many architectures.