asd / docs /hunyuan_video.md
FusionCow's picture
Add files using upload-large-folder tool
157a4c0 verified

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

HunyuanVideo

Overview / 概要

This document describes the usage of the HunyuanVideo architecture within the Musubi Tuner framework. HunyuanVideo is a video generation model that supports text-to-video generation.

This feature is experimental.

日本語

このドキュメントは、Musubi Tunerフレームワーク内でのHunyuanVideoアーキテクチャの使用法について説明しています。HunyuanVideoはテキストから動画を生成するモデルです。

この機能は実験的なものです。

Download the model / モデルのダウンロード

There are two ways to download the model.

Use the Official HunyuanVideo Model / 公式HunyuanVideoモデルを使う

Download the model following the official README and place it in your chosen directory with the following structure:

  ckpts
    ├──hunyuan-video-t2v-720p
    │  ├──transformers
    │  ├──vae
    ├──text_encoder
    ├──text_encoder_2
    ├──...

Using ComfyUI Models for Text Encoder / Text EncoderにComfyUI提供のモデルを使う

This method is easier.

For DiT and VAE, use the HunyuanVideo models.

From https://huggingface.co/tencent/HunyuanVideo/tree/main/hunyuan-video-t2v-720p/transformers, download mp_rank_00_model_states.pt and place it in your chosen directory.

(Note: The fp8 model on the same page is unverified.)

If you are training with --fp8_base, you can use mp_rank_00_model_states_fp8.safetensors from here instead of mp_rank_00_model_states.pt. (This file is unofficial and simply converts the weights to float8_e4m3fn.)

From https://huggingface.co/tencent/HunyuanVideo/tree/main/hunyuan-video-t2v-720p/vae, download pytorch_model.pt and place it in your chosen directory.

For the Text Encoder, use the models provided by ComfyUI. Refer to ComfyUI's page, from https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/tree/main/split_files/text_encoders, download llava_llama3_fp16.safetensors (Text Encoder 1, LLM) and clip_l.safetensors (Text Encoder 2, CLIP) and place them in your chosen directory.

(Note: The fp8 LLM model on the same page is unverified.)

日本語

以下のいずれかの方法で、モデルをダウンロードしてください。

HunyuanVideoの公式モデルを使う

公式のREADMEを参考にダウンロードし、任意のディレクトリに以下のように配置します。

  ckpts
    ├──hunyuan-video-t2v-720p
    │  ├──transformers
    │  ├──vae
    ├──text_encoder
    ├──text_encoder_2
    ├──...

Text EncoderにComfyUI提供のモデルを使う

こちらの方法の方がより簡単です。DiTとVAEのモデルはHumyuanVideoのものを使用します。

https://huggingface.co/tencent/HunyuanVideo/tree/main/hunyuan-video-t2v-720p/transformers から、mp_rank_00_model_states.pt をダウンロードし、任意のディレクトリに配置します。

(同じページにfp8のモデルもありますが、未検証です。)

--fp8_baseを指定して学習する場合は、mp_rank_00_model_states.ptの代わりに、こちらmp_rank_00_model_states_fp8.safetensorsを使用可能です。(このファイルは非公式のもので、重みを単純にfloat8_e4m3fnに変換したものです。)

また、https://huggingface.co/tencent/HunyuanVideo/tree/main/hunyuan-video-t2v-720p/vae から、pytorch_model.pt をダウンロードし、任意のディレクトリに配置します。

Text EncoderにはComfyUI提供のモデルを使用させていただきます。ComyUIのページを参考に、https://huggingface.co/Comfy-Org/HunyuanVideo_repackaged/tree/main/split_files/text_encoders から、llava_llama3_fp16.safetensors (Text Encoder 1、LLM)と、clip_l.safetensors (Text Encoder 2、CLIP)をダウンロードし、任意のディレクトリに配置します。

(同じページにfp8のLLMモデルもありますが、動作未検証です。)

Pre-caching / 事前キャッシング

Latent Pre-caching / latentの事前キャッシング

Latent pre-caching is required. Create the cache using the following command:

If you have installed using pip:

python src/musubi_tuner/cache_latents.py --dataset_config path/to/toml --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt --vae_chunk_size 32 --vae_tiling

