diff --git a/comfy/model_patcher.py b/comfy/model_patcher.py index c397ee51c..1fc5a6cfe 100644 --- a/comfy/model_patcher.py +++ b/comfy/model_patcher.py @@ -6,7 +6,7 @@ import uuid import comfy.utils import comfy.model_management -from comfy.types import UnetWrapperFunction +from comfy.model_patcher_types import UnetWrapperFunction def apply_weight_decompose(dora_scale, weight): diff --git a/comfy/model_patcher_types.py b/comfy/model_patcher_types.py new file mode 100644 index 000000000..a31242ea8 --- /dev/null +++ b/comfy/model_patcher_types.py @@ -0,0 +1,36 @@ +from __future__ import annotations + +from typing import Callable, Protocol, TypedDict, List +from typing_extensions import NotRequired + +import torch + + +class UnetApplyFunction(Protocol): + """Function signature protocol on comfy.model_base.BaseModel.apply_model""" + + def __call__(self, x: torch.Tensor, t: torch.Tensor, **kwargs) -> torch.Tensor: + pass + + +class UnetApplyConds(TypedDict): + """Optional conditions for unet apply function.""" + + c_concat: NotRequired[torch.Tensor] + c_crossattn: NotRequired[torch.Tensor] + control: NotRequired[torch.Tensor] + transformer_options: NotRequired[dict] + + +class UnetParams(TypedDict): + # Tensor of shape [B, C, H, W] + input: torch.Tensor + # Tensor of shape [B] + timestep: torch.Tensor + c: UnetApplyConds + # List of [0, 1], [0], [1], ... + # 0 means unconditional, 1 means conditional + cond_or_uncond: List[int] + + +UnetWrapperFunction = Callable[[UnetApplyFunction, UnetParams], torch.Tensor]