Nodes/ComfyUI_Swwan/Image Upscale With Model Batched (Swwan)
ComfyUI Node

Image Upscale With Model Batched (Swwan)

The 4x upscaler that doesn't blow your VRAM

By aining2022·Created 10 months ago·Updated about 18 hours ago· 33
Image Upscale With Model Batched (Swwan)
  • upscale_model
  • images
  • IMAGE
◄per_batch16►

What it is

ComfyUI core's ImageUpscaleWithModel node, with one extra widget: per_batch. Same UPSCALE_MODEL input, same IMAGE output, same ESRGAN-family behaviour - but instead of pushing the entire batch through your upscaler in one go, it slices the batch into chunks of per_batch and moves them to the GPU one chunk at a time.

That's the whole idea, and it's the difference between finishing a 60-frame video upscale and watching the sampler die at frame 17. The KB's upscaling doc puts ESRGAN models in the "more pixels, no hallucination" bucket: milliseconds per frame, minimal VRAM, and still the right answer when the source is already sharp. What it doesn't say is that "minimal VRAM" assumes you're not feeding it sixty 1080p frames at once.

How it works

The implementation is refreshingly literal. Move the batch to [B,C,H,W], load the model onto the GPU once, then loop range(0, B, per_batch) - for each window, run the model on that slice, copy the result back to CPU, append. When the loop finishes, the model goes back to CPU and the pieces are concatenated and permuted back to the usual [B,H,W,C] layout. There's a progress bar per batch, and the model stays resident on the GPU for the whole call rather than being loaded per slice.

Two consequences you should internalise:

  • per_batch=1 is the memory floor. One image at a time, slowest, but it will get through a batch that OOMs at any higher setting.
  • This controls the batch dimension, not the area of a single image. A single 8000×8000 input is still one immense tensor through a 4x model. For that problem you want tiled upscaling (Ultimate SD Upscale with a Tile ControlNet, per the KB), not this node.

The default of 16 is tuned for a comfortable GPU with modest frames. On a 8GB card doing 2K frames, start at 2 and work up.

Inputs and outputs

upscale_model takes the output of an UpscaleModelLoader - the pack ships your standard ESRGANs from ComfyUI/models/upscale_models, and the KB names the usual suspects: 4x-UltraSharp for general use, 4x_NMKD-Siax_200k or RealESRGAN_x4plus_anime_6B for anime. images is the batch. per_batch is the only knob.

Output is a single IMAGE at the model's native factor (4x for the common models), so a 1024×1024 batch becomes 4096×4096 and your disk usage quadruples in both directions. Remember that most 4x models don't halve nicely - if you want a 2x result, upscale 4x and then resize down with a Lanczos resize, which is the standard trick and also helps kill the upscaler's characteristic crunch.

There is no mask, no tile size, and no tiling at all. If that's what you need, this is the wrong node.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
cd ComfyUI_Swwan
python -m pip install -r requirements.txt

Restart, refresh, search Swwan. The node itself needs nothing special, and the pack never downloads models for you - put your .pth files in ComfyUI/models/upscale_models yourself.

Common issues

Still OOMs at per_batch=1. The single image is too big, or the model is a heavyweight (some are 300MB+ with internal tiling expectations). Crop into tiles and stitch, or resize before upscaling.

Output looks crunchy. Typical ESRGAN behaviour - the model is sharpening what's there. Downscale the 4x result 2x with Lanczos and it usually cleans up.

Missing node in an imported KJNodes workflow. Same data contract, different ID (SwwanImageUpscaleWithModelBatched), and the pack registers no compatibility aliases by design. Migrate the workflow with python scripts/migrate_workflow.py old.json --dry-run rather than renaming things by hand.

Manager warns about a conflict with KJNodes. It's about overlapping node names between the two packs, not a broken install - the pack is a reimplementation of 56 KJNodes nodes, so Manager notices. Harmless for this node; worth reading if you're also running rgthree (see the pack's install notes about frontend isolation).

CategorySwwan/Advanced/Batch

Inputs (3)

NameTypeDefaultDescription
upscale_modelUPSCALE_MODEL—
imagesIMAGE—
per_batchINT161–4096—

Outputs (1)

NameTypeDescription
IMAGEIMAGE—