If you have installed with uv, you can use uv run --extra cu124 to run the script. If CUDA 12.8 or 13.0 is supported, uv run --extra cu128 or uv run --extra cu130 is also available. Other scripts can be run in the same way. (Note that the installation with uv is experimental. Feedback is welcome. If you encounter any issues, please use the pip-based installation.)

uv run --extra cu124 src/musubi_tuner/cache_latents.py --dataset_config path/to/toml --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt --vae_chunk_size 32 --vae_tiling

For additional options, use python src/musubi_tuner/cache_latents.py --help.

If you're running low on VRAM, reduce --vae_spatial_tile_sample_min_size to around 128 and lower the --batch_size (--vae_spatial_tile_sample_min_size may not exist in architectures other than HunyuanVideo, see the documentation for each architecture).

If you are using an AMD GPU and/or are experiencing slow latent caching, consider trying --disable_cudnn_backend. For some details, see this pull request.

Use --debug_mode image to display dataset images and captions in a new window, or --debug_mode console to display them in the console (requires ascii-magic).

With --debug_mode video, images or videos will be saved in the cache directory (please delete them after checking). The bitrate of the saved video is set to 1Mbps for preview purposes. The images decoded from the original video (not degraded) are used for the cache (for training).

When --debug_mode is specified, the actual caching process is not performed.

By default, cache files not included in the dataset are automatically deleted. You can still keep cache files as before by specifying --keep_cache.

日本語

latentの事前キャッシュは必須です。以下のコマンドを使用して、事前キャッシュを作成してください。(pipによるインストールの場合)

python src/musubi_tuner/cache_latents.py --dataset_config path/to/toml --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt --vae_chunk_size 32 --vae_tiling

uvでインストールした場合は、uv run --extra cu124 python src/musubi_tuner/cache_latents.py ...のように、uv run --extra cu124を先頭につけてください。CUDA 12.8や13.0に対応している場合は、uv run --extra cu128uv run --extra cu130も利用可能です。以下のコマンドも同様です。

その他のオプションはpython src/musubi_tuner/cache_latents.py --helpで確認できます。

VRAMが足りない場合は、--vae_spatial_tile_sample_min_sizeを128程度に減らし、--batch_sizeを小さくしてください。

--debug_mode image を指定するとデータセットの画像とキャプションが新規ウィンドウに表示されます。--debug_mode consoleでコンソールに表示されます(ascii-magicが必要)。

--debug_mode videoで、キャッシュディレクトリに画像または動画が保存されます(確認後、削除してください)。動画のビットレートは確認用に低くしてあります。実際には元動画の画像が学習に使用されます。

--debug_mode指定時は、実際のキャッシュ処理は行われません。

デフォルトではデータセットに含まれないキャッシュファイルは自動的に削除されます。--keep_cacheを指定すると、キャッシュファイルを残すことができます。

Text Encoder Output Pre-caching / テキストエンコーダー出力の事前キャッシング

Text Encoder output pre-caching is required. Create the cache using the following command:

python src/musubi_tuner/cache_text_encoder_outputs.py --dataset_config path/to/toml  --text_encoder1 path/to/ckpts/text_encoder --text_encoder2 path/to/ckpts/text_encoder_2 --batch_size 16

or for uv:

uv run --extra cu124 src/musubi_tuner/cache_text_encoder_outputs.py --dataset_config path/to/toml  --text_encoder1 path/to/ckpts/text_encoder --text_encoder2 path/to/ckpts/text_encoder_2 --batch_size 16

For additional options, use python src/musubi_tuner/cache_text_encoder_outputs.py --help.

Adjust --batch_size according to your available VRAM.

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

By default, cache files not included in the dataset are automatically deleted. You can still keep cache files as before by specifying --keep_cache.

日本語

Text Encoder出力の事前キャッシュは必須です。以下のコマンドを使用して、事前キャッシュを作成してください。

python src/musubi_tuner/cache_text_encoder_outputs.py --dataset_config path/to/toml  --text_encoder1 path/to/ckpts/text_encoder --text_encoder2 path/to/ckpts/text_encoder_2 --batch_size 16

