spandrel
Give your project support for a variety of PyTorch model architectures, including auto-detecting model architecture from just .pth files. spandrel gives you arch support.
What it is and what it does
Spandrel is a PyTorch model loading library that automatically detects model architecture and hyperparameters from saved model files, then wraps them in a unified interface for inference. It originated from the chaiNNer project and now serves as a central package for architecture support across the community. The library focuses on image models (super-resolution, restoration) but is designed to be extensible for other architectures.
You provide a path to a model file (.pth, .pt, .ckpt, or .safetensors), and Spandrel identifies the architecture, returns a ModelDescriptor object with metadata, and lets you call the model directly. It does not handle image-to-tensor conversion or other preprocessing—you manage that yourself. The base package includes only permissive-license architectures (MIT, Apache 2.0, public domain); restrictive-license models require the optional spandrel_extra_arches package.
Use it for:
- Load and run ESRGAN, SwinIR, HAT, or other super-resolution models without manually implementing architecture detection.
- Build an image processing pipeline that supports multiple model formats and architectures through a single interface.
- Integrate community-trained PyTorch models into an application without hardcoding architecture-specific loading logic.
- Extend model support by contributing new architectures to a shared, centralized package rather than maintaining per-project implementations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Spandrel loads and runs pre-trained PyTorch models by automatically detecting their architecture from model files and providing a unified interface for inference.
Yes, if you work with pre-trained PyTorch models and want to avoid architecture-specific loading boilerplate. The library is actively maintained, has low install friction, uses a permissive license, and supports a wide range of image models. Start with the base package; add spandrel_extra_arches only if you need non-commercial or restrictive-license architectures. Note that you must handle tensor preparation yourself—this is not an end-to-end inference library.
Install
spandrel on PyPI
pip
pip install spandreluv
uv add spandrelpoetry
poetry add spandrelInstalling spandrel
Before you install
Low install friction with a pure-Python wheel. Maintenance is active with a recent release (174 days ago). Requires Python 3.10 or later and depends on torch, torchvision, and several other standard ML libraries.
License in practice
MIT license (permissive) means you can use this freely in commercial and private projects without restriction or attribution requirement.
Quickstart
pip install spandrel
from spandrel import ImageModelDescriptor, ModelLoader
import torch
model = ModelLoader().load_from_file("path/to/model.pth")
assert isinstance(model, ImageModelDescriptor)
model.cuda().eval()
with torch.no_grad():
output = model(input_tensor)
Requires Python 3.10+. Torch and torchvision must be installed; they are not bundled. The model descriptor does not automatically convert images to tensors—you must handle tensor preparation yourself.
Verify before relying
- Whether the package has comprehensive documentation beyond the GitHub README for all supported architectures.
- Performance characteristics when loading very large model files or running inference on CPU vs GPU.
- Whether spandrel_extra_arches is required for your specific model architecture or if the base package suffices.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — torch, torchvision, safetensors, numpy, einops, typing_extensions |
| Maintenance | actively maintained — 174 days since the last release |
| First released | |
| Downloads | 1,553,115/month — #3,772 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: spandrel-0.4.2-py3-none-any.whl
Keywords: spandrel, pytorch architecture, pytorch arch, model arch, model architecture
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
spandrel-extra-archesRegisters additional PyTorch model…
permissive · top 15,000 on PyPI
torchvisionTorchvision provides pre-built datasets, model…
permissive · top 1,000 on PyPI
torchtexttorchtext provides text datasets, preprocessing…
permissive · top 15,000 on PyPI
torchsrProvides pretrained neural network models for…
permissive · top 15,000 on PyPI
facenet-pytorchProvides pretrained PyTorch models for face…
permissive · top 15,000 on PyPI
ncnnncnn is a neural network inference framework…
permissive · top 15,000 on PyPI
pytorchThis package is a redirect or placeholder; the…
unclear · top 15,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
efficientnet-pytorchLoads and runs pretrained EfficientNet image…
permissive · top 15,000 on PyPI
torch-model-archiverTorch Model Archiver creates .mar archive files…
permissive · top 15,000 on PyPI