Views
No views yet
pip install sageattention をしただけだと B200 では silently fallback して PyTorch SDPA で動きます。ここでは:core.py に sm_100 分岐 を注入、| min | mean | median | max | |
|---|---|---|---|---|
| SDPA baseline | 98.95s | 102.86s | 100.64s | 108.98s |
| SageAttention (this wheel) | 96.54s | 99.26s | 98.59s | 102.65s |
| Δ (mean) | +3.6 % | |||
| Per-iteration | 2.13 s/it | |||
| Per-iteration | 2.07 s/it |
1280×704 / 30 step では attention の比率はそこまで大きくないので速度差は ~3.6%。VRAM 余裕がある B200 なら "engage 確認 + 安定動作" の価値の方が大きいです。長尺 / 高解像度 / 14B モデルで差はさらに広がります (未測)。
| レイヤー | 既知の壁 |
|---|---|
| CUDA toolkit | nvcc が sm_100 を扱うには CUDA 12.8 以上。それ未満だと "unrecognized arch" |
| PyTorch | 2.7.0+cu128 で初めて Blackwell の Tensor Core を fully 使える。古い wheel だと torch.cuda.get_device_capability() は (10, 0) を返すが kernel 側が未対応 |
| Modal builder | nvidia/cuda:12.8.1-devel-ubuntu22.04 がベース。build-essential には g++ は入るが clang は別パッケージ で、Modal 内 Python は clang でビルドされているため setuptools が clang++ を要求して link 失敗 |
| SageAttention setup.py | 拡張モジュール名は _qattn_sm80 等だが、これは アルゴリズム種別で target arch とは無関係。TORCH_CUDA_ARCH_LIST=10.0 で各 .so に sm_100 PTX を埋められる |
| SageAttention dispatcher | core.py の sageattn() は sm80/86/89/90/120/121 を hardcode で分岐し、それ以外は raise ValueError("Unsupported CUDA architecture: sm100")。これが ComfyUI 側で catch されて pytorch attention instead の log が出る |
| ComfyUI | --use-sage-attention 指定でも、SageAttention の例外を catch して silently SDPA に切替わる仕様。何が起きているのか分からない のが最大の罠 |
| Modal volume mount | git clone 直後の /opt/ComfyUI/models には put_*_here の placeholder があり 非空のままだとボリュームをマウントできない。rm -rf && mkdir で空にしておく必要あり |
git clone 後・pip wheel 前に sageattention/core.py の sageattn() 関数本体を sed/Python で書き換えます。新しい branch は sm_89/sm_120/sm_121 と同じ FP8 経路 (sageattn_qk_int8_pv_fp8_cuda, pv_accum_dtype="fp32+fp16") に B200 をルーティング:1elif arch == "sm100": # Blackwell datacenter (B200)
2 return sageattn_qk_int8_pv_fp8_cuda(
3 q, k, v, tensor_layout=tensor_layout, is_causal=is_causal,
4 qk_quant_gran="per_warp", sm_scale=sm_scale,
5 return_lse=return_lse, pv_accum_dtype="fp32+fp16")patches/sm100_dispatch.diff。TORCH_CUDA_ARCH_LIST=10.0 # Blackwell datacenter のみ生成 (B200 は sm_100, B100 は sm_100、RTX 50 系は sm_120)
FORCE_CUDA=1 # nvcc が GPU を見つけられなくても compile を強行
MAX_JOBS=4 # Modal builder の vCPU/RAM に合わせて控えめに (デフォの 32 だと OOM)
NVCC_APPEND_FLAGS=--threads 4
EXT_PARALLEL=2
CUDA_HOME=/usr/local/cuda1build_image = (
2 modal.Image.from_registry("nvidia/cuda:12.8.1-devel-ubuntu22.04", add_python="3.11")
3 .apt_install("git", "build-essential", "ninja-build", "ca-certificates", "wget",
4 "clang") # ← link 段で clang++ を呼ぶので必須
5 .pip_install("packaging", "wheel", "setuptools", "ninja", "build")
6 .pip_install("torch==2.7.0", "torchvision==0.22.0", "torchaudio==2.7.0",
7 index_url="https://download.pytorch.org/whl/cu128")
8)pip wheel 後、ビルド関数内でその場で:pip install でローカルに入れてinspect.getsource(c.sageattn) で 'sm100' in src を assert (パック後にも patch が残っているか)torch.randn(device="cuda") + sageattn(...) で B200 上で forward を実行、shape/dtype を確認/opt/ComfyUI/models と /opt/ComfyUI/output を image build 時に rm -rf & mkdir してから Modal Volume をマウント。これで ComfyUI が起動時に必要なサブディレクトリを自動生成、HF からダウンロードしたモデルは /opt/ComfyUI/models/diffusion_models/*.safetensors 等の標準パスに置けば自動認識。1whl = sorted(glob.glob("/wheels/sageattention-*.whl"))[-1]
2subprocess.check_call(["pip", "install", "--force-reinstall", "--no-deps", whl])
3subprocess.Popen(["python", "main.py", "--listen", "0.0.0.0", "--port", "8188",
4 "--use-sage-attention", "--disable-auto-launch"], cwd="/opt/ComfyUI")Unsupported CUDA architecture: sm100 が 1 度も出ないこと が engage 確認の決定打。modal_B200_sageattetion_comfyUI/
├── README.md ← この文書
├── wheels/
│ └── sageattention-2.2.0-cp311-cp311-linux_x86_64.whl ← 主成果物 (17 MB)
├── patches/
│ └── sm100_dispatch.diff ← core.py への sm_100 分岐パッチ
├── scripts/
│ ├── comfy_b200.py ← wheel build + ComfyUI web server
│ ├── wan22_demo.py ← Wan2.2 モデル DL + 動画生成 + ベンチ
│ └── push_to_hf.py ← この repo を再アップする用
├── benchmarks/
│ ├── wan22_sage_vs_sdpa.json ← 全 6 run の生データ
│ ├── sample_sdpa.webp ← SDPA 出力サンプル
│ └── sample_sage.webp ← SageAttention 出力サンプル
├── videos/
│ ├── wan22_00001_.webp ← 1 回目 (SDPA fallback だった)
│ ├── wan22_00001_.json
│ ├── wan22_00002_.webp ← 2 回目 (SageAttention engaged)
│ └── wan22_00002_.json
└── logs/
└── build_success.log ← B200 forward sanity 込みのビルドログpip install modal && modal token new)1modal run scripts/comfy_b200.py::build_wheel
2# 初回 ~10 min。`./wheels/sageattention-*.whl` と Modal Volume `sage-wheels` に保存される。
3# 既にあるときは skip、上書きしたいなら --force。1modal serve scripts/comfy_b200.py
2# 印字された https://<...>.modal.run を開けば ComfyUI UI。
3# モデルは `/opt/ComfyUI/models/...` 配下に置けば認識。
4# Modal Volume `comfy-models` に置くなら:
5modal volume put comfy-models <local-file> /diffusion_models/foo.safetensors1# 一度だけモデルをボリュームに DL (合計 ~17 GB、~5-10 min)
2modal run scripts/wan22_demo.py::download_models
3
4# 生成
5modal run scripts/wan22_demo.py::generate
6modal run scripts/wan22_demo.py::generate --prompt "..." --seed 1234 --steps 30
7# → ./videos/wan22_*.webp + 同名 .json (メタデータ)1modal run scripts/wan22_demo.py::benchmark
2modal run scripts/wan22_demo.py::benchmark --seeds 42,1234,7777 --steps 30
3# → ./benchmarks/wan22_sage_vs_sdpa.jsonTORCH_CUDA_ARCH_LIST=12.0 で再ビルド推奨。d1a57a5)。upstream で sm_100 が正式サポートされたら本 patch は不要に。Wan2.2-T2V-A14B 等) は未検証。VRAM 192 GB あれば動くはずだがメモリ管理に注意。