その他のオプションはpython src/musubi_tuner/cache_text_encoder_outputs.py --helpで確認できます。

--batch_sizeはVRAMに合わせて調整してください。

VRAMが足りない場合(16GB程度未満の場合)は、--fp8_llmを指定して、fp8でLLMを実行してください。

デフォルトではデータセットに含まれないキャッシュファイルは自動的に削除されます。--keep_cacheを指定すると、キャッシュファイルを残すことができます。

Training / 学習

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

accelerate launch --num_cpu_threads_per_process 1 --mixed_precision bf16 src/musubi_tuner/hv_train_network.py 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt 
    --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 --network_dim 32 
    --timestep_sampling shift --discrete_flow_shift 7.0 
    --max_train_epochs 16 --save_every_n_epochs 1 --seed 42
    --output_dir path/to/output_dir --output_name name-of-lora

or for uv:

uv run --extra cu124 accelerate launch --num_cpu_threads_per_process 1 --mixed_precision bf16 src/musubi_tuner/hv_train_network.py 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt 
    --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 --network_dim 32 
    --timestep_sampling shift --discrete_flow_shift 7.0 
    --max_train_epochs 16 --save_every_n_epochs 1 --seed 42
    --output_dir path/to/output_dir --output_name name-of-lora

If the details of the image are not learned well, try lowering the discrete flow shift to around 3.0.

The training settings are still experimental. Appropriate learning rates, training steps, timestep distribution, loss weighting, etc. are not yet known. Feedback is welcome.

For additional options, use python src/musubi_tuner/hv_train_network.py --help (note that many options are unverified).

Memory Optimization

--gradient_checkpointing enables gradient checkpointing to reduce VRAM usage. Gradient checkpointing is a memory-saving technique that trades off computation time for memory usage by recomputing certain intermediate results during the backward pass instead of storing them all in memory. This is particularly useful for training large models such as HunyuanVideo, where VRAM can be a limiting factor. However, it may slow down training. If you have sufficient VRAM, you can disable it.

Specifying --fp8_base runs DiT in fp8 mode. Without this flag, mixed precision data type will be used. fp8 can significantly reduce memory consumption but may impact output quality. If --fp8_base is not specified, 24GB or more VRAM is recommended. Use --blocks_to_swap as needed.

If you're running low on VRAM, use --blocks_to_swap to offload some blocks to CPU. Maximum value is 36.

(The idea of block swap is based on the implementation by 2kpr. Thanks again to 2kpr.)

--use_pinned_memory_for_block_swap can be used to enable pinned memory for block swapping. This may improve performance when swapping blocks between CPU and GPU. However, it may increase shared VRAM usage on Windows systems. Use this option based on your system configuration (e.g., available system RAM and VRAM). In some environments, not specifying this option may result in faster performance.

--gradient_checkpointing_cpu_offload can be used to offload activations to CPU when using gradient checkpointing. This can further reduce VRAM usage, but may slow down training. This option is especially useful when the latent resolution (or video length) is high and VRAM is limited. This option must be used together with --gradient_checkpointing. See PR #537 for more details.

Attention

Use --sdpa for PyTorch's scaled dot product attention. Use --flash_attn for FlashAttention. Use --xformers for xformers, but specify --split_attn when using xformers. --sage_attn for SageAttention, but SageAttention is not yet supported for training, so it raises a ValueError.

--split_attn processes attention in chunks. Speed may be slightly reduced, but VRAM usage is slightly reduced.

Timestep Sampling

You can also specify the range of timesteps with --min_timestep and --max_timestep. See advanced configuration for details.

--show_timesteps can be set to image (requires matplotlib) or console to display timestep distribution and loss weighting during training. (When using flux_shift and qwen_shift, the distribution will be for images with a resolution of 1024x1024.)

Other Options

The format of LoRA trained is the same as sd-scripts.

You can record logs during training. Refer to Save and view logs in TensorBoard format.

For PyTorch Dynamo optimization, refer to this document.

For sample image generation during training, refer to this document. For advanced configuration, refer to this document.

日本語

以下のコマンドを使用して、学習を開始します(実際には一行で入力してください)。

