
【MiniMax H3】ComfyUIにSageAttentionを入れてVRAM 12GBグラボで30%高速化してみた
こんにちは、かみもとです!
MiniMax H3がリリースされてまだ数日ですが、色々と面白いワークフローや高速化技術がコミュニティの力で整えられています。性能が良い動画生成モデルのせいか、ものすごい速さで技術開発されている印象です。
RTX4070 VRAM 12GBの私としては、まずはできるだけ高速化したい!LoRAも作ったので、次は高速化に取り組んでみたいと思います。
高速化といってもいろいろな種類がありますが、今回は「SageAttention」という技術を導入してみました。ただ、既存のComfyUI環境にインストールしようとしたらエラーになってしまったので、今回思い切ってComfyUIを新規でインストールしなおしています。
なので、今回の記事では、ComfyUIポータブル版@Windowsのインストールも含めて最初から説明しています。今からComfyUIをインストールする方にも参考になると思います!
SageAttention導入手順
以下は単調な導入説明が続きますので、結果だけ見たい場合は目次から「MiniMax H3でSage Attentionを試す」へ。詳細な手順を手動で試したい場合は以下を読んでみてください。あるいはこの記事をClaude CodeやCodexに読み込ませれば環境構築やってくれると思います。
1.ComfyUIのポータブル版をダウンロードする
C:\comfyui\sage_clean_setupというフォルダを作成し、ComfyUIをダウンロードします。ポータブル版ですね。
curl.exe -L "https://github.com/Comfy-Org/ComfyUI/releases/latest/download/ComfyUI_windows_portable_nvidia.7z" -o ".\ComfyUI_windows_portable_nvidia.7z"ダウンロード終わったら解凍します。
tar.exe -xf ".\ComfyUI_windows_portable_nvidia.7z"うまく解凍できたら、ComfyUIのPython, PyTorchを調べます。
cd "C:\comfyui\sage_clean_setup\ComfyUI_windows_portable"
.\python_embeded\python.exe -c "import sys, torch; print('Python:', sys.version); print('Torch:', torch.__version__); print('CUDA runtime:', torch.version.cuda); print('CUDA available:', torch.cuda.is_available()); print('GPU:', torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'None'); print('Capability:', torch.cuda.get_device_capability(0) if torch.cuda.is_available() else 'None')"私の環境では以下になりました。この辺のバージョンが異なっているとSageAttentionがうまくインストールできないこともあるので注意。都度、AIにチャットしながら確認していきましょう。
Python: 3.13.14 (tags/v3.13.14:fd17997, Jun 10 2026, 13:03:48) [MSC v.1944 64 bit (AMD64)]
Torch: 2.13.0+cu130
CUDA runtime: 13.0
CUDA available: True
GPU: NVIDIA GeForce RTX 4070
Capability: (8, 9)
2.embedded Pythonのinclude/libsの有無を確認
SageAttentionを使うためにinclude/libsが必要になりますので、存在するか確認します。
Test-Path ".\python_embeded\include\Python.h"
Test-Path ".\python_embeded\libs\python313.lib"私の環境ではどちらも「False」になりました。存在しない、ということなので、Python 3.13用のinclude/libsをダウンロードします。
curl.exe -L "https://github.com/woct0rdho/triton-windows/releases/download/v3.0.0-windows.post1/python_3.13.2_include_libs.zip" -o ".\python_3.13.2_include_libs.zip"ダウンロード後、解凍します。
tar.exe -xf ".\python_3.13.2_include_libs.zip" -C ".\python_embeded"成功したら、再度存在チェックを行います。
Test-Path ".\python_embeded\include\Python.h"
Test-Path ".\python_embeded\libs\python313.lib"今度はどちらも「True」になっていると思います。それで成功。
3.triton-windows 3.7.1.post27 を導入
続いて、tritonをインストールします。C:\comfyui\sage_clean_setup\ComfyUI_windows_portableフォルダのまま、以下を実行します。
.\python_embeded\python.exe -m pip install --no-deps triton-windows==3.7.1.post27うまくインストールできたかを以下のコマンドで調べます。
.\python_embeded\python.exe -c "import triton; import triton.experimental; print('triton:', triton.__version__); print('experimental: OK')"成功すると
triton: 3.7.1
experimental: OK
のようになります。
4.SageAttentionのWindows wheelをダウンロード
いよいよ、SageAttentionをインストールしていきます。まずは本体のダウンロードから。
curl.exe -L "https://github.com/woct0rdho/SageAttention/releases/download/v2.2.0-windows.post6/sageattention-2.2.0%2Bcu130torch2.10.0andhigher.post6-cp310-abi3-win_amd64.whl" -o ".\sageattention-2.2.0+cu130torch2.10.0andhigher.post6-cp310-abi3-win_amd64.whl"ダウンロード終わったら、インストールします。すぐ終わるはず。
.\python_embeded\python.exe -m pip install --no-deps ".\sageattention-2.2.0+cu130torch2.10.0andhigher.post6-cp310-abi3-win_amd64.whl"正しくインストールできているか、以下コマンドでチェックします。
.\python_embeded\python.exe -c "import sageattention; print('sageattention import: OK'); print('sageattention path:', sageattention.__file__)"うまくいけば、
sageattention import: OK
sageattention path: C:\comfyui\sage_clean_setup\ComfyUI_windows_portable\python_embeded\Lib\site-packages\sageattention_init_.py
と表示されると思います。
5.SageAttentionの実カーネルを最小テスト
簡単なSageAttentionの動作確認します。
.\python_embeded\python.exe -c "import torch; from sageattention import sageattn; q=torch.randn(1,1024,56,128,device='cuda',dtype=torch.bfloat16); k=torch.randn_like(q); v=torch.randn_like(q); y=sageattn(q,k,v,tensor_layout='NHD'); torch.cuda.synchronize(); print('OK', y.shape, y.dtype, torch.isfinite(y).all().item())"うまくいくと、
OK torch.Size([1, 1024, 56, 128]) torch.bfloat16 True
という表示が出ます。
6.ComfyUIをSageAttention有効で起動
ようやくComfyUIでSageAttentionを動かします。まだ、MiniMax H3ではありません。長いですねー。
.\python_embeded\python.exe -s .\ComfyUI\main.py --windows-standalone-build --use-sage-attentionこのコマンドで、SageAttention付きの引数でComfyUIを起動します。成功すれば、ComfyUIのWebUI画面が表示されます。コンソールのログの最後に、
[INFO] Using sage attention
[INFO] Starting server
[INFO] To see the GUI go to: http://127.0.0.1:8188
みたいに表示されると思います。一旦ここでコンソールでCtrl-Cを押してComfyUIを閉じます。
7.既存モデルを新環境から参照する設定を作成
私はすでに別フォルダでComfyUIを動かしていて、そこにMiniMax H3などのモデルファイルが置いてあります。複製して持ってくるとSSD容量が不足してしまうので、既存モデルを新ComfyUI環境から参照できるようにします。
Copy-Item ".\ComfyUI\extra_model_paths.yaml.example" ".\ComfyUI\extra_model_paths.yaml"成功してもコンソールには表示がないので、そのまま次へ。
@"
comfyui:
base_path: C:/comfyui/ComfyUI_windows_portable/ComfyUI/
checkpoints: models/checkpoints/
configs: models/configs/
loras: models/loras/
vae: models/vae/
text_encoders: |
models/text_encoders/
models/clip/
diffusion_models: |
models/unet/
models/diffusion_models/
clip_vision: models/clip_vision/
style_models: models/style_models/
embeddings: models/embeddings/
diffusers: models/diffusers/
vae_approx: models/vae_approx/
controlnet: |
models/controlnet/
models/t2i_adapter/
gligen: models/gligen/
upscale_models: models/upscale_models/
latent_upscale_models: models/latent_upscale_models/
hypernetworks: models/hypernetworks/
photomaker: models/photomaker/
classifiers: models/classifiers/
model_patches: models/model_patches/
audio_encoders: models/audio_encoders/
background_removal: models/background_removal/
frame_interpolation: models/frame_interpolation/
geometry_estimation: models/geometry_estimation/
optical_flow: models/optical_flow/
detection: models/detection/
"@ | Set-Content ".\ComfyUI\extra_model_paths.yaml" -Encoding utf8yamlファイルに既存ComfyUIのパスを認識させます。この辺は各自のPC環境に依存しますので、AIに聞きながら進めましょう。Codex, Claudeなら正しく環境を認識してyamlを作ってくれると思います。
できたらComfyUIを実行します。yaml関連の書式エラーやモデルパスエラーがでなければOKです。
.\python_embeded\python.exe -s .\ComfyUI\main.py --windows-standalone-build --use-sage-attentionMiniMax H3でSage Attentionを試す
Sage Attentionがようやく導入できたので、いよいよMiniMax H3でSage Attentionを試します。
今回はAPIワークフローで試すので、以下のファイルを使います。私のオリジナルLoRAがワークフローに入っているので、各自で試す際は除外してください。
ComfyUIを起動したまま、以下のコマンドでワークフローを実行します。
$wf = "(ワークフローをおいたパス)\T2V_00361_5s_lora_v2_on_api_clean_sage.json"
$clientId = [guid]::NewGuid().ToString()
$prompt = Get-Content -Raw $wf | ConvertFrom-Json
$body = @{
client_id = $clientId
prompt = $prompt
}
Invoke-RestMethod -Uri "http://127.0.0.1:8188/prompt" -Method Post -ContentType "application/json" -Body ($body | ConvertTo-Json -Depth 50)うまく実行できれば成功!なのですが、私の環境(RTX4070 12GB)ではCUDA OOMとなりました。忘れてましたが、私の環境はマルチGPU(RTX4070, RTX3060)なので、GPUを明示しないといけませんでした。
以下コマンドで起動しなおします。
$env:CUDA_VISIBLE_DEVICES="0"; .\python_embeded\python.exe -s .\ComfyUI\main.py --windows-standalone-build --use-sage-attentionCUDA_VISIBLE_DEVICES="0"にするのがポイント。これでRTX4070に固定します。ComfyUIはマルチGPUの場合、いい感じに分散してモデルをロードさせようとするのですが、その辺の処理がうまくなく、OOMになってしまいます。
Device: cuda:0 NVIDIA GeForce RTX 4070
Using sage attention
DynamicVRAM support detected and enabled
こんな感じのログが出ればOK。
再度、ワークフローを実行します。
$wf = "(ワークフローをおいたパス)\T2V_00361_5s_lora_v2_on_api_clean_sage.json"
$prompt = Get-Content -Raw $wf | ConvertFrom-Json
$body = @{ client_id = [guid]::NewGuid().ToString(); prompt = $prompt }
Invoke-RestMethod -Uri "http://127.0.0.1:8188/prompt" -Method Post -ContentType "application/json" -Body ($body | ConvertTo-Json -Depth 50)うまくいくと、MiniMax H3で動画が生成されていきます。

