Block Swap (RAM Offload)
Run the 28.6 GB Wan fp16 you already downloaded
- model
- MODEL
This node keeps the first N of Wan's transformer blocks parked in system RAM and streams each one to the GPU for exactly as long as its forward pass needs, then drops it back. If you have the Wan 2.2 14B fp16 weights - 28.6 GB, roughly a GB per block over 40 blocks - sitting on a 24 GB card, this is the difference between a workflow that OOMs and one that just finishes.
Block swapping itself isn't new. ComfyUI core and Kijai's wrapper have shipped Wan-specific versions for a while, and the people who use them tend to treat them as quietly essential - one thread on the technique literally called it "magic." What this pack adds is a generic, native MODEL-level implementation that isn't tied to a Wan wrapper, and it's this node that targets the classic Wan family (.blocks, plain fp16/bf16). Its two siblings handle the newer paths - read on if your model is fp8 or Krea 2.
How it works
Instead of ComfyUI's usual lowvram trick of casting layers in and out per forward pass, BlockSwap hooks the model's ON_LOAD and reorganizes the whole thing once:
- LoRA patches get baked into the CPU-resident weights a single time at load.
- Swapped blocks are moved to (optionally pinned) system RAM.
- Everything else is made fully GPU-resident, which removes the slow per-layer
LowVramPatchcast path entirely.
Each swapped block's forward is then wrapped: parameters are repointed to a GPU copy just-in-time, and repointed straight back to the CPU master afterward - no device-to-host copy, because weights never change during inference. The one cost is a PCIe H2D transfer per block per forward (~25–30 ms per 660 MB fp16 block on PCIe 4.0 x16), and since transfers overlap with the previous block's compute, the net hit is close to zero when you're compute-bound. The author's own measurement on Wan 14B: 28–29 s/it with or without the swap.
The inputs that matter
All three of them, honestly. This is a small node.
model- yourMODELfromUNETLoader. Place it after your LoRA loaders; the node bakes LoRAs in at load.blocks_to_swap(default 20) - how many of Wan's 40 blocks live in RAM. Raise it if you still hit OOM. It also auto-raises itself when the resident part wouldn't fit the VRAM weight budget, so the default is a safe starting point.pin_memory(default true) - page-locks the CPU copies for faster PCIe transfers. Costs the same amount of non-swappable system RAM; leave it on unless you're on the Windows mmap-loading edge cases described in the LTX/Krea2 notes.
The single output is a MODEL, the same object with swap callbacks attached. Wire it into ModelSamplingSD3 → KSampler and you're done.
Installing it
Zero dependencies, zero model downloads, no API, no key. The whole pack is three Python files. Either:
ComfyUI Manager → Install Custom Nodes → search "ComfyUI-JITBlockSwap"
or
cd ComfyUI/custom_nodes
git clone https://github.com/lovemachine100/ComfyUI-JITBlockSwap
then restart ComfyUI. Full chain for Wan 2.2:
UNETLoader → LoraLoaderModelOnly → BlockSwap → ModelSamplingSD3 → KSampler
Where people get burned
The launch flag is not optional. This node only acts when ComfyUI runs with --disable-dynamic-vram. Without it the node does not error - it passes the model through unchanged and prints [BlockSwap] dynamic VRAM patcher detected, skipping. to the console only. Nothing shows in the browser UI. If block swap "isn't working," that line is the first thing to look for, and it's the most common reason a downloaded workflow with this node seems dead on arrival.
Two more real gotchas from the README: don't chain two BlockSwap nodes on the same model, and this class only covers .blocks - Flux's double blocks are not handled, and fp8-scaled checkpoints (including Wan 2.2 fp8) want the BlockSwapLTX sibling. LoRA changes and model switching (the Wan 2.2 high/low-noise swap) are safe: placement is re-applied on every load.
One thing to check before you bother: you need the system RAM to hold the swap masters. 20 blocks of fp16 is ~13 GB of your physical RAM, pinned. If your machine is light on RAM, block swap trades a VRAM problem for a different one.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| blocks_to_swap | INT | 200–80 | Number of transformer blocks kept in system RAM and streamed to the GPU per forward pass. Raise if you still hit OOM. Automatically raised further when the resident part would not fit in VRAM. |
| pin_memory | BOOLEAN | true | Page-lock the CPU copies for faster PCIe transfers. Costs the same amount of non-swappable system RAM. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |