Nodes/XB_ToolBox/XB-BOX - 🔄 Wan 分块交换
ComfyUI Node

XB-BOX - 🔄 Wan 分块交换

Swap transformer blocks to RAM so a 14B Wan model fits your card

By wjluoxiao·Created 5 months ago·Updated 6 days ago· 302
XB-BOX - 🔄 Wan 分块交换
    • BLOCKSWAPARGS
    blocks_to_swap0
    offload_img_embfalse
    offload_txt_embfalse
    use_non_blockingtrue
    prefetch_blocks0
    vace_blocks_to_swap0

    Wan 2.2's 14B model is ~28GB in fp16. Your 16GB card doesn't care about the arithmetic - it just fails. The community's standard answer is GGUF quantization, but there's a second lever that costs you nothing in quality and only in speed: block swapping, which unloads whole transformer blocks from VRAM to system RAM and shuttles them back just before each one is needed. XB_WanBlockSwap is the pack's settings node for exactly that, producing a BLOCKSWAPARGS bundle you feed into the pack's XB_WanModelLoader.

    The mechanism is the same "trading time for space" idea the README describes for its UNet/Checkpoint swap nodes: Wan 2.2's transformer is a stack of ~40 blocks, and the model runs through them roughly in order, so you can keep the first N blocks in RAM and only bring each block onto the GPU right before it's used. The more blocks you swap, the lower the VRAM ceiling - and the slower every step gets, because RAM ↔ VRAM transfers add up fast.

    The inputs that matter

    • blocks_to_swap (0–48, default 0) - the main knob. Start at 8–12 on a 16GB card and tune from there. 0 means no swapping, i.e. plain behavior.
    • offload_img_emb / offload_txt_emb - also push the image and text embedding layers to RAM. Cheap VRAM wins if your clips are short; turn them off if sampling gets sluggish.
    • use_non_blocking (default true) - non-blocking transfers, which let the GPU overlap compute with the swap. Keep it on.
    • prefetch_blocks (0–40) - how many blocks ahead to prefetch, hiding some of the transfer latency. Higher = more VRAM used but fewer stalls.
    • vace_blocks_to_swap (0–15) - a separate counter for VACE blocks, if you're also running a VACE reference model.

    The single output is BLOCKSWAPARGS, wired into XB_WanModelLoader's block_swap_args input. It's a pure settings node - no model tensors flow through it.

    The honest take

    Block swap is the tool for "the model just barely doesn't fit." It's strictly slower than fitting outright - the community's rule of thumb is that shuffling memory between VRAM and RAM carries a huge performance penalty, so you never use it when you don't have to. That also means the tuning loop is real: too few blocks and you still OOM, too many and a 5-minute clip becomes a 30-minute clip. The node's prefetch_blocks and use_non_blocking exist specifically to claw back some of that speed, so if it's too slow, that's where to look first. And pair it with the pack's XB_VRAM_Calculator to sanity-check the arithmetic before you commit: it has a Layers_to_Swap field that matches this node's blocks_to_swap.

    Install

    cd ComfyUI/custom_nodes
    git clone https://github.com/WJLUOXIAO/XB_ToolBox.git
    

    then restart, or install via ComfyUI Manager ("XB_ToolBox"). It's a settings node with zero dependencies; the actual swapping happens inside the Wan model loader, which you also get from this pack.

    CategoryXB_ToolBox/Wan

    Inputs (6)

    NameTypeDefaultDescription
    blocks_to_swapINT00–48
    offload_img_embBOOLEANfalse
    offload_txt_embBOOLEANfalse
    use_non_blockingBOOLEANtrue
    prefetch_blocksINT00–40
    vace_blocks_to_swapINT00–15

    Outputs (1)

    NameTypeDescription
    BLOCKSWAPARGSBLOCKSWAPARGS