svjack's picture
Upload folder using huggingface_hub
ef46f0f verified

📝 Click on the language section to expand / 蚀語をクリックしお展開

Wan 2.1

Overview / 抂芁

This is an unofficial training and inference script for Wan2.1. The features are as follows.

  • fp8 support and memory reduction by block swap: Inference of a 720x1280x81frames videos with 24GB VRAM, training with 720x1280 images with 24GB VRAM
  • Inference without installing Flash attention (using PyTorch's scaled dot product attention)
  • Supports xformers and Sage attention

This feature is experimental.

日本語 [Wan2.1](https://github.com/Wan-Video/Wan2.1) の非公匏の孊習および掚論スクリプトです。

以䞋の特城がありたす。

  • fp8察応およびblock swapによる省メモリ化720x1280x81framesの動画を24GB VRAMで掚論可胜、720x1280の画像での孊習が24GB VRAMで可胜
  • Flash attentionのむンストヌルなしでの実行PyTorchのscaled dot product attentionを䜿甚
  • xformersおよびSage attention察応

この機胜は実隓的なものです。

Download the model / モデルのダりンロヌド

Download the T5 models_t5_umt5-xxl-enc-bf16.pth and CLIP models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth from the following page: https://huggingface.co/Wan-AI/Wan2.1-I2V-14B-720P/tree/main

Download the VAE from the above page Wan2.1_VAE.pth or download split_files/vae/wan_2.1_vae.safetensors from the following page: https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/tree/main/split_files/vae

Download the DiT weights from the following page: https://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/tree/main/split_files/diffusion_models

Wan2.1 Fun Control model weights can be downloaded from here. Navigate to each weight page and download. The Fun Control model seems to support not only T2V but also I2V tasks.

Please select the appropriate weights according to T2V, I2V, resolution, model size, etc.

fp16 and bf16 models can be used, and fp8_e4m3fn models can be used if --fp8 (or --fp8_base) is specified without specifying --fp8_scaled. Please note that fp8_scaled models are not supported even with --fp8_scaled.

(Thanks to Comfy-Org for providing the repackaged weights.)

Model support matrix / モデルサポヌトマトリックス

  • columns: training dtype (行孊習時のデヌタ型)
  • rows: model dtype (列モデルのデヌタ型)
model \ training bf16 fp16 --fp8_base --fp8base & --fp8_scaled
bf16 ✓ -- ✓ ✓
fp16 -- ✓ ✓ ✓
fp8_e4m3fn -- -- ✓ --
fp8_scaled -- -- -- --
日本語 T5 `models_t5_umt5-xxl-enc-bf16.pth` およびCLIP `models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth` を、次のペヌゞからダりンロヌドしおくださいhttps://huggingface.co/Wan-AI/Wan2.1-I2V-14B-720P/tree/main

VAEは䞊のペヌゞから Wan2.1_VAE.pth をダりンロヌドするか、次のペヌゞから split_files/vae/wan_2.1_vae.safetensors をダりンロヌドしおくださいhttps://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/tree/main/split_files/vae

DiTの重みを次のペヌゞからダりンロヌドしおくださいhttps://huggingface.co/Comfy-Org/Wan_2.1_ComfyUI_repackaged/tree/main/split_files/diffusion_models

Wan2.1 Fun Controlモデルの重みは、こちらから、それぞれの重みのペヌゞに遷移し、ダりンロヌドしおください。Fun ControlモデルはT2VだけでなくI2Vタスクにも察応しおいるようです。

T2VやI2V、解像床、モデルサむズなどにより適切な重みを遞択しおください。

fp16 および bf16 モデルを䜿甚できたす。たた、--fp8 たたは--fp8_baseを指定し--fp8_scaledを指定をしないずきには fp8_e4m3fn モデルを䜿甚できたす。**fp8_scaled モデルはいずれの堎合もサポヌトされおいたせんのでご泚意ください。**

repackaged版の重みを提䟛しおくださっおいるComfy-Orgに感謝いたしたす。

Pre-caching / 事前キャッシュ

Latent Pre-caching

Latent pre-caching is almost the same as in HunyuanVideo. Create the cache using the following command:

python wan_cache_latents.py --dataset_config path/to/toml --vae path/to/wan_2.1_vae.safetensors

If you train I2V models, add --clip path/to/models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth to specify the CLIP model. If not specified, the training will raise an error.

If you're running low on VRAM, specify --vae_cache_cpu to use the CPU for the VAE internal cache, which will reduce VRAM usage somewhat.

The control video settings are required for training the Fun-Control model. Please refer to Dataset Settings for details.

日本語 latentの事前キャッシングはHunyuanVideoずほが同じです。䞊のコマンド䟋を䜿甚しおキャッシュを䜜成しおください。

I2Vモデルを孊習する堎合は、--clip path/to/models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth を远加しおCLIPモデルを指定しおください。指定しないず孊習時に゚ラヌが発生したす。

VRAMが䞍足しおいる堎合は、--vae_cache_cpu を指定するずVAEの内郚キャッシュにCPUを䜿うこずで、䜿甚VRAMを倚少削枛できたす。

Fun-Controlモデルを孊習する堎合は、制埡甚動画の蚭定が必芁です。デヌタセット蚭定を参照しおください。

Text Encoder Output Pre-caching

Text encoder output pre-caching is also almost the same as in HunyuanVideo. Create the cache using the following command:

python wan_cache_text_encoder_outputs.py --dataset_config path/to/toml  --t5 path/to/models_t5_umt5-xxl-enc-bf16.pth --batch_size 16 

Adjust --batch_size according to your available VRAM.

For systems with limited VRAM (less than ~16GB), use --fp8_t5 to run the T5 in fp8 mode.

日本語 テキスト゚ンコヌダ出力の事前キャッシングもHunyuanVideoずほが同じです。䞊のコマンド䟋を䜿甚しおキャッシュを䜜成しおください。

䜿甚可胜なVRAMに合わせお --batch_size を調敎しおください。

VRAMが限られおいるシステム玄16GB未満の堎合は、T5をfp8モヌドで実行するために --fp8_t5 を䜿甚しおください。

Training / å­Šç¿’

Training

Start training using the following command (input as a single line):

accelerate launch --num_cpu_threads_per_process 1 --mixed_precision bf16 wan_train_network.py 
    --task t2v-1.3B 
    --dit path/to/wan2.1_xxx_bf16.safetensors 
    --dataset_config path/to/toml --sdpa --mixed_precision bf16 --fp8_base 
    --optimizer_type adamw8bit --learning_rate 2e-4 --gradient_checkpointing 
    --max_data_loader_n_workers 2 --persistent_data_loader_workers 
    --network_module networks.lora_wan --network_dim 32 
    --timestep_sampling shift --discrete_flow_shift 3.0 
    --max_train_epochs 16 --save_every_n_epochs 1 --seed 42
    --output_dir path/to/output_dir --output_name name-of-lora

The above is an example. The appropriate values for timestep_sampling and discrete_flow_shift need to be determined by experimentation.

For additional options, use python wan_train_network.py --help (note that many options are unverified).

--task is one of t2v-1.3B, t2v-14B, i2v-14B, t2i-14B (for Wan2.1 official models), t2v-1.3B-FC, t2v-14B-FC, and i2v-14B-FC (for Wan2.1 Fun Control model). Specify the DiT weights for the task with --dit.

Don't forget to specify --network_module networks.lora_wan.

Other options are mostly the same as hv_train_network.py.

Use convert_lora.py for converting the LoRA weights after training, as in HunyuanVideo.

日本語 `timestep_sampling`や`discrete_flow_shift`は䞀䟋です。どのような倀が適切かは実隓が必芁です。

その他のオプションに぀いおは python wan_train_network.py --help を䜿甚しおください倚くのオプションは未怜蚌です。

--task には t2v-1.3B, t2v-14B, i2v-14B, t2i-14B これらはWan2.1公匏モデル、t2v-1.3B-FC, t2v-14B-FC, i2v-14B-FCWan2.1-Fun Controlモデルを指定したす。--ditに、taskに応じたDiTの重みを指定しおください。

--network_module に networks.lora_wan を指定するこずを忘れないでください。

その他のオプションは、ほがhv_train_network.pyず同様です。

孊習埌のLoRAの重みの倉換は、HunyuanVideoず同様にconvert_lora.pyを䜿甚しおください。

Command line options for training with sampling / サンプル画像生成に関連する孊習時のコマンドラむンオプション

Example of command line options for training with sampling / 蚘述䟋:

--vae path/to/wan_2.1_vae.safetensors 
--t5 path/to/models_t5_umt5-xxl-enc-bf16.pth 
--sample_prompts /path/to/prompt_file.txt 
--sample_every_n_epochs 1 --sample_every_n_steps 1000 -- sample_at_first

Each option is the same as when generating images or as HunyuanVideo. Please refer to here for details.

If you train I2V models, add --clip path/to/models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth to specify the CLIP model.

You can specify the initial image, the negative prompt and the control video (for Wan2.1-Fun-Control) in the prompt file. Please refer to here.

日本語 各オプションは掚論時、およびHunyuanVideoの堎合ず同様です。[こちら](/docs/sampling_during_training.md)を参照しおください。

I2Vモデルを孊習する堎合は、--clip path/to/models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth を远加しおCLIPモデルを指定しおください。

プロンプトファむルで、初期画像やネガティブプロンプト、制埡動画Wan2.1-Fun-Control甚等を指定できたす。こちらを参照しおください。

Inference / 掚論

Inference Options Comparison / 掚論オプション比范

Speed Comparison (Faster → Slower) / 速床比范速い→遅い

Note: Results may vary depending on GPU type

fp8_fast > bf16/fp16 (no block swap) > fp8 > fp8_scaled > bf16/fp16 (block swap)

Quality Comparison (Higher → Lower) / 品質比范高→䜎

bf16/fp16 > fp8_scaled > fp8 >> fp8_fast

T2V Inference / T2V掚論

The following is an example of T2V inference (input as a single line):

python wan_generate_video.py --fp8 --task t2v-1.3B --video_size  832 480 --video_length 81 --infer_steps 20 
--prompt "prompt for the video" --save_path path/to/save.mp4 --output_type both 
--dit path/to/wan2.1_t2v_1.3B_bf16_etc.safetensors --vae path/to/wan_2.1_vae.safetensors 
--t5 path/to/models_t5_umt5-xxl-enc-bf16.pth 
--attn_mode torch

--task is one of t2v-1.3B, t2v-14B, i2v-14B, t2i-14B (these are Wan2.1 official models), t2v-1.3B-FC, t2v-14B-FC and i2v-14B-FC (for Wan2.1-Fun Control model).

--attn_mode is torch, sdpa (same as torch), xformers, sageattn,flash2, flash (same as flash2) or flash3. torch is the default. Other options require the corresponding library to be installed. flash3 (Flash attention 3) is not tested.

Specifying --fp8 runs DiT in fp8 mode. fp8 can significantly reduce memory consumption but may impact output quality.

--fp8_scaled can be specified in addition to --fp8 to run the model in fp8 weights optimization. This increases memory consumption and speed slightly but improves output quality. See here for details.

--fp8_fast option is also available for faster inference on RTX 40x0 GPUs. This option requires --fp8_scaled option. This option seems to degrade the output quality.

--fp8_t5 can be used to specify the T5 model in fp8 format. This option reduces memory usage for the T5 model.

--negative_prompt can be used to specify a negative prompt. If omitted, the default negative prompt is used.

--flow_shift can be used to specify the flow shift (default 3.0 for I2V with 480p, 5.0 for others).

--guidance_scale can be used to specify the guidance scale for classifier free guidance (default 5.0).

--blocks_to_swap is the number of blocks to swap during inference. The default value is None (no block swap). The maximum value is 39 for 14B model and 29 for 1.3B model.

--vae_cache_cpu enables VAE cache in main memory. This reduces VRAM usage slightly but processing is slower.

--compile enables torch.compile. See here for details.

--trim_tail_frames can be used to trim the tail frames when saving. The default is 0.

--cfg_skip_mode specifies the mode for skipping CFG in different steps. The default is none (all steps).--cfg_apply_ratio specifies the ratio of steps where CFG is applied. See below for details.

--include_patterns and --exclude_patterns can be used to specify which LoRA modules to apply or exclude during training. If not specified, all modules are applied by default. These options accept regular expressions.

--include_patterns specifies the modules to be applied, and --exclude_patterns specifies the modules to be excluded. The regular expression is matched against the LoRA key name, and include takes precedence.

The key name to be searched is in sd-scripts format (lora_unet_<module_name with dot replaced by _>). For example, lora_unet_blocks_9_cross_attn_k.

For example, if you specify --exclude_patterns "blocks_[23]\d_", it will exclude modules containing blocks_20 to blocks_39. If you specify --include_patterns "cross_attn" --exclude_patterns "blocks_(0|1|2|3|4)_", it will apply LoRA to modules containing cross_attn and not containing blocks_0 to blocks_4.

If you specify multiple LoRA weights, please specify them with multiple arguments. For example: --include_patterns "cross_attn" ".*" --exclude_patterns "dummy_do_not_exclude" "blocks_(0|1|2|3|4)". ".*" is a regex that matches everything. dummy_do_not_exclude is a dummy regex that does not match anything.

--cpu_noise generates initial noise on the CPU. This may result in the same results as ComfyUI with the same seed (depending on other settings).

If you are using the Fun Control model, specify the control video with --control_path. You can specify a video file or a folder containing multiple image files. The number of frames in the video file (or the number of images) should be at least the number specified in --video_length (plus 1 frame if you specify --end_image_path).

Please try to match the aspect ratio of the control video with the aspect ratio specified in --video_size (there may be some deviation from the initial image of I2V due to the use of bucketing processing).

Other options are same as hv_generate_video.py (some options are not supported, please check the help).

日本語 `--task` には `t2v-1.3B`, `t2v-14B`, `i2v-14B`, `t2i-14B` これらはWan2.1公匏モデル、`t2v-1.3B-FC`, `t2v-14B-FC`, `i2v-14B-FC`Wan2.1-Fun Controlモデルを指定したす。

--attn_mode には torch, sdpatorchず同じ、xformers, sageattn, flash2, flashflash2ず同じ, flash3 のいずれかを指定したす。デフォルトは torch です。その他のオプションを䜿甚する堎合は、察応するラむブラリをむンストヌルする必芁がありたす。flash3Flash attention 3は未テストです。

--fp8 を指定するずDiTモデルをfp8圢匏で実行したす。fp8はメモリ消費を倧幅に削枛できたすが、出力品質に圱響を䞎える可胜性がありたす。

--fp8_scaled を --fp8 ず䜵甚するず、fp8ぞの重み量子化を行いたす。メモリ消費ず速床はわずかに悪化したすが、出力品質が向䞊したす。詳しくはこちらを参照しおください。

--fp8_fast オプションはRTX 40x0 GPUでの高速掚論に䜿甚されるオプションです。このオプションは --fp8_scaled オプションが必芁です。出力品質が劣化するようです。

--fp8_t5 を指定するずT5モデルをfp8圢匏で実行したす。T5モデル呌び出し時のメモリ䜿甚量を削枛したす。

--negative_prompt でネガティブプロンプトを指定できたす。省略した堎合はデフォルトのネガティブプロンプトが䜿甚されたす。

--flow_shift でflow shiftを指定できたす480pのI2Vの堎合はデフォルト3.0、それ以倖は5.0。

--guidance_scale でclassifier free guianceのガむダンススケヌルを指定できたすデフォルト5.0。

--blocks_to_swap は掚論時のblock swapの数です。デフォルト倀はNoneblock swapなしです。最倧倀は14Bモデルの堎合39、1.3Bモデルの堎合29です。

--vae_cache_cpu を有効にするず、VAEのキャッシュをメむンメモリに保持したす。VRAM䜿甚量が倚少枛りたすが、凊理は遅くなりたす。

--compileでtorch.compileを有効にしたす。詳现に぀いおはこちらを参照しおください。

--trim_tail_frames で保存時に末尟のフレヌムをトリミングできたす。デフォルトは0です。

--cfg_skip_mode は異なるステップでCFGをスキップするモヌドを指定したす。デフォルトは none党ステップ。--cfg_apply_ratio はCFGが適甚されるステップの割合を指定したす。詳现は埌述したす。

LoRAのどのモゞュヌルを適甚するかを、--include_patternsず--exclude_patternsで指定できたす未指定時・デフォルトは党モゞュヌル適甚されたす 。これらのオプションには、正芏衚珟を指定したす。--include_patternsは適甚するモゞュヌル、--exclude_patternsは適甚しないモゞュヌルを指定したす。正芏衚珟がLoRAのキヌ名に含たれるかどうかで刀断され、includeが優先されたす。

怜玢察象ずなるキヌ名は sd-scripts 圢匏lora_unet_<モゞュヌル名のドットを_に眮換したもの>です。䟋lora_unet_blocks_9_cross_attn_k

たずえば --exclude_patterns "blocks_[23]\d_"のみを指定するず、blocks_20からblocks_39を含むモゞュヌルが陀倖されたす。--include_patterns "cross_attn" --exclude_patterns "blocks_(0|1|2|3|4)_"のようにincludeずexcludeを指定するず、cross_attnを含むモゞュヌルで、か぀blocks_0からblocks_4を含たないモゞュヌルにLoRAが適甚されたす。

耇数のLoRAの重みを指定する堎合は、耇数個の匕数で指定しおください。䟋--include_patterns "cross_attn" ".*" --exclude_patterns "dummy_do_not_exclude" "blocks_(0|1|2|3|4)" ".*"は党おにマッチする正芏衚珟です。dummy_do_not_excludeは䜕にもマッチしないダミヌの正芏衚珟です。

--cpu_noiseを指定するず初期ノむズをCPUで生成したす。これにより同䞀seed時の結果がComfyUIず同じになる可胜性がありたす他の蚭定にもよりたす。

Fun Controlモデルを䜿甚する堎合は、--control_pathで制埡甚の映像を指定したす。動画ファむル、たたは耇数枚の画像ファむルを含んだフォルダを指定できたす。動画ファむルのフレヌム数たたは画像の枚数は、--video_lengthで指定したフレヌム数以䞊にしおください埌述の--end_image_pathを指定した堎合は、さらに+1フレヌム。

制埡甚の映像のアスペクト比は、--video_sizeで指定したアスペクト比ずできるかぎり合わせおくださいbucketingの凊理を流甚しおいるためI2Vの初期画像ずズレる堎合がありたす。

その他のオプションは hv_generate_video.py ず同じです䞀郚のオプションはサポヌトされおいないため、ヘルプを確認しおください。

CFG Skip Mode / CFGスキップモヌド

These options allow you to balance generation speed against prompt accuracy. More skipped steps results in faster generation with potential quality degradation.

Setting --cfg_apply_ratio to 0.5 speeds up the denoising loop by up to 25%.

--cfg_skip_mode specified one of the following modes:

  • early: Skips CFG in early steps for faster generation, applying guidance mainly in later refinement steps
  • late: Skips CFG in later steps, applying guidance during initial structure formation
  • middle: Skips CFG in middle steps, applying guidance in both early and later steps
  • early_late: Skips CFG in both early and late steps, applying only in middle steps
  • alternate: Applies CFG in alternate steps based on the specified ratio
  • none: Applies CFG at all steps (default)

--cfg_apply_ratio specifies a value from 0.0 to 1.0 controlling the proportion of steps where CFG is applied. For example, setting 0.5 means CFG will be applied in only 50% of the steps.

If num_steps is 10, the following table shows the steps where CFG is applied based on the --cfg_skip_mode option (A means CFG is applied, S means it is skipped, --cfg_apply_ratio is 0.6):

skip mode CFG apply pattern
early SSSSAAAAAA
late AAAAAASSSS
middle AAASSSSAAA
early_late SSAAAAAASS
alternate SASASAASAS

The appropriate settings are unknown, but you may want to try late or early_late mode with a ratio of around 0.3 to 0.5.

日本語 これらのオプションは、生成速床ずプロンプトの粟床のバランスを取るこずができたす。スキップされるステップが倚いほど、生成速床が速くなりたすが、品質が䜎䞋する可胜性がありたす。

ratioに0.5を指定するこずで、デノむゞングのルヌプが最倧25%皋床、高速化されたす。

--cfg_skip_mode は次のモヌドのいずれかを指定したす

  • early初期のステップでCFGをスキップしお、䞻に終盀の粟现化のステップで適甚したす
  • late終盀のステップでCFGをスキップし、初期の構造が決たる段階で適甚したす
  • middle䞭間のステップでCFGをスキップし、初期ず終盀のステップの䞡方で適甚したす
  • early_late初期ず終盀のステップの䞡方でCFGをスキップし、䞭間のステップのみ適甚したす
  • alternate指定された割合に基づいおCFGを適甚したす

--cfg_apply_ratio は、CFGが適甚されるステップの割合を0.0から1.0の倀で指定したす。たずえば、0.5に蚭定するず、CFGはステップの50%のみで適甚されたす。

具䜓的なパタヌンは䞊のテヌブルを参照しおください。

適切な蚭定は䞍明ですが、モヌドはlateたたはearly_late、ratioは0.3~0.5皋床から詊しおみるず良いかもしれたせん。

Skip Layer Guidance

Skip Layer Guidance is a feature that uses the output of a model with some blocks skipped as the unconditional output of classifier free guidance. It was originally proposed in SD 3.5 and first applied in Wan2GP in this PR. It may improve the quality of generated videos.

The implementation of SD 3.5 is here, and the implementation of Wan2GP (the PR mentioned above) has some different specifications. This inference script allows you to choose between the two methods.

The SD3.5 method applies slg output in addition to cond and uncond (slows down the speed). The Wan2GP method uses only cond and slg output.

The following arguments are available:

  • --slg_mode: Specifies the SLG mode. original for SD 3.5 method, uncond for Wan2GP method. Default is None (no SLG).
  • --slg_layers: Specifies the indices of the blocks (layers) to skip in SLG, separated by commas. Example: --slg_layers 4,5,6. Default is empty (no skip). If this option is not specified, --slg_mode is ignored.
  • --slg_scale: Specifies the scale of SLG when original. Default is 3.0.
  • --slg_start: Specifies the start step of SLG application in inference steps from 0.0 to 1.0. Default is 0.0 (applied from the beginning).
  • --slg_end: Specifies the end step of SLG application in inference steps from 0.0 to 1.0. Default is 0.3 (applied up to 30% from the beginning).

Appropriate settings are unknown, but you may want to try original mode with a scale of around 3.0 and a start ratio of 0.0 and an end ratio of 0.5, with layers 4, 5, and 6 skipped.

日本語 Skip Layer Guidanceは、䞀郚のblockをスキップしたモデル出力をclassifier free guidanceのunconditional出力に䜿甚する機胜です。元々は[SD 3.5](https://github.com/comfyanonymous/ComfyUI/pull/5404)で提案されたもので、Wan2.1には[Wan2GPのこちらのPR](https://github.com/deepbeepmeep/Wan2GP/pull/61)で初めお適甚されたした。生成動画の品質が向䞊する可胜性がありたす。

SD 3.5の実装はこちらで、Wan2GPの実装前述のPRは䞀郚仕様が異なりたす。この掚論スクリプトでは䞡者の方匏を遞択できるようになっおいたす。

※SD3.5方匏はcondずuncondに加えおslg outputを適甚したす速床が䜎䞋したす。Wan2GP方匏はcondずslg outputのみを䜿甚したす。

以䞋の匕数がありたす。

  • --slg_modeSLGのモヌドを指定したす。originalでSD 3.5の方匏、uncondでWan2GPの方匏です。デフォルトはNoneで、SLGを䜿甚したせん。
  • --slg_layersSLGでスキップするblock (layer)のむンデクスをカンマ区切りで指定したす。䟋--slg_layers 4,5,6。デフォルトは空スキップしないです。このオプションを指定しないず--slg_modeは無芖されたす。
  • --slg_scaleoriginalのずきのSLGのスケヌルを指定したす。デフォルトは3.0です。
  • --slg_start掚論ステップのSLG適甚開始ステップを0.0から1.0の割合で指定したす。デフォルトは0.0です最初から適甚。
  • --slg_end掚論ステップのSLG適甚終了ステップを0.0から1.0の割合で指定したす。デフォルトは0.3です最初から30%たで適甚。

適切な蚭定は䞍明ですが、originalモヌドでスケヌルを3.0皋床、開始割合を0.0、終了割合を0.5皋床に蚭定し、4, 5, 6のlayerをスキップする蚭定から始めるず良いかもしれたせん。

I2V Inference / I2V掚論

The following is an example of I2V inference (input as a single line):

python wan_generate_video.py --fp8 --task i2v-14B --video_size 832 480 --video_length 81 --infer_steps 20 
--prompt "prompt for the video" --save_path path/to/save.mp4 --output_type both 
--dit path/to/wan2.1_i2v_480p_14B_bf16_etc.safetensors --vae path/to/wan_2.1_vae.safetensors 
--t5 path/to/models_t5_umt5-xxl-enc-bf16.pth --clip path/to/models_clip_open-clip-xlm-roberta-large-vit-huge-14.pth 
--attn_mode torch --image_path path/to/image.jpg

Add --clip to specify the CLIP model. --image_path is the path to the image to be used as the initial frame.

--end_image_path can be used to specify the end image. This option is experimental. When this option is specified, the saved video will be slightly longer than the specified number of frames and will have noise, so it is recommended to specify --trim_tail_frames 3 to trim the tail frames.

You can also use the Fun Control model for I2V inference. Specify the control video with --control_path.

Other options are same as T2V inference.

日本語 `--clip` を远加しおCLIPモデルを指定したす。`--image_path` は初期フレヌムずしお䜿甚する画像のパスです。

--end_image_path で終了画像を指定できたす。このオプションは実隓的なものです。このオプションを指定するず、保存される動画が指定フレヌム数よりもやや倚くなり、か぀ノむズが乗るため、--trim_tail_frames 3 などを指定しお末尟のフレヌムをトリミングするこずをお勧めしたす。

I2V掚論でもFun Controlモデルが䜿甚できたす。--control_path で制埡甚の映像を指定したす。

その他のオプションはT2V掚論ず同じです。

New Batch and Interactive Modes / 新しいバッチモヌドずむンタラクティブモヌド

In addition to single video generation, Wan 2.1 now supports batch generation from file and interactive prompt input:

Batch Mode from File / ファむルからのバッチモヌド

Generate multiple videos from prompts stored in a text file:

python wan_generate_video.py --from_file prompts.txt --task t2v-14B 
--dit path/to/model.safetensors --vae path/to/vae.safetensors 
--t5 path/to/t5_model.pth --save_path output_directory

The prompts file format:

  • One prompt per line
  • Empty lines and lines starting with # are ignored (comments)
  • Each line can include prompt-specific parameters using command-line style format:
A beautiful sunset over mountains --w 832 --h 480 --f 81 --d 42 --s 20
A busy city street at night --w 480 --h 832 --g 7.5 --n low quality, blurry

Supported inline parameters (if ommitted, default values from the command line are used):

  • --w: Width
  • --h: Height
  • --f: Frame count
  • --d: Seed
  • --s: Inference steps
  • --g or --l: Guidance scale
  • --fs: Flow shift
  • --i: Image path (for I2V)
  • --cn: Control path (for Fun Control)
  • --n: Negative prompt

In batch mode, models are loaded once and reused for all prompts, significantly improving overall generation time compared to multiple single runs.

Interactive Mode / むンタラクティブモヌド

Interactive command-line interface for entering prompts:

python wan_generate_video.py --interactive --task t2v-14B 
--dit path/to/model.safetensors --vae path/to/vae.safetensors 
--t5 path/to/t5_model.pth --save_path output_directory

In interactive mode:

  • Enter prompts directly at the command line
  • Use the same inline parameter format as batch mode
  • Use Ctrl+D (or Ctrl+Z on Windows) to exit
  • Models remain loaded between generations for efficiency
日本語 単䞀動画の生成に加えお、Wan 2.1は珟圚、ファむルからのバッチ生成ずむンタラクティブなプロンプト入力をサポヌトしおいたす。

ファむルからのバッチモヌド

テキストファむルに保存されたプロンプトから耇数の動画を生成したす

python wan_generate_video.py --from_file prompts.txt --task t2v-14B 
--dit path/to/model.safetensors --vae path/to/vae.safetensors 
--t5 path/to/t5_model.pth --save_path output_directory

プロンプトファむルの圢匏

  • 1行に1぀のプロンプト
  • 空行や#で始たる行は無芖されたすコメント
  • 各行にはコマンドラむン圢匏でプロンプト固有のパラメヌタを含めるこずができたす

サポヌトされおいるむンラむンパラメヌタ省略した堎合、コマンドラむンのデフォルト倀が䜿甚されたす

  • --w: 幅
  • --h: 高さ
  • --f: フレヌム数
  • --d: シヌド
  • --s: 掚論ステップ
  • --g たたは --l: ガむダンススケヌル
  • --fs: フロヌシフト
  • --i: 画像パスI2V甚
  • --cn: コントロヌルパスFun Control甚
  • --n: ネガティブプロンプト

バッチモヌドでは、モデルは䞀床だけロヌドされ、すべおのプロンプトで再利甚されるため、耇数回の単䞀実行ず比范しお党䜓的な生成時間が倧幅に改善されたす。

むンタラクティブモヌド

プロンプトを入力するためのむンタラクティブなコマンドラむンむンタヌフェヌス

python wan_generate_video.py --interactive --task t2v-14B 
--dit path/to/model.safetensors --vae path/to/vae.safetensors 
--t5 path/to/t5_model.pth --save_path output_directory

むンタラクティブモヌドでは

  • コマンドラむンで盎接プロンプトを入力
  • バッチモヌドず同じむンラむンパラメヌタ圢匏を䜿甚
  • 終了するには Ctrl+D (Windowsでは Ctrl+Z) を䜿甚
  • 効率のため、モデルは生成間で読み蟌たれたたたになりたす