ホーム 暮らし Accelerating MiniMax H3: A Guide to Implementing LightX2V Ref2VA and SageAttention 2.2.0

Accelerating MiniMax H3: A Guide to Implementing LightX2V Ref2VA and SageAttention 2.2.0

雨宮 千夏 雨宮 千夏 • 更新: • 公開: • 読了約 28 分
目次

Accelerating MiniMax H3

n58f921a50788

While MiniMax H3 can generate high-quality videos, the generation process requires a significant amount of computation.

In this article, we will introduce the following two methods to accelerate the use of MiniMax H3 in ComfyUI.

  • Accelerating Ref2VA with LightX2V Turbo LoRA

  • Accelerating Attention processing with SageAttention 2.2.0

Finally, we will measure the actual generation time before and after implementation to confirm how much it can be accelerated.

Environment used this time

The verification environment for this time is as follows.

What is Ref2VA for MiniMax H3?

In addition to Text-to-Video and Image-to-Video, MiniMax H3 has a generation method called Reference-to-Video (Ref2VA / R2V).

With Ref2VA, you can generate videos while maintaining characters, art styles, and movements by using references such as images or videos as input. In ComfyUI, you use the MiniMaxH3ReferenceToVideo node.

Unlike the FL2VA series models used for standard T2V/I2V, Ref2VA uses Ref2VA series models. Representative models are as follows.

minimax_h3_ref2va_pruned_int8_convrot.safetensors

Please note that this model has different weights from the standard minimax_h3_fl2va_....

Acceleration Part 1: LightX2V Turbo LoRA

What is LightX2V?

LightX2V is a method that reduces generation time by decreasing the number of inference steps in video generation models.

Standard MiniMax H3 requires multi-step sampling, but by using Turbo LoRA, you can generate videos with fewer steps. The goal here is to reduce the number of generation steps without significantly degrading quality.

Turbo LoRA for Ref2VA

For MiniMax H3's Ref2VA, you use a different model and LoRA configuration than the standard FL2VA model. In this guide, we will use the LightX2V Ref2VA Turbo LoRA.

Download the following safetensors file and place it in your ComfyUI LoRA folder.

minimax_h3_ref2v_turbo_4step_v0.1_comfyui_bf16.safetensors

Location:

C:\Software\ComfyUI\models\loras\MiniMaxH3\

If the MiniMaxH3 folder does not exist, please create it using File Explorer.

Applying LoRA in ComfyUI

Open the MiniMax H3 Reference to Video workflow from the templates.

Basically, connect the generation model and text encoder to the LoRA loader, and connect the model output to the basic guider and basic scheduler. Connect the CLIP to the MiniMax H3 Reference to Video node.


Here, we will use the LoRA Power Loader included in the custom node pack called rgthree. If you haven't installed it yet, please install rgthree via ComfyUI Manager.

It is important to use the corresponding Ref2VA LoRA for the standard MiniMax H3 Ref2VA model. Be careful not to confuse the FL2VA LoRA with the Ref2VA LoRA.

Turbo Settings

The LightX2V Turbo LoRA aims to generate images with fewer steps than usual. For this verification, we will start by setting the steps to 4.

There is a trade-off in image quality with Turbo LoRA. This acceleration works by reducing the number of denoising steps to lower the computational load. If you cannot achieve sufficient quality with 4 steps, do not feel restricted to 4; try changing it to 8 steps or more. While generation speed will decrease, you may be able to improve image quality while still maintaining some level of acceleration.

To change the number of steps, modify the steps value in the basic scheduler. First, set it to 4, which is the recommended value for the LoRA.

Once the settings are complete, enter your reference and prompt to generate. The generation time will be displayed in the console that appears when ComfyUI starts, so compare the time before and after enabling the Turbo LoRA. If the time has been reduced, you have succeeded.

Implementing SageAttention 2.2.0

SageAttention is a CUDA kernel that accelerates the Attention processing used in image and video generation. Attention is the part of the generation model that performs a massive amount of computation.

SageAttention does not accelerate the entire model, but rather replaces the internal Attention parts of the model with a faster implementation.

There are two ways to implement it. One is to install a whl binary built by a contributor. However, because SageAttention operates at a low level, it is highly dependent on the versions of Python and PyTorch. Finding a compatible build is not easy.

Another option is to build the whl yourself. With this method, even if you update Python or PyTorch in your venv in the future, you may be able to handle it by rebuilding it yourself. However, please note that this will not work if the Python or PyTorch APIs or function signatures are changed.

For this guide, the build was verified in an environment with Visual Studio Build Tools 2022, Python 3.13.15, CUDA Toolkit 13.0.3, and PyTorch 2.13.0+cu130. SageAttention 2.2.0 cannot be built as-is. This is because PyTorch requires the C++20 standard, while SageAttention 2.2.0 attempts to build using the C++17 standard. Be sure to apply the patch described below before building.

Installing Visual Studio Build Tools 2022

Be sure to install Build Tools 2022. Installing the desktop version or the 2026 version may result in build failures due to C++ compiler compatibility issues.

Visual Studio Build Tools 2022 does not currently have a standard installer distributed on the web. Here, we will use winget to install it from the command line.

