skillfed

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.

spandrel v0.4.2 1.6M downloads/30d#3,772 on PyPI
Permissive license MIT Active released

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 spandrel

uv

uv add spandrel

poetry

poetry add spandrel

Installing 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

Development Status :: 2 - Pre-AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Topic :: Software Development :: Libraries

Tags

pytorch model loaderauto-detect model architectureload pth filespytorch model inferencemodel architecture detectionunified pytorch interfacepre-trained model support
pytorch-modelsmodel-loadingimage-restoration

More Libraries packages