Nodes/ComfyUI_Wan2_1_lora_trainer/Musubi Cache Latents (Wan)
ComfyUI Node

Musubi Cache Latents (Wan)

The precompute step that keeps training from re-encoding every image

By jaimitoes·Created about a year ago·Updated about a year ago· 61
Musubi Cache Latents (Wan)
  • trigger_in
  • dataset_toml_path
  • trigger_out
  • status_message
dataset_config_toml
vae_name
vae_dtypebfloat16
devicecuda
batch_size_override0
num_workers_override0
skip_existingfalse
keep_cachetrue
vae_cache_cpufalse
clip_nameNone

Second node in the jaimitoes/ComfyUI_Wan2_1_lora_trainer pipeline, right after WanDatasetConfig. Where the dataset node wrote the config, this one actually does work: it runs your images through the Wan VAE once, converts them to latent space, and saves the result so training never has to do it again. Cache the latents once, and every epoch of a multi-thousand-step run reads precomputed data off disk instead of re-encoding frames.

The pack is a GUI around kohya-ss/musubi-tuner, and this node is basically musubi's wan_cache_latents.py with a ComfyUI face. The README's whole pitch is that the entire process - write TOML, cache latents, cache text, train - runs in one shot because the nodes are chained by triggers. This is the middle of that chain.

How it works

You feed it the dataset_toml_path from WanDatasetConfig, plus a VAE. It constructs the same arguments the command-line cache script would take (via musubi's own argparse defaults, so your overrides land on top of sane defaults), then runs the cache. Output lands in the dataset1_cache_directory you set back in the config node. Because this is a long operation, the node computes an estimated batch count and drives ComfyUI's progress bar - the num_workers default scales off your CPU cores.

The inputs that matter

  • vae_name - the VAE for your base model (Wan 2.1 uses wan_2.1_vae.safetensors from the Comfy-Org repackage, or Wan2.1_VAE.pth). Wrong VAE, wrong latents, bad LoRA. Get this right.
  • vae_dtype - bfloat16 default; that's the right call for the balance of speed and quality.
  • clip_name - None unless you're training an I2V model. This is the pack's single most repeated warning: CLIP vision exists only for image-to-video. For T2V, leave it None or the cache stage will expect a clip vision model you don't need.
  • skip_existing - default off. Flip it on and the node skips files that already have cached versions, which is your resume button.
  • keep_cache - on by default. Leave it on; if you turn it off, processed data can get cleaned up.
  • vae_cache_cpu - off. If you're tight on VRAM on a big dataset, this shoves cached VAE outputs into system RAM instead. Slower, but it fits.

The batch_size_override and num_workers_override inputs are there if you want to diverge from the config's values; 0 means "use what the config says." device is cuda unless you enjoy waiting.

Outputs

All three wire forward:

  • dataset_toml_path (STRING) - the config path, passed through untouched.
  • trigger_out (any) - "latents_ok" on success, "error_trigger" on failure. Feed it to WanCacheTextEncoder's trigger_in.
  • status_message (STRING) - human-readable "completed" or "Skipped: prev error" text.

Install

Same as every node in this pack - it doesn't install alone:

cd ComfyUI/custom_nodes
git clone https://github.com/jaimitoes/ComfyUI_Wan2_1_lora_trainer
..\..\..\python_embeded\python -m pip install -r requirements.txt

then restart ComfyUI. Remember this pack is Windows-portable-oriented: launch from the README's custom .bat (which loads Visual Studio Build Tools) and extract Include_and_libs.zip into python_embeded or the subprocess training bits will break.

Where people get burned

The biggest is re-caching every time you restart training. The README says it straight: you can skip the latents and text caches if you're resuming and nothing about your VAE / clip vision / text model changed. Toggle skip_existing, keep your cache folders per-LoRA (mixing them poisons later runs), and a re-run starts almost immediately instead of re-encoding your whole dataset. And if the node spits back "ERROR: VAE not found" on a name you're sure exists - check the folder the file lives in; the node resolves names against ComfyUI's vae directory specifically.

Categorymusubi-tuner/wan/preprocess

Inputs (11)

NameTypeDefaultDescription
dataset_config_tomlSTRING
trigger_in*
vae_nameCOMBOVAE Model (Variational AutoEncoder). Select the VAE that is compatible with your base model. The VAE is like the model's "eyes," helping to encode and decode images during the process.
vae_dtypeCOMBObfloat16The data precision type for the VAE (the component that handles images). `bfloat16` is a good option for its balance between speed and quality.
deviceCOMBOcudaChoose the hardware device to use for processing. `cuda` uses your NVIDIA GPU (much faster), while `cpu` uses your computer's main processor (much slower).
batch_size_overrideINT0Override the default batch size used for processing data. `0` means use the default value from the dataset configuration. A higher number processes more items at once, but uses more memory.
num_workers_overrideINT0Override the default number of workers for loading data. `0` means use the default value from the dataset configuration. A higher number can speed up data loading, but consumes more CPU and RAM.
skip_existingBOOLEANfalseIf enabled, the node will skip processing files that already have existing cached versions, saving time and computation.
keep_cacheBOOLEANtrueIf enabled, the processed data will be kept in the cache directory even after this operation completes, so it can be reused later without reprocessing.
vae_cache_cpuBOOLEANfalseIf enabled, the VAE's processed outputs will be cached in your system's main memory (RAM) instead of GPU memory. Useful for saving VRAM, especially with large datasets, but can be slower if you have a slow CPU or hard drive.
clip_nameCOMBONoneCLIP Model (Vision). If your training is not for "Image-to-Video" (I2V) models, leave it as `None`. If it is I2V, select the appropriate CLIP model, as it helps the model understand the visual information from the input images.

Outputs (3)

NameTypeDescription
dataset_toml_pathSTRING
trigger_out*
status_messageSTRING