先ほどのワークフローはt2vで、5秒動画を生成します。SageAttention未導入ではRTX4070で6分かかる処理です。気長に待ちます。
正常に生成されたらコンソールの最後に生成時間が出ています。私の環境だと最初の1回目の生成が「242秒=4分2秒」でした。これを元に、Sage Attentionなしでも生成します。
今度はSage Attentionなしで起動します。
$env:CUDA_VISIBLE_DEVICES="0"; .\python_embeded\python.exe -s .\ComfyUI\main.py --windows-standalone-buildDevice: cuda:0 NVIDIA GeForce RTX 4070
Using pytorch attention
だけ表示されることを確認して、同じワークフローを実行します。
$wf = "(ワークフローおいたパス)\T2V_00361_5s_lora_v2_on_api_clean_sage.json"
$prompt = Get-Content -Raw $wf | ConvertFrom-Json
$body = @{ client_id = [guid]::NewGuid().ToString(); prompt = $prompt }
Invoke-RestMethod -Uri "http://127.0.0.1:8188/prompt" -Method Post -ContentType "application/json" -Body ($body | ConvertTo-Json -Depth 50)これでOK!
MiniMax H3 SageAttention有無で比較
長かったですが、ようやくSageAttentionを導入できたので、生成結果を比較していきます。動画生成設定は以下。
解像度:544x832
フレームレート:24fps
秒数:5秒
プロンプトは以下。
High-quality Japanese anime style. A schoolgirl with short dark bob hair, wearing a dark blazer jacket, white collared shirt, gray necktie, dark pleated skirt, black pantyhose/tights, holding a school bag, walking on a paved path lined with trees under a blue sky. Create one continuous beautiful 5-second clip with no scene cut. The schoolgirl walks forward along the path with light, joyful steps while carrying her school bag. Halfway through, she turns and spins around gracefully, letting her skirt and hair flutter in the breeze. She then places both hands behind her back, leans forward towards the camera with a cute, mischievous teasing smile, and winks her right eye charmingly at the viewer. Natural anime movement, no morphing, no sudden cuts. Audio: cheerful upbeat instrumental music, soft footsteps, breeze rustling. No spoken dialogue, no speech, no vocals. No text, subtitles, logos, or watermarks.
(高品質な日本のアニメスタイル。黒髪のショートボブで、濃い色のブレザー、白い襟付きシャツ、グレーのネクタイ、濃い色のプリーツスカート、黒のタイツを身につけ、スクールバッグを持った女子生徒が、青空の下、木々が並ぶ舗装された道を歩いています。シーンの切り替えなしで、5秒間の美しい映像を1つの連続したクリップとして作成してください。女子生徒はスクールバッグを手に持ち、軽やかで楽しげな足取りで道を前進します。途中で優雅にくるりと振り返り、スカートと髪を風になびかせます。その後、両手を背中に回し、可愛らしく茶目っ気のある「からかうような」笑みを浮かべてカメラの方へ身を乗り出し、見る人に向かって愛らしく右目でウィンクします。自然なアニメの動きで、モーフィングや急なカット変更はありません。音声:明るく軽快なインストゥルメンタル音楽、柔らかな足音、風のそよぐ音。セリフや話し声、ボーカルはなし。テキスト、字幕、ロゴ、透かし(ウォーターマーク)もなし。)
今回のSage AttentionはカスタムノードではなくComfyUI全体にインストールしてあるので、ComfyUIの起動オプションで「--use-sage-attention」を指定して起動します。
.\python_embeded\python.exe -s .\ComfyUI\main.py --windows-standalone-build --use-sage-attentionそれでは実行結果です!

