Using WAN Video Block Swap with ComfyUI  「Block SwapでVRAM使用メモリを削減する」

20/07/2025

AI ComfyUI WAN

 in English

Generating video requires a large amount of VRAM (graphics card memory), so using normal methods it is not possible to generate videos as desired in environments with low VRAM capacity.

The function that allocates this required memory amount to the PC's main memory is Block Swap.

Main memory is slower than VRAM, but this function sacrifices speed to prevent OOM (Out of Memory).


1. Conditions

Model : WAN21_I2V_14B_480p_Q5_K_M.gguf

Text Encoder : umt5_xxl_fp8_e4m3fn_scaled.safetensors

Clip Vision : clip_vision_h.safetensors

VAE : WAN21_VAE_bf16.safetensors

steps = 20, CFG = 6.0, shift = 8.0


The image we will use is this one, 480x848.


The workflow uses the basic form we built previously. Clicking on this workflow image will bring up an image saved on Google Drive, from which you can download it and drag and drop it into ComfyUI to reproduce the workflow. If you haven't installed the custom node WanVideoWrapper yet, please install it by referring to the previous article .


Add WanVideo BlockSwap to the workflow and connect it to WanVideo Model Loader as shown below.


In addition, measurements were taken with the following PC configuration:

M/B: MPG B550 GAMING PLUS (note that the VGA slot is PCIE4.0)

CPU : Ryzen7 5700X

GPU : RTX5060ti 16GB

RAM : DDR4 3200 64GB (32GBx2)


2. Measurement


The blocks_to_swap value of the WanVideo BlockSwap node can be set from 0 to 40.

Increasing the value of blocks_to_swap will increase the main memory usage ratio. From the measurement results later, we found that when the value is 20, the main memory usage ratio is 50%. When the value is 0, the result is the same as when the node is not used.


Now, I will describe the measurement results.


blocks_to_swap = 40

Transformer blocks on cpu: 11222.15MB (This is the main memory usage)

Transformer blocks on cuda:0: 0.00MB (This is the VRAM usage)

Total memory used by transformer blocks: 11222.15MB (Total memory used)

Time: 14:52


blocks_to_swap = 20

Transformer blocks on cpu: 5611.07MB

Transformer blocks on cuda:0: 5611.07MB

Total memory used by transformer blocks: 11222.15MB

Time: 14:08


blocks_to_swap = 0

Transformer blocks on cpu: 0.00MB

Transformer blocks on cuda:0: 11222.15MB

Total memory used by transformer blocks: 11222.15MB

Time: 13:34


When comparing the case where everything is processed in main memory with block swap to the case where everything is processed in VRAM, the main memory took about 10% longer. The difference may be even greater depending on the performance of the graphics card and the environment of the slot to which it is connected.

Since the processing time is reduced when the swap value is changed from 40 to 20, it can be seen that it is a good idea to process up to the limit of the capacity that the VRAM can handle and have the remainder handled by the main memory.

Furthermore, there was no change in the generated video. It can be said that changing this value will not change the results.



日本語(in Japanese)

動画生成には大量のVRAM(グラフィックカードのメモリ)が必要なため、VRAM容量が低い環境では生成を行うことができない場合があります。

Block Swap は本来VRAMに割り当てるメモリをPCのメインメモリに振り替える機能となります。

メインメモリはVRAMよりも速度が遅いですが、速度を犠牲にして OOM (Out of Memory) を防ぐことができます。


1. 計測条件

Model : WAN21_I2V_14B_480p_Q5_K_M.gguf

Text Encoder : umt5_xxl_fp8_e4m3fn_scaled.safetensors

Clip Vision : clip_vision_h.safetensors

VAE : WAN21_VAE_bf16.safetensors

steps = 20, CFG = 6.0, shift = 8.0


画像は 480x848 のこちらを使用します。


使用するワークフローは以前の記事で構築したこちらになります。このワークフロー画像をクリックするとGoogleドライブに保存された画像が表示されるので、そこからダウンロードしてComfyUIにドラッグ&ドロップすればワークフローが再現できます。カスタムノード WanVideoWrapper が導入されていない場合は、以前の記事を参考にインストールしてください。


以下のように WanVideo BlockSwap ノードを追加し、 WanVideo Model Loader ノードに接続します。


また、計測時のPC環境は以下となります。

M/B: MPG B550 GAMING PLUS (スロットが PCIE4.0 な点に注意)

CPU : Ryzen7 5700X

GPU : RTX5060ti 16GB

RAM : DDR4 3200 64GB (32GBx2)


2. 計測


WanVideo BlockSwap ノードの blocks_to_swap の値は 0 ~ 40 に設定できます。

blocks_to_swap の値を増やすほどメインメモリを使用します。後ほどの計測のとおり、値が 20 のとき VRAM とメインメモリの使用量は半々となります。値がゼロの時は、ノード未接続時と同じ結果となります。


それでは計測した結果を記載します。


blocks_to_swap = 40

Transformer blocks on cpu: 11222.15MB (これがメインメモリ使用量)

Transformer blocks on cuda:0: 0.00MB (これがVRAM使用量)

Total memory used by transformer blocks: 11222.15MB (合計メモリ使用量)

Time: 14:52


blocks_to_swap = 20

Transformer blocks on cpu: 5611.07MB

Transformer blocks on cuda:0: 5611.07MB

Total memory used by transformer blocks: 11222.15MB

Time: 14:08


blocks_to_swap = 0

Transformer blocks on cpu: 0.00MB

Transformer blocks on cuda:0: 11222.15MB

Total memory used by transformer blocks: 11222.15MB

Time: 13:34


すべてを VRAM で処理した結果に比べると、すべてメインメモリで賄った場合は 10% ほど処理時間が延びています。これはグラフィックカードの性能や周辺環境によりさらに顕著な差になる可能性があります。

swap の値が 40 と 20 でも時間の差がありました。このことから、VRAM で処理できるギリギリの量までは VRAM で処理し、残りをメインメモリに渡すのが良いことが分かります。

尚、block swap の値によって、生成された動画に変化はありませんでした。


Ko-fi

Major Contents

ブログ アーカイブ

Contact us

名前

メール *

メッセージ *

QooQ