Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e23de0e693 | ||
|
|
2e6dadb296 | ||
|
|
da4c63d3d4 | ||
|
|
73348a6034 | ||
|
|
0a4313e4c3 | ||
|
|
44b4952dc8 | ||
|
|
512e2d40f3 | ||
|
|
720ff188cc | ||
|
|
6a12858acc | ||
|
|
64d856dab6 | ||
|
|
9ac320b50b | ||
|
|
83f12f1389 | ||
|
|
d4e2312d6c | ||
|
|
1f7e3104be | ||
|
|
711fdb6a33 | ||
|
|
28f903d0d1 |
@@ -0,0 +1,24 @@
|
||||
name: Publish to Comfy registry
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
paths:
|
||||
- "pyproject.toml"
|
||||
|
||||
jobs:
|
||||
publish-node:
|
||||
name: Publish Custom Node to registry
|
||||
runs-on: ubuntu-latest
|
||||
# if this is a forked repository. Skipping the workflow.
|
||||
if: github.event.repository.fork == false
|
||||
steps:
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish Custom Node
|
||||
uses: Comfy-Org/publish-node-action@main
|
||||
with:
|
||||
## Add your own personal access token to your Github Repository secrets and reference it here.
|
||||
personal_access_token: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
|
||||
@@ -17,3 +17,8 @@ Current `Visionatrix/UI` nodes list:
|
||||
- **VixUi-CheckboxLogic** - to define the boolean logical switch (checkbox), e.g. two modes and paths of workflow execution;
|
||||
- **VixUi-ListLogic** - to define the list of available mode options similar to `VixUi-CheckboxLogic` (up to 6 input options);
|
||||
- **VixUi-WorkflowMetadata** - mandatory node to fill the workflow metadata required for each Visionatrix flow for displaying in the UI list of workflows;
|
||||
- **VixUiAspectRatioSelector** - use it to display the desired image aspect ratio for your Flow.
|
||||
|
||||
### Incorporated nodes
|
||||
|
||||
- **StyleAlignedBatchAlign** - from the `style_aligned_comfy` repository
|
||||
|
||||
+113
@@ -1,5 +1,7 @@
|
||||
import json
|
||||
|
||||
from .style_aligned import StyleAlignedBatchAlign
|
||||
|
||||
|
||||
class AnyType(str):
|
||||
def __ne__(self, __value: object) -> bool:
|
||||
@@ -9,6 +11,51 @@ class AnyType(str):
|
||||
any_typ = AnyType("*")
|
||||
|
||||
|
||||
class VixUiAspectRatioSelector:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
return {
|
||||
"required": {
|
||||
"aspect_ratio": (
|
||||
[
|
||||
"1:1 (1024x1024)",
|
||||
"2:3 (832x1216)",
|
||||
"3:4 (896x1152)",
|
||||
"5:8 (768x1216)",
|
||||
"9:16 (768x1344)",
|
||||
"9:19 (704x1472)",
|
||||
"9:21 (640x1536)",
|
||||
"3:2 (1216x832)",
|
||||
"4:3 (1152x896)",
|
||||
"8:5 (1216x768)",
|
||||
"16:9 (1344x768)",
|
||||
"19:9 (1472x704)",
|
||||
"21:9 (1536x640)",
|
||||
],
|
||||
),
|
||||
"display_name": ("STRING", {"default": "Aspect Ratio"}),
|
||||
"optional": ("BOOLEAN", {"default": True}),
|
||||
"advanced": ("BOOLEAN", {"default": True}),
|
||||
"order": ("INT", {"default": 20}),
|
||||
"custom_id": ("STRING", {"default": "aspect_ratio"}),
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "INT", "INT")
|
||||
RETURN_NAMES = ("ratio", "width", "height")
|
||||
FUNCTION = "do_it"
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
|
||||
def do_it(self, aspect_ratio, **kwargs):
|
||||
ratio, dims = aspect_ratio.split(" (")
|
||||
dims = dims[:-1] # Remove the closing parenthesis
|
||||
width, height = map(int, dims.split("x"))
|
||||
return ratio, width, height
|
||||
|
||||
|
||||
class VixUiCheckbox:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -167,6 +214,7 @@ class VixUiPrompt:
|
||||
},
|
||||
"optional": {
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
"translatable": ("BOOLEAN", {"default": False}),
|
||||
},
|
||||
}
|
||||
RETURN_TYPES = ("STRING",)
|
||||
@@ -300,6 +348,10 @@ class VixUiWorkflowMetadata:
|
||||
"requires": ("STRING", {"default": "[]", "multiline": True}),
|
||||
"is_seed_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_count_supported": ("BOOLEAN", {"default": True}),
|
||||
"is_translations_supported": ("BOOLEAN", {"default": False}),
|
||||
"is_macos_supported": ("BOOLEAN", {"default": True}),
|
||||
"required_memory_gb": ("FLOAT", {"default": 0.0, "step": 0.1, "round": False}),
|
||||
"hidden": ("BOOLEAN", {"default": False}),
|
||||
}
|
||||
}
|
||||
RETURN_TYPES = ("STRING",)
|
||||
@@ -311,7 +363,61 @@ class VixUiWorkflowMetadata:
|
||||
return (text,)
|
||||
|
||||
|
||||
class VixDynamicLoraDefinition:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL", {"tooltip": "The diffusion model the LoRA will be applied to."}),
|
||||
"clip": ("CLIP", {"tooltip": "The CLIP model the LoRA will be applied to."}),
|
||||
"base_model_type": ("STRING", {"tooltip": "The base type of model in CivitAI format."}),
|
||||
"description": ("STRING", {"tooltip": "Brief explanation of LoRA functionality at the added place."}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MODEL", "CLIP")
|
||||
OUTPUT_TOOLTIPS = ("The modified diffusion model.", "The modified CLIP model.")
|
||||
CATEGORY = "Visionatrix/UI"
|
||||
FUNCTION = "do_it"
|
||||
DESCRIPTION = "Node that allows dynamic selection of any supported LoRAs from CivitAI in the Visionatrix UI."
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, model, clip, **kwargs) -> tuple:
|
||||
return model, clip
|
||||
|
||||
|
||||
class VixCheckboxLogic:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"state": ("BOOLEAN", {"default": False}),
|
||||
"input_off_state": (any_typ, {"lazy": True}),
|
||||
"input_on_state": (any_typ, {"lazy": True}),
|
||||
},
|
||||
"optional": {},
|
||||
}
|
||||
|
||||
RETURN_TYPES = (any_typ,)
|
||||
RETURN_NAMES = ("output_to",)
|
||||
CATEGORY = "Visionatrix/Logic"
|
||||
FUNCTION = "do_it"
|
||||
|
||||
@classmethod
|
||||
def do_it(cls, state, **kwargs) -> tuple:
|
||||
if state is False:
|
||||
return (kwargs.get("input_off_state", None),)
|
||||
return (kwargs.get("input_on_state", None),)
|
||||
|
||||
@staticmethod
|
||||
def check_lazy_status(state, **kwargs):
|
||||
if state is False:
|
||||
return ["input_off_state"]
|
||||
return ["input_on_state"]
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"VixUiAspectRatioSelector": VixUiAspectRatioSelector,
|
||||
"VixUiCheckbox": VixUiCheckbox,
|
||||
"VixUiRangeFloat": VixUiRangeFloat,
|
||||
"VixUiRangeScaleFloat": VixUiRangeScaleFloat,
|
||||
@@ -321,9 +427,13 @@ NODE_CLASS_MAPPINGS = {
|
||||
"VixUiCheckboxLogic": VixUiCheckboxLogic,
|
||||
"VixUiListLogic": VixUiListLogic,
|
||||
"VixUiWorkflowMetadata": VixUiWorkflowMetadata,
|
||||
"VixDynamicLoraDefinition": VixDynamicLoraDefinition,
|
||||
"VixCheckboxLogic": VixCheckboxLogic,
|
||||
"StyleAlignedBatchAlign": StyleAlignedBatchAlign,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VixUiAspectRatioSelector": "VixUI-Aspect Ratio",
|
||||
"VixUiCheckbox": "VixUI-Checkbox",
|
||||
"VixUiRangeFloat": "VixUI-RangeFloat",
|
||||
"VixUiRangeScaleFloat": "VixUI-RangeScaleFloat",
|
||||
@@ -333,4 +443,7 @@ NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"VixUiCheckboxLogic": "VixUI-CheckboxLogic",
|
||||
"VixUiListLogic": "VixUI-ListLogic",
|
||||
"VixUiWorkflowMetadata": "VixUI-WorkflowMetadata",
|
||||
"VixDynamicLoraDefinition": "Vix-DynamicLoraDefinition",
|
||||
"VixCheckboxLogic": "Vix-CheckboxLogic",
|
||||
"StyleAlignedBatchAlign": "StyleAligned Batch Align",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[project]
|
||||
name = "comfyui-visionatrix"
|
||||
description = "The ComfyUI-Visionatrix nodes are designed for convenient ComfyUI to [a/Visionatrix](https://github.com/Visionatrix/Visionatrix) workflow support migration, in particular to extract prompt input params (input, textarea, checkbox, select, range, file) to be used in simplified Visionatrix UI."
|
||||
version = "1.0.7"
|
||||
license = {file = "LICENSE"}
|
||||
urls.Repository = "https://github.com/Visionatrix/ComfyUI-Visionatrix"
|
||||
|
||||
[tool.comfy]
|
||||
PublisherId = "visionatrix"
|
||||
DisplayName = "ComfyUI-Visionatrix"
|
||||
Icon = "https://raw.githubusercontent.com/Visionatrix/VixFlowsDocs/main/screenshots/logo_org_400x400.png"
|
||||
@@ -0,0 +1,162 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2023 Brian Fitzgerald
|
||||
# original repository: https://github.com/brianfitzgerald/style_aligned_comfy
|
||||
|
||||
import torch.nn as nn
|
||||
import torch
|
||||
|
||||
from comfy.model_patcher import ModelPatcher
|
||||
|
||||
|
||||
T = torch.Tensor
|
||||
|
||||
|
||||
class StyleAlignedArgs:
|
||||
def __init__(self, share_attn: str) -> None:
|
||||
self.adain_keys = "k" in share_attn
|
||||
self.adain_values = "v" in share_attn
|
||||
self.adain_queries = "q" in share_attn
|
||||
|
||||
share_attention: bool = True
|
||||
adain_queries: bool = True
|
||||
adain_keys: bool = True
|
||||
adain_values: bool = True
|
||||
|
||||
|
||||
def expand_first(
|
||||
feat: T,
|
||||
scale=1.0,
|
||||
) -> T:
|
||||
b = feat.shape[0]
|
||||
feat_style = torch.stack((feat[0], feat[b // 2])).unsqueeze(1)
|
||||
if scale == 1:
|
||||
feat_style = feat_style.expand(2, b // 2, *feat.shape[1:])
|
||||
else:
|
||||
feat_style = feat_style.repeat(1, b // 2, 1, 1, 1)
|
||||
feat_style = torch.cat([feat_style[:, :1], scale * feat_style[:, 1:]], dim=1)
|
||||
return feat_style.reshape(*feat.shape)
|
||||
|
||||
|
||||
def concat_first(feat: T, dim=2, scale=1.0) -> T:
|
||||
feat_style = expand_first(feat, scale=scale)
|
||||
return torch.cat((feat, feat_style), dim=dim)
|
||||
|
||||
|
||||
def calc_mean_std(feat, eps: float = 1e-5) -> "tuple[T, T]":
|
||||
feat_std = (feat.var(dim=-2, keepdims=True) + eps).sqrt()
|
||||
feat_mean = feat.mean(dim=-2, keepdims=True)
|
||||
return feat_mean, feat_std
|
||||
|
||||
|
||||
def adain(feat: T) -> T:
|
||||
feat_mean, feat_std = calc_mean_std(feat)
|
||||
feat_style_mean = expand_first(feat_mean)
|
||||
feat_style_std = expand_first(feat_std)
|
||||
feat = (feat - feat_mean) / feat_std
|
||||
feat = feat * feat_style_std + feat_style_mean
|
||||
return feat
|
||||
|
||||
|
||||
class SharedAttentionProcessor:
|
||||
def __init__(self, args: StyleAlignedArgs, scale: float):
|
||||
self.args = args
|
||||
self.scale = scale
|
||||
|
||||
def __call__(self, q, k, v, extra_options):
|
||||
if self.args.adain_queries:
|
||||
q = adain(q)
|
||||
if self.args.adain_keys:
|
||||
k = adain(k)
|
||||
if self.args.adain_values:
|
||||
v = adain(v)
|
||||
if self.args.share_attention:
|
||||
k = concat_first(k, -2, scale=self.scale)
|
||||
v = concat_first(v, -2)
|
||||
|
||||
return q, k, v
|
||||
|
||||
|
||||
def get_norm_layers(
|
||||
layer: nn.Module,
|
||||
norm_layers_: "dict[str, list[nn.GroupNorm | nn.LayerNorm]]",
|
||||
share_layer_norm: bool,
|
||||
share_group_norm: bool,
|
||||
):
|
||||
if isinstance(layer, nn.LayerNorm) and share_layer_norm:
|
||||
norm_layers_["layer"].append(layer)
|
||||
if isinstance(layer, nn.GroupNorm) and share_group_norm:
|
||||
norm_layers_["group"].append(layer)
|
||||
else:
|
||||
for child_layer in layer.children():
|
||||
get_norm_layers(
|
||||
child_layer, norm_layers_, share_layer_norm, share_group_norm
|
||||
)
|
||||
|
||||
|
||||
def register_norm_forward(
|
||||
norm_layer: nn.GroupNorm | nn.LayerNorm,
|
||||
) -> nn.GroupNorm | nn.LayerNorm:
|
||||
if not hasattr(norm_layer, "orig_forward"):
|
||||
setattr(norm_layer, "orig_forward", norm_layer.forward)
|
||||
orig_forward = norm_layer.orig_forward
|
||||
|
||||
def forward_(hidden_states: T) -> T:
|
||||
n = hidden_states.shape[-2]
|
||||
hidden_states = concat_first(hidden_states, dim=-2)
|
||||
hidden_states = orig_forward(hidden_states) # type: ignore
|
||||
return hidden_states[..., :n, :]
|
||||
|
||||
norm_layer.forward = forward_ # type: ignore
|
||||
return norm_layer
|
||||
|
||||
|
||||
def register_shared_norm(
|
||||
model: ModelPatcher,
|
||||
share_group_norm: bool = True,
|
||||
share_layer_norm: bool = True,
|
||||
):
|
||||
norm_layers = {"group": [], "layer": []}
|
||||
get_norm_layers(model.model, norm_layers, share_layer_norm, share_group_norm)
|
||||
print(
|
||||
f"Patching {len(norm_layers['group'])} group norms, {len(norm_layers['layer'])} layer norms."
|
||||
)
|
||||
return [register_norm_forward(layer) for layer in norm_layers["group"]] + [
|
||||
register_norm_forward(layer) for layer in norm_layers["layer"]
|
||||
]
|
||||
|
||||
|
||||
SHARE_NORM_OPTIONS = ["both", "group", "layer", "disabled"]
|
||||
SHARE_ATTN_OPTIONS = ["q+k", "q+k+v", "disabled"]
|
||||
|
||||
|
||||
class StyleAlignedBatchAlign:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL",),
|
||||
"share_norm": (SHARE_NORM_OPTIONS,),
|
||||
"share_attn": (SHARE_ATTN_OPTIONS,),
|
||||
"scale": ("FLOAT", {"default": 1, "min": 0, "max": 1.0, "step": 0.1}),
|
||||
}
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("MODEL",)
|
||||
FUNCTION = "patch"
|
||||
CATEGORY = "style_aligned"
|
||||
|
||||
def patch(
|
||||
self,
|
||||
model: ModelPatcher,
|
||||
share_norm: str,
|
||||
share_attn: str,
|
||||
scale: float,
|
||||
):
|
||||
m = model.clone()
|
||||
share_group_norm = share_norm in ["group", "both"]
|
||||
share_layer_norm = share_norm in ["layer", "both"]
|
||||
register_shared_norm(model, share_group_norm, share_layer_norm)
|
||||
args = StyleAlignedArgs(share_attn)
|
||||
m.set_model_attn1_patch(SharedAttentionProcessor(args, scale))
|
||||
return (m,)
|
||||
Reference in New Issue
Block a user