accelerate launch --num_cpu_threads_per_process 1 --mixed_precision bf16 src/musubi_tuner/hv_train_network.py 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt 
    --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 --network_dim 32 
    --timestep_sampling shift --discrete_flow_shift 7.0 
    --max_train_epochs 16 --save_every_n_epochs 1 --seed 42
    --output_dir path/to/output_dir --output_name name-of-lora

ディテールが甘くなる場合は、discrete flow shiftを3.0程度に下げてみてください。

ただ、適切な学習率、学習ステップ数、timestepsの分布、loss weightingなどのパラメータは、以前として不明な点が数多くあります。情報提供をお待ちしています。

その他のオプションはpython src/musubi_tuner/hv_train_network.py --helpで確認できます(ただし多くのオプションは動作未確認です)。

メモリ最適化

--gradient_checkpointingでgradient checkpointingを有効にします。VRAM使用量を削減できます。gradient checkpointingは、バックワードパス中に一部の中間結果をすべてメモリに保存するのではなく、再計算することで、計算時間とメモリ使用量をトレードオフするメモリ節約技術です。HunyuanVideoのような大規模モデルの学習ではVRAMが制約となることが多いため、特に有用です。ただし学習が遅くなる可能性があります。十分なVRAMがある場合は無効にしても構いません。

--fp8_baseを指定すると、DiTがfp8で学習されます。未指定時はmixed precisionのデータ型が使用されます。fp8は大きく消費メモリを削減できますが、品質は低下する可能性があります。--fp8_baseを指定しない場合はVRAM 24GB以上を推奨します。また必要に応じて--blocks_to_swapを使用してください。

VRAMが足りない場合は、--blocks_to_swapを指定して、一部のブロックをCPUにオフロードしてください。最大36が指定できます。

(block swapのアイデアは2kpr氏の実装に基づくものです。2kpr氏にあらためて感謝します。)

--use_pinned_memory_for_block_swapを指定すると、block swapにピン留めメモリを使用します。CPUとGPU間でブロックをスワップする際のパフォーマンスが向上する可能性があります。ただし、Windows環境では共有VRAM使用量が増加する可能性があります。システム構成(利用可能なシステムRAMやVRAMなど)に応じて、このオプションを使用してください。環境によっては指定しないほうが高速になる場合もあります。

--gradient_checkpointing_cpu_offloadを指定すると、gradient checkpointing使用時にアクティベーションをCPUにオフロードします。これによりVRAM使用量をさらに削減できますが、学習が遅くなる可能性があります。latent解像度(または動画長)が高く、VRAMが限られている場合に特に有用です。このオプションは--gradient_checkpointingと併用する必要があります。詳細はPR #537を参照してください。

Attention

--sdpaでPyTorchのscaled dot product attentionを使用します。--flash_attnで[FlashAttention]:(https://github.com/Dao-AILab/flash-attention)を使用します。`--xformers`でxformersの利用も可能ですが、xformersを使う場合は`--split_attn`を指定してください。`--sage_attn`でSageAttentionを使用しますが、SageAttentionは現時点では学習に未対応のため、エラーが発生します。

--split_attnを指定すると、attentionを分割して処理します。速度が多少低下しますが、VRAM使用量はわずかに減ります。

タイムステップサンプリング

--min_timestep--max_timestepを指定すると、学習時のタイムステップの範囲を指定できます。詳細は高度な設定を参照してください。

--show_timestepsimagematplotlibが必要)またはconsoleを指定すると、学習時のtimestepsの分布とtimestepsごとのloss weightingが確認できます。(flux_shiftqwen_shiftを使用する場合は画像の解像度が1024x1024の場合の分布になります。)

その他のオプション

学習されるLoRAの形式は、sd-scriptsと同じです。

学習時のログの記録が可能です。TensorBoard形式のログの保存と参照を参照してください。

PyTorch Dynamoによる最適化を行う場合は、こちらを参照してください。

学習中のサンプル画像生成については、こちらのドキュメントを参照してください。その他の高度な設定についてはこちらのドキュメントを参照してください。

Merging LoRA Weights / LoRAの重みのマージ