生成時間:
・Sage Attentionあり:242.09秒(約4分2秒)
・Sage Attentionなし:342.25秒(約5分42秒)
100秒も時短できました!29.3%の高速化です。劇的ですねー。
しかも生成結果の動画を見ても大差がないので、これは常用できますね!
まとめ
今回は、新規のComfyUI環境に、SageAttentionをインストールしてMiniMax H3の動画生成を高速化しました。
RTX4070 VRAM 12GBの環境でも、CUDA OOMせずに100秒も時短でき、5秒の動画を4分で生成できるようになりました!
SageAttentionにはカスタムノードのPatch Sage Attention KJ版というのもあるんですが、私の環境ではどうもうまく動かず、「triton.experimentalのインポートエラー」で止まってしまいました。新規ComfyUI環境では試していませんが、--use-sage-attentionで100秒時短できたのでヨシとします!
そうこうしているうちに、MiniMax H3用の高速化LoRAも出てきているので、次回はそれを試したいと思います!
最後まで読んでいただき、ありがとうございました!
もし今回の記事が「良かった」と感じていただけたら、スキを押していただけると、ComfyUIを新規にインストールしなおした甲斐があります!手動でやり直しているので、結構大変でした・・・。
今後もローカル画像生成、音声生成、LLM、たまに息抜きの画像生成など、実際に動かして分かったことをまとめていきますので、フォローもぜひよろしくお願いします!