Press the Windows + R keys and run cmd. Paste the following and press Enter. The installer will launch and the toolchain will be installed. If the installer asks for confirmation, please proceed with the default settings.

winget install --id Microsoft.VisualStudio.2022.BuildTools --accept-source-agreements --accept-package-agreements --override "--passive --wait --norestart --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset --add Microsoft.VisualStudio.Component.VC.CMake.Project --add Microsoft.VisualStudio.Component.Windows11SDK.26100"
Installing CUDA Toolkit 13.0.3

Download the installer from the NVIDIA website and perform an express installation. Always install the CUDA Toolkit after the Visual Studio Build Tools 2022 installation is complete. If you get the order wrong, the settings required for the build will not be installed on the Visual Studio Build Tools side.

CUDA Toolkit 13.0.3 Installer

Building SageAttention 2.2.0

In this environment, you need to apply a patch to SageAttention's setup.py. This patch rewrites the compiler options to build using the C++20 standard.

Patch file

When building, be sure to run Developer Command Prompt for VS 2022 instead of a regular terminal. Launch it from the Start menu. If you run it from a regular cmd, the paths to the toolchain and environment variables will not be set, and the build will fail.

cd /d C:\Software\ComfyUI
.\venv\scripts\activate
pip install setuptools wheel ninja packaging
pip install triton-windows
mkdir extra
cd extra
git clone https://github.com/thu-ml/SageAttention.git
cd SageAttention
git apply C:\User\<user>\Downloads\sageattention-cuda13-cpp20.diff
set DISTUTILS_USE_SDK=1
python setup.py bdist_wheel

※Please replace <user> with your username. If you are unsure, you can also copy sageattention-cuda13-cpp20.diff to C:\ and run git apply c:\sageattention-cuda13-cpp20.diff, which should also work.

Installing SageAttention 2.2.0

In the terminal used for the build, continue by entering the following to complete the SageAttention installation.

pip install dist\sageattention-2.2.0-cp313-cp313-win_amd64.whl
Using SageAttention

One way to enable SageAttention is to add --use-sage-attention when launching ComfyUI. Alternatively, using a custom node called Patch Sage Attention KJ allows you to toggle SageAttention on or off for each ComfyUI workflow. We will use this custom node.

PatchSageAttentionKJ is provided by ComfyUI-KJNodes. Click the extension manager button, type KJNodes in the search bar to display ComfyUI-KJNodes. If it is not installed, click the Install button, and after installation is complete, restart ComfyUI as instructed.

Once ComfyUI has restarted, enable SageAttention on the workflow where LightX2V is applied. Open the node library and type Patch KJ in the search box. Place the displayed Patch Sage Attention KJ node near the bottom of the Power LoRA Loader.

Connect only the diffusion model to the Patch Sage Attention KJ. Also, make sure to connect it after the LoRA. Connect the model output of the Power LoRA Loader to the model input of the Patch Sage Attention KJ, and connect the model output of the Patch Sage Attention KJ to the model inputs of the basic guider and basic scheduler.

Patch Sage Attention KJ should be disabled by default. While auto will set the optimal attention, I have selected sageattn_qk_int8_pv_fp8_cuda++ here. If it works, it is a good idea to compare its speed with other methods.

Once the connections are complete, press the Generate button and confirm that you can generate a video. Since model loading and other processes occur during generation immediately after starting ComfyUI, try it twice to verify if it has been accelerated. In an RTX 5060 environment, the speed seems to improve by about 20% compared to when using LightX2V alone.

Performance Measurement Results

I measured the performance of standard MiniMax H3, LightX2V, SageAttention 2.2.0, and a combination of both.

With LightX2V, the generation time was reduced to about one-third. When used simultaneously with SageAttention, it was reduced to about one-fourth.

Other Acceleration Methods

comfy-kitchen

This is an acceleration technique that patches relatively new attention implementations. It seems fast on RTX 3000 and RTX 4000 series, but there are reports that SageAttention is faster on the RTX 5000 series. Also, it requires building from pip to use.

MiniMax H3 Block Cache (T8)

This can affect the output. I stopped using it because the cache hit count can sometimes drop to 0. Additionally, there are reports that it does not work properly when used simultaneously with other cache-related nodes.

Sol-Attn

I am not using this because there are too many competing implementations, but it seems to be popular.

SageAttention 3

This is included in the repository for SageAttention 2.2.0, which I used this time. The build was successful in an RTX 5090 environment, but ComfyUI crashed. Since it has not been updated for 8 months, if comfy-kitchen or Sol-Attn are improved in the future, a migration to those might progress.

Conclusion

SageAttention is a technology from when SDXL was mainstream, but it still provides acceleration benefits today. LightX2V is a distilled model, an approach that extracts the target latent representation with fewer denoising steps.

The technical concept itself is not new in local AI, but I wrote this article because it allows for stable performance gains.

Next time, I plan to introduce a method for bullet-pointing MiniMax H3 prompts in Japanese and having an LLM compile them. I have already finished verifying that it works in an environment with 8 GB of VRAM and 16 GB of memory.

同じカテゴリの記事

雨宮 千夏
デジタルマーケター 雨宮 千夏
プロフィールを見る →

アイドルと音楽シーンの取材を担当。公式サイトの公演情報、リリース告知、公開チャートを照合してから構成しています。

おすすめの関連記事