python src/musubi_tuner/merge_lora.py \
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt \
    --lora_weight path/to/lora.safetensors \
    --save_merged_model path/to/merged_model.safetensors \
    --device cpu \
    --lora_multiplier 1.0

or for uv:

uv run --extra cu124 src/musubi_tuner/merge_lora.py \
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt \
    --lora_weight path/to/lora.safetensors \
    --save_merged_model path/to/merged_model.safetensors \
    --device cpu \
    --lora_multiplier 1.0

Specify the device to perform the calculation (cpu or cuda, etc.) with --device. Calculation will be faster if cuda is specified.

Specify the LoRA weights to merge with --lora_weight and the multiplier for the LoRA weights with --lora_multiplier. Multiple values can be specified, and the number of values must match.

日本語
python src/musubi_tuner/merge_lora.py \
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt \
    --lora_weight path/to/lora.safetensors \
    --save_merged_model path/to/merged_model.safetensors \
    --device cpu \
    --lora_multiplier 1.0

--deviceには計算を行うデバイス(cpuまたはcuda等)を指定してください。cudaを指定すると計算が高速化されます。

--lora_weightにはマージするLoRAの重みを、--lora_multiplierにはLoRAの重みの係数を、それぞれ指定してください。複数個が指定可能で、両者の数は一致させてください。

Inference / 推論

Generate videos using the following command:

python src/musubi_tuner/hv_generate_video.py --fp8 --video_size 544 960 --video_length 5 --infer_steps 30 
    --prompt "A cat walks on the grass, realistic style."  --save_path path/to/save/dir --output_type both 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt --attn_mode sdpa --split_attn
    --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt 
    --vae_chunk_size 32 --vae_spatial_tile_sample_min_size 128 
    --text_encoder1 path/to/ckpts/text_encoder 
    --text_encoder2 path/to/ckpts/text_encoder_2 
    --seed 1234 --lora_multiplier 1.0 --lora_weight path/to/lora.safetensors

or for uv:

uv run --extra cu124 src/musubi_tuner/hv_generate_video.py --fp8 --video_size 544 960 --video_length 5 --infer_steps 30 
    --prompt "A cat walks on the grass, realistic style."  --save_path path/to/save/dir --output_type both 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt --attn_mode sdpa --split_attn
    --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt 
    --vae_chunk_size 32 --vae_spatial_tile_sample_min_size 128 
    --text_encoder1 path/to/ckpts/text_encoder 
    --text_encoder2 path/to/ckpts/text_encoder_2 
    --seed 1234 --lora_multiplier 1.0 --lora_weight path/to/lora.safetensors

For additional options, use python src/musubi_tuner/hv_generate_video.py --help.

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

--fp8_fast option is also available for faster inference on RTX 40x0 GPUs. This option requires --fp8 option.

If you're running low on VRAM, use --blocks_to_swap to offload some blocks to CPU. Maximum value is 38.

For --attn_mode, specify either flash, torch, sageattn, xformers, or sdpa (same as torch). These correspond to FlashAttention, scaled dot product attention, SageAttention, and xformers, respectively. Default is torch. SageAttention is effective for VRAM reduction.

Specifing --split_attn will process attention in chunks. Inference with SageAttention is expected to be about 10% faster.

For --output_type, specify either both, latent, video or images. both outputs both latents and video. Recommended to use both in case of Out of Memory errors during VAE processing. You can specify saved latents with --latent_path and use --output_type video (or images) to only perform VAE decoding.

--seed is optional. A random seed will be used if not specified.

--video_length should be specified as "a multiple of 4 plus 1".

--flow_shift can be specified to shift the timestep (discrete flow shift). The default value when omitted is 7.0, which is the recommended value for 50 inference steps. In the HunyuanVideo paper, 7.0 is recommended for 50 steps, and 17.0 is recommended for less than 20 steps (e.g. 10).

By specifying --video_path, video2video inference is possible. Specify a video file or a directory containing multiple image files (the image files are sorted by file name and used as frames). An error will occur if the video is shorter than --video_length. You can specify the strength with --strength. It can be specified from 0 to 1.0, and the larger the value, the greater the change from the original video.

Note that video2video inference is experimental.

