Nodes/ComfyUI-SwinIR/SwinIR Model Loader
ComfyUI Node

SwinIR Model Loader

Where 90% of SwinIR problems actually live

By alexcong·Created 8 months ago·Updated 7 months ago· 4
SwinIR Model Loader
    • SWINIR_MODEL
    model_name
    model_type
    upscale4
    window_size8
    embed_dim180
    depths6, 6, 6, 6, 6, 6
    num_heads6, 6, 6, 6, 6, 6
    mlp_ratio2.0
    img_size128

    This node doesn't upscale anything. What it does is load a SwinIR model file and build the network architecture around it, producing a SWINIR_MODEL that you feed to SwinIR Upscale/Denoise. Which sounds boring until you realise it's the node holding all nine config knobs - and the one where misconfiguration produces output that looks like the other node broke. Get this right once and you never think about it again.

    SwinIR is the 2021 Swin Transformer for image restoration, the deterministic ancestor of the modern generative upscalers. In the upscaling ladder from the wider ComfyUI knowledge base it lives on the non-generative rung: it adds resolution and cleans noise without hallucinating detail the way SeedVR2 or SUPIR will. It's an old name - it shipped as a built-in upscaler in A1111 back in 2022 - but it's still one of the few fast, predictable, low-VRAM options that also does real denoising.

    How it works

    The loader pulls the model file from ComfyUI's upscale_models folder, then parses your comma-separated depths and num_heads strings into the actual network structure. model_type decides the upsampling path: classicalSR uses pixel-shuffle, lightweightSR a direct pixel-shuffle, realSR nearest-neighbour plus convolution, and denoising no upsampler at all (it prints a warning if you pair it with an upscale other than 1). Weights are loaded with strict=False, handling the params_ema / params state-dict wrappers the official checkpoints ship in.

    Inputs that matter

    Nine required inputs, but most of them you can forget after one setup:

    • model_name - dropdown populated from your upscale_models folder. Pick your downloaded .pth.
    • model_type - classicalSR, lightweightSR, realSR, or denoising. Match it to the file you downloaded.
    • upscale (default 4) - the scale factor baked into the model, not an arbitrary "make it 4x" button. It must match the file (_x2, _x4 in the filename).
    • img_size (default 128) - the trap. This must equal the model's training size, which is encoded in the filename: s64 means 64, s128 means 128. The README's config tables spell this out per model.
    • The rest - window_size, embed_dim, depths, num_heads, mlp_ratio - are the architecture itself. Use the README tables.

    Output is a single SWINIR_MODEL that wires into SwinIR Upscale/Denoise.

    The trap: strict=False

    Here's what burns people. The loader uses strict=False when loading weights, which means a mismatched architecture doesn't crash - it just loads whatever keys line up and silently ignores the rest. Set img_size wrong, or type "6,6,6,6" for a model that wants six layers, and you get a soft, washed-out, or subtly wrong upscale with zero error messages. If your SwinIR output looks bad, audit the loader config against the README's "Common Model Configurations" table before touching anything else.

    Install

    ComfyUI Manager, search "ComfyUI-SwinIR". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alexcong/ComfyUI-SwinIR.git
    cd ComfyUI-SwinIR
    pip install -r requirements.txt
    

    Dependencies are timm, numpy, and torch - timm is the one that'll actually be missing if pip complains. Models come from the official SwinIR releases and go in ComfyUI/models/upscale_models/. If model_name shows nothing, that's your problem - the folder's empty or the file's in the wrong place. Restart ComfyUI after installing.

    CategorySwinIR

    Inputs (9)

    NameTypeDefaultDescription
    model_nameCOMBO0 options:
    model_typeCOMBO4 options: classicalSR, lightweightSR, realSR, denoising
    upscaleINT41–8
    window_sizeINT84–32
    embed_dimINT18048–512
    depthsSTRING6, 6, 6, 6, 6, 6
    num_headsSTRING6, 6, 6, 6, 6, 6
    mlp_ratioFLOAT2.01–8
    img_sizeINT12832–256

    Outputs (1)

    NameTypeDescription
    SWINIR_MODELSWINIR_MODEL