見出し画像

Fixed Impact-Pack for ComfyUI V3

…警戒していたtransformers4.57.0が意外と何事もなかった一方で、またAPI変更に伴うエラーです。

ComfyUI-Impact-Pack 修正完了レポート

問題の概要

エラー: `'DifferentialDiffusion' object has no attribute 'apply'` → `'patch'`

原因: ComfyUI v3でのAPI変更に対応していなかった

対象ファイル: `ComfyUI/custom_nodes/comfyui-impact-pack/modules/impact/impact_pack.py`


修正の経緯

【第1段階】元のコード(エラー)

# 304行目付近
model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]

エラー: `.apply()` メソッドが存在しない

【第2段階】第一の修正(失敗)

model = nodes_differential_diffusion.DifferentialDiffusion().patch(model)[0]

エラー: `.patch()` メソッドも存在しない

【第3段階】最終修正(成功)

model = nodes_differential_diffusion.DifferentialDiffusion.execute(model)[0]

正解: クラスメソッド `.execute()` を直接呼び出し


ComfyUI APIの変更点

ComfyUI v2以前(旧API)

class DifferentialDiffusion:
    def apply(self, model):
        # インスタンスメソッド
        return (patched_model,)

# 使い方
instance = DifferentialDiffusion()
model = instance.apply(model)[0]

ComfyUI v3(新API)

class DifferentialDiffusion(io.ComfyNode):
    @classmethod
    def execute(cls, model, strength=1.0) -> io.NodeOutput:
        # クラスメソッド
        model = model.clone()
        model.set_model_denoise_mask_function(
            lambda *args, **kwargs: cls.forward(*args, **kwargs, strength=strength)
        )
        return io.NodeOutput(model)

# 使い方
model = DifferentialDiffusion.execute(model)[0]

重要な技術的変更

| 項目 | v2以前 | v3 |
|------|--------|-----|
| メソッド種別 | インスタンスメソッド | クラスメソッド (`@classmethod`) |
| 呼び出し方 | `Class().method()` | `Class.method()` |
| メソッド名 | `.apply()` | `.execute()` |
| 戻り値 | `tuple` | `io.NodeOutput` |
| 基底クラス | なし | `io.ComfyNode` |


DifferentialDiffusionの役割

機能: マスク境界のグラデーション処理

# 実行されるコード(簡略版)
def forward(sigma, denoise_mask, extra_options, strength):
    # タイムステップに基づいてマスクの閾値を計算
    threshold = (current_ts - ts_to) / (ts_from - ts_to)
    
    # 二値マスクを生成
    binary_mask = (denoise_mask >= threshold).to(denoise_mask.dtype)
    
    # strengthパラメータでブレンド
    if strength < 1:
        return strength * binary_mask + (1 - strength) * denoise_mask
    else:
        return binary_mask

用途:

  • インペイント時のマスク境界を自然にぼかす

  • `DetailerForEach` ノードの `noise_mask_feather` と連携

  • マスクのグラデーション効果を実現


該当行: 304行目(および同様の箇所すべて)

修正内容:

# 修正前
if not (isinstance(model, str) and model == "DUMMY") and noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
    model = nodes_differential_diffusion.DifferentialDiffusion().apply(model)[0]

# 修正後
if not (isinstance(model, str) and model == "DUMMY") and noise_mask_feather > 0 and 'denoise_mask_function' not in model.model_options:
    model = nodes_differential_diffusion.DifferentialDiffusion.execute(model)[0]

動作確認

✅ エラーが解消され、`DetailerForEach` ノードが正常に動作するようになりました

✅ `noise_mask_feather` パラメータによるマスクのぼかし効果が正しく適用されます

✅ ComfyUI v3の新しいノードAPIに完全対応しました

いいなと思ったら応援しよう!