--compile option enables PyTorch's compile feature (experimental). Requires triton. On Windows, also requires Visual C++ build tools installed and PyTorch>=2.6.0 (Visual C++ build tools is also required). See the torch.compile documentation for details.

The --compile option takes a long time to run the first time, but speeds up on subsequent runs.

You can save the DiT model after LoRA merge with the --save_merged_model option. Specify --save_merged_model path/to/merged_model.safetensors. Note that inference will not be performed when this option is specified.

日本語

以下のコマンドを使用して動画を生成します。

python src/musubi_tuner/hv_generate_video.py --fp8 --video_size 544 960 --video_length 5 --infer_steps 30 
    --prompt "A cat walks on the grass, realistic style."  --save_path path/to/save/dir --output_type both 
    --dit path/to/ckpts/hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states.pt --attn_mode sdpa --split_attn
    --vae path/to/ckpts/hunyuan-video-t2v-720p/vae/pytorch_model.pt 
    --vae_chunk_size 32 --vae_spatial_tile_sample_min_size 128 
    --text_encoder1 path/to/ckpts/text_encoder 
    --text_encoder2 path/to/ckpts/text_encoder_2 
    --seed 1234 --lora_multiplier 1.0 --lora_weight path/to/lora.safetensors

その他のオプションはpython src/musubi_tuner/hv_generate_video.py --helpで確認できます。

--fp8を指定すると、DiTがfp8で推論されます。fp8は大きく消費メモリを削減できますが、品質は低下する可能性があります。

RTX 40x0シリーズのGPUを使用している場合は、--fp8_fastオプションを指定することで、高速推論が可能です。このオプションを指定する場合は、--fp8も指定してください。

VRAMが足りない場合は、--blocks_to_swapを指定して、一部のブロックをCPUにオフロードしてください。最大38が指定できます。

--attn_modeにはflashtorchsageattnxformersまたはsdpatorch指定時と同じ)のいずれかを指定してください。それぞれFlashAttention、scaled dot product attention、SageAttention、xformersに対応します。デフォルトはtorchです。SageAttentionはVRAMの削減に有効です。

--split_attnを指定すると、attentionを分割して処理します。SageAttention利用時で10%程度の高速化が見込まれます。

--output_typeにはbothlatentvideoimagesのいずれかを指定してください。bothはlatentと動画の両方を出力します。VAEでOut of Memoryエラーが発生する場合に備えて、bothを指定することをお勧めします。--latent_pathに保存されたlatentを指定し、--output_type video (またはimages)としてスクリプトを実行すると、VAEのdecodeのみを行えます。

--seedは省略可能です。指定しない場合はランダムなシードが使用されます。

--video_lengthは「4の倍数+1」を指定してください。

--flow_shiftにタイムステップのシフト値(discrete flow shift)を指定可能です。省略時のデフォルト値は7.0で、これは推論ステップ数が50の時の推奨値です。HunyuanVideoの論文では、ステップ数50の場合は7.0、ステップ数20未満(10など)で17.0が推奨されています。

--video_pathに読み込む動画を指定すると、video2videoの推論が可能です。動画ファイルを指定するか、複数の画像ファイルが入ったディレクトリを指定してください(画像ファイルはファイル名でソートされ、各フレームとして用いられます)。--video_lengthよりも短い動画を指定するとエラーになります。--strengthで強度を指定できます。0~1.0で指定でき、大きいほど元の動画からの変化が大きくなります。

なおvideo2video推論の処理は実験的なものです。

--compileオプションでPyTorchのコンパイル機能を有効にします(実験的機能)。tritonのインストールが必要です。また、WindowsではVisual C++ build toolsが必要で、かつPyTorch>=2.6.0でのみ動作します。詳細はtorch.compileのドキュメントを参照してください。

--compileは初回実行時にかなりの時間がかかりますが、2回目以降は高速化されます。

--save_merged_modelオプションで、LoRAマージ後のDiTモデルを保存できます。--save_merged_model path/to/merged_model.safetensorsのように指定してください。なおこのオプションを指定すると推論は行われません。

Inference with SkyReels V1 / SkyReels V1での推論

SkyReels V1 T2V and I2V models are supported (inference only).

