Fix model patcher types

This commit is contained in:
huchenlei 2024-05-24 18:00:44 -04:00
parent 58c9838274
commit ddd2ac967c
2 changed files with 37 additions and 1 deletions

View File

@ -6,7 +6,7 @@ import uuid
import comfy.utils import comfy.utils
import comfy.model_management import comfy.model_management
from comfy.types import UnetWrapperFunction from comfy.model_patcher_types import UnetWrapperFunction
def apply_weight_decompose(dora_scale, weight): def apply_weight_decompose(dora_scale, weight):

View File

@ -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]