spandrel-extra-arches
spandrel-extra-arches is a Python library that implements various PyTorch model architectures with restrictive licenses, designed to extend the capabilities of the core `spandrel` package. It enables `spandrel` to automatically detect and load models that might have non-commercial or other specific license requirements, segregating them from `spandrel`'s permissively licensed architectures. The current version is 0.2.0, released on September 15, 2024, and it is actively maintained and developed in conjunction with `spandrel`.
Common errors
-
ModuleNotFoundError: No module named 'spandrel_extra_arches.architectures.<some_arch>'
cause The `spandrel-extra-arches` package is either not installed, or the specified architecture path is incorrect or does not exist. This can happen if attempting a direct import before installation or if an unsupported architecture name is used.fixFirst, ensure `spandrel-extra-arches` is installed via `pip install spandrel-extra-arches`. If directly importing, double-check the exact import path and architecture name against the library's source code or documentation. -
TypeError: <ArchitectureClass>() takes no positional arguments
cause This error occurs when attempting to instantiate an architecture class with positional arguments. A recent update in `spandrel` and `spandrel-extra-arches` requires all architecture parameters to be passed as keyword arguments.fixModify the instantiation call to use keyword arguments for all parameters, e.g., change `RCAN(2, 64, 16)` to `RCAN(scale=2, num_feat=64, num_rcab=16)`.
Warnings
- gotcha Many architectures within `spandrel-extra-arches` are subject to restrictive licenses (e.g., non-commercial use only). Users engaging in commercial or closed-source projects MUST carefully review the individual licenses of each architecture they intend to use.
- breaking Starting with `spandrel` v0.4.0 (released alongside `spandrel-extra-arches` v0.2.0), all architectures now require keyword arguments for instantiation. Code that previously used positional arguments for initializing models might break.
- gotcha While `spandrel-extra-arches` itself specifies `requires_python: >=3.8`, the core `spandrel` library, which is a dependency and the primary interface, has recently dropped support for Python 3.8 and 3.9, now requiring Python >=3.10. Using `spandrel-extra-arches` with older Python versions (3.8, 3.9) might lead to incompatibility issues with `spandrel`.
Install
-
pip install spandrel-extra-arches
Imports
- RCAN
from spandrel_extra_arches.architectures.rcan.__arch.rcan import RCAN
Quickstart
import torch
from spandrel import Spandrel
# Ensure spandrel-extra-arches is installed (pip install spandrel-extra-arches)
# spandrel will automatically discover architectures provided by spandrel-extra-arches
# Example: Assuming you have a .pth model file for an architecture in spandrel-extra-arches
# For demonstration, let's pretend 'my_extra_arch_model.pth' is an RCAN model.
# In a real scenario, `spandrel.Spandrel()` would detect the architecture type.
try:
# This path would be to an actual model file
model_path = 'my_extra_arch_model.pth'
# Create a dummy model file for demonstration if it doesn't exist
if not torch.exists(model_path):
# This is a placeholder. A real model would be loaded from a file.
# In practice, you'd download a .pth file for an extra arch model.
print(f"[INFO] No model file found at {model_path}. Skipping model loading example.")
print("[INFO] Please provide a valid .pth model file for an architecture supported by spandrel-extra-arches to run this part.")
else:
# Load the model using spandrel
spandrel_model = Spandrel(model_path)
print(f"Model loaded successfully: {spandrel_model.name} - {spandrel_model.arch_name}")
# Example of getting the underlying PyTorch module
pytorch_module = spandrel_model.model
print(f"PyTorch module type: {type(pytorch_module)}")
except Exception as e:
print(f"An error occurred during model loading: {e}")