The model can be downloaded from here. Many thanks to Kijai for providing the model. skyreels_hunyuan_i2v_bf16.safetensors is the I2V model, and skyreels_hunyuan_t2v_bf16.safetensors is the T2V model. The models other than bf16 are not tested (fp8_e4m3fn may work).

For T2V inference, add the following options to the inference command:

--guidance_scale 6.0 --embedded_cfg_scale 1.0 --negative_prompt "Aerial view, aerial view, overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion" --split_uncond

SkyReels V1 seems to require a classfier free guidance (negative prompt).--guidance_scale is a guidance scale for the negative prompt. The recommended value is 6.0 from the official repository. The default is 1.0, it means no classifier free guidance.

--embedded_cfg_scale is a scale of the embedded guidance. The recommended value is 1.0 from the official repository (it may mean no embedded guidance).

--negative_prompt is a negative prompt for the classifier free guidance. The above sample is from the official repository. If you don't specify this, and specify --guidance_scale other than 1.0, an empty string will be used as the negative prompt.

--split_uncond is a flag to split the model call into unconditional and conditional parts. This reduces VRAM usage but may slow down inference. If --split_attn is specified, --split_uncond is automatically set.

You can also perform image2video inference with SkyReels V1 I2V model. Specify the image file path with --image_path. The image will be resized to the given --video_size.

--image_path path/to/image.jpg
日本語

SkyReels V1のT2VとI2Vモデルがサポートされています(推論のみ)。

モデルはこちらからダウンロードできます。モデルを提供してくださったKijai氏に感謝します。skyreels_hunyuan_i2v_bf16.safetensorsがI2Vモデル、skyreels_hunyuan_t2v_bf16.safetensorsがT2Vモデルです。bf16以外の形式は未検証です(fp8_e4m3fnは動作するかもしれません)。

T2V推論を行う場合、以下のオプションを推論コマンドに追加してください:

--guidance_scale 6.0 --embedded_cfg_scale 1.0 --negative_prompt "Aerial view, aerial view, overexposed, low quality, deformation, a poor composition, bad hands, bad teeth, bad eyes, bad limbs, distortion" --split_uncond

SkyReels V1はclassifier free guidance(ネガティブプロンプト)を必要とするようです。--guidance_scaleはネガティブプロンプトのガイダンススケールです。公式リポジトリの推奨値は6.0です。デフォルトは1.0で、この場合はclassifier free guidanceは使用されません(ネガティブプロンプトは無視されます)。

--embedded_cfg_scaleは埋め込みガイダンスのスケールです。公式リポジトリの推奨値は1.0です(埋め込みガイダンスなしを意味すると思われます)。

--negative_promptはいわゆるネガティブプロンプトです。上記のサンプルは公式リポジトリのものです。--guidance_scaleを指定し、--negative_promptを指定しなかった場合は、空文字列が使用されます。

--split_uncondを指定すると、モデル呼び出しをuncondとcond(ネガティブプロンプトとプロンプト)に分割します。VRAM使用量が減りますが、推論速度は低下する可能性があります。--split_attnが指定されている場合、--split_uncondは自動的に有効になります。

Convert LoRA to another format / LoRAの形式の変換

You can convert LoRA to a format (presumed to be Diffusion-pipe) compatible with another inference environment (Diffusers, ComfyUI etc.) using the following command:

python src/musubi_tuner/convert_lora.py --input path/to/musubi_lora.safetensors --output path/to/another_format.safetensors --target other

or for uv:

uv run --extra cu124 src/musubi_tuner/convert_lora.py --input path/to/musubi_lora.safetensors --output path/to/another_format.safetensors --target other

Specify the input and output file paths with --input and --output, respectively.

Specify other for --target. Use default to convert from another format to the format of this repository.

日本語

他の推論環境(DiffusersやComfyUI)で使用可能な形式(Diffusion-pipe または Diffusers と思われる)への変換は以下のコマンドで行えます。

python src/musubi_tuner/convert_lora.py --input path/to/musubi_lora.safetensors --output path/to/another_format.safetensors --target other

--input--outputはそれぞれ入力と出力のファイルパスを指定してください。

--targetにはotherを指定してください。defaultを指定すると、他の形式から当リポジトリの形式に変換できます。