mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-22 07:27:00 +08:00
Add types.py
This commit is contained in:
parent
902f12e0b7
commit
3f85a20b13
@ -3,38 +3,10 @@ import copy
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Callable, Protocol, TypedDict, Optional, List
|
|
||||||
|
|
||||||
import comfy.utils
|
import comfy.utils
|
||||||
import comfy.model_management
|
import comfy.model_management
|
||||||
|
from comfy.types import UnetWrapperFunction
|
||||||
|
|
||||||
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: Optional[torch.Tensor]
|
|
||||||
c_crossattn: Optional[torch.Tensor]
|
|
||||||
control: Optional[torch.Tensor]
|
|
||||||
transformer_options: Optional[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]
|
|
||||||
|
|
||||||
|
|
||||||
def apply_weight_decompose(dora_scale, weight):
|
def apply_weight_decompose(dora_scale, weight):
|
||||||
|
|||||||
32
comfy/types.py
Normal file
32
comfy/types.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import torch
|
||||||
|
from typing import Callable, Protocol, TypedDict, Optional, List
|
||||||
|
|
||||||
|
|
||||||
|
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: Optional[torch.Tensor]
|
||||||
|
c_crossattn: Optional[torch.Tensor]
|
||||||
|
control: Optional[torch.Tensor]
|
||||||
|
transformer_options: Optional[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]
|
||||||
Loading…
x
Reference in New Issue
Block a user