-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #498 from Kosinkadink/rework-modelpatcher
Rework ModelPatcher for upcoming ComfyUI update
- Loading branch information
Showing
31 changed files
with
1,865 additions
and
2,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import folder_paths | ||
from .animatediff.logger import logger | ||
from .animatediff.utils_model import get_available_motion_models, Folders | ||
from .animatediff.model_injection import prepare_dinklink_register_definitions | ||
from .animatediff.nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS | ||
from .animatediff import documentation | ||
from .animatediff.dinklink import init_dinklink | ||
|
||
if len(get_available_motion_models()) == 0: | ||
logger.error(f"No motion models found. Please download one and place in: {folder_paths.get_folder_paths(Folders.ANIMATEDIFF_MODELS)}") | ||
|
||
WEB_DIRECTORY = "./web" | ||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] | ||
documentation.format_descriptions(NODE_CLASS_MAPPINGS) | ||
|
||
init_dinklink() | ||
prepare_dinklink_register_definitions() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from torch import nn | ||
|
||
import comfy.ops | ||
|
||
|
||
FancyVideoKeys = [ | ||
'fps_embedding.linear.bias', | ||
'fps_embedding.linear.weight', | ||
'motion_embedding.linear.bias', | ||
'motion_embedding.linear.weight', | ||
'conv_in.bias', | ||
'conv_in.weight', | ||
] | ||
|
||
|
||
def initialize_weights_to_zero(m): | ||
if isinstance(m, nn.Linear) or isinstance(m, nn.Conv2d): | ||
nn.init.constant_(m.weight, 0) | ||
if m.bias is not None: | ||
nn.init.constant_(m.bias, 0) | ||
|
||
|
||
class FancyVideoCondEmbedding(nn.Module): | ||
def __init__(self, in_channels: int, cond_embed_dim: int, act_fn: str = "silu", ops=comfy.ops.disable_weight_init): | ||
super().__init__() | ||
|
||
self.linear = ops.Linear(in_channels, cond_embed_dim) | ||
self.act = None | ||
if act_fn == "silu": | ||
self.act = nn.SiLU() | ||
elif act_fn == "mish": | ||
self.act = nn.Mish() | ||
|
||
def forward(self, sample): | ||
sample = self.linear(sample) | ||
|
||
if self.act is not None: | ||
sample = self.act(sample) | ||
|
||
return sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#################################################################################################### | ||
# DinkLink is my method of sharing classes/functions between my nodes. | ||
# | ||
# My DinkLink-compatible nodes will inject comfy.hooks with a __DINKLINK attr | ||
# that stores a dictionary, where any of my node packs can store their stuff. | ||
# | ||
# It is not intended to be accessed by node packs that I don't develop, so things may change | ||
# at any time. | ||
# | ||
# DinkLink also serves as a proof-of-concept for a future ComfyUI implementation of | ||
# purposely exposing node pack classes/functions with other node packs. | ||
#################################################################################################### | ||
from __future__ import annotations | ||
import comfy.hooks | ||
|
||
from .motion_module_ad import AnimateDiffModel, AnimateDiffInfo | ||
|
||
DINKLINK = "__DINKLINK" | ||
|
||
|
||
def init_dinklink(): | ||
create_dinklink() | ||
prepare_dinklink() | ||
|
||
def create_dinklink(): | ||
if not hasattr(comfy.hooks, DINKLINK): | ||
setattr(comfy.hooks, DINKLINK, {}) | ||
|
||
def get_dinklink() -> dict[str, dict[str]]: | ||
create_dinklink() | ||
return getattr(comfy.hooks, DINKLINK) | ||
|
||
|
||
class DinkLinkConst: | ||
VERSION = "version" | ||
# ACN | ||
ACN = "ACN" | ||
ACN_CREATE_OUTER_SAMPLE_WRAPPER = "create_outer_sample_wrapper" | ||
# ADE | ||
ADE = "ADE" | ||
ADE_ANIMATEDIFFMODEL = "AnimateDiffModel" | ||
ADE_ANIMATEDIFFINFO = "AnimateDiffInfo" | ||
ADE_CREATE_MOTIONMODELPATCHER = "create_MotionModelPatcher" | ||
|
||
def prepare_dinklink(): | ||
# expose classes | ||
d = get_dinklink() | ||
link_ade = d.setdefault(DinkLinkConst.ADE, {}) | ||
link_ade[DinkLinkConst.VERSION] = 10000 | ||
link_ade[DinkLinkConst.ADE_ANIMATEDIFFMODEL] = AnimateDiffModel | ||
link_ade[DinkLinkConst.ADE_ANIMATEDIFFINFO] = AnimateDiffInfo | ||
|
||
def get_acn_outer_sample_wrapper(throw_exception=True): | ||
d = get_dinklink() | ||
try: | ||
link_acn = d[DinkLinkConst.ACN] | ||
return link_acn[DinkLinkConst.ACN_CREATE_OUTER_SAMPLE_WRAPPER] | ||
except KeyError: | ||
if throw_exception: | ||
raise Exception("Advanced-ControlNet nodes need to be installed to make use of ContextRef; " + \ | ||
"they are either not installed or are of an insufficient version.") | ||
return None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.