text
stringlengths
0
1.28M
import torch class DifferentialDiffusion(): @classmethod def INPUT_TYPES(s): return {"required": {"model": ("MODEL", ), }} RETURN_TYPES = ("MODEL",) FUNCTION = "apply" CATEGORY = "_for_testing" INIT = False def apply(self, model): model = model.clone() model.set_model_denoise_mask_function(self.forward) return (model,)...
import torch import logging def Fourier_filter(x, threshold, scale): x_freq = torch.fft.fftn(x.float(), dim=(-2, -1)) x_freq = torch.fft.fftshift(x_freq, dim=(-2, -1)) B, C, H, W = x_freq.shape mask = torch.ones((B, C, H, W), device=x.device) crow, ccol = H mask[..., crow - threshold:crow + threshold, ccol - threshold:...
import numpy as np import torch def loglinear_interp(t_steps, num_steps): """ Performs log-linear interpolation of a given array of decreasing numbers. """ xs = np.linspace(0, 1, len(t_steps)) ys = np.log(t_steps[::-1]) new_xs = np.linspace(0, 1, num_steps) new_ys = np.interp(new_xs, xs, ys) interped_ys = np.exp(new_ys...
import comfy.utils import folder_paths import torch import logging def load_hypernetwork_patch(path, strength): sd = comfy.utils.load_torch_file(path, safe_load=True) activation_func = sd.get('activation_func', 'linear') is_layer_norm = sd.get('is_layer_norm', False) use_dropout = sd.get('use_dropout', False) activate_...
import math from einops import rearrange from torch import randint def random_divisor(value: int, min_value: int, /, max_options: int = 1) -> int: min_value = min(min_value, value) divisors = [i for i in range(min_value, value + 1) if value % i == 0] ns = [value if len(ns) - 1 > 0: idx = randint(low=0, high=len(ns) - 1...
import nodes import folder_paths from comfy.cli_args import args from PIL import Image from PIL.PngImagePlugin import PngInfo import numpy as np import json import os MAX_RESOLUTION = nodes.MAX_RESOLUTION class ImageCrop: @classmethod def INPUT_TYPES(s): return {"required": { "image": ("IMAGE",), "width": ("INT", {"def...
import torch class InstructPixToPixConditioning: @classmethod def INPUT_TYPES(s): return {"required": {"positive": ("CONDITIONING", ), "negative": ("CONDITIONING", ), "vae": ("VAE", ), "pixels": ("IMAGE", ), }} RETURN_TYPES = ("CONDITIONING","CONDITIONING","LATENT") RETURN_NAMES = ("positive", "negative", "latent") FUN...
import comfy.utils import torch def reshape_latent_to(target_shape, latent): if latent.shape[1:] != target_shape[1:]: latent = comfy.utils.common_upscale(latent, target_shape[3], target_shape[2], "bilinear", "center") return comfy.utils.repeat_to_batch_size(latent, target_shape[0]) class LatentAdd: @classmethod def INP...
import numpy as np import scipy.ndimage import torch import comfy.utils from nodes import MAX_RESOLUTION def composite(destination, source, x, y, mask = None, multiplier = 8, resize_source = False): source = source.to(destination.device) if resize_source: source = torch.nn.functional.interpolate(source, size=(destinati...
import folder_paths import comfy.sd import comfy.model_sampling import comfy.latent_formats import torch class LCM(comfy.model_sampling.EPS): def calculate_denoised(self, sigma, model_output, model_input): timestep = self.timestep(sigma).view(sigma.shape[:1] + (1,) * (model_output.ndim - 1)) sigma = sigma.view(sigma.sh...
import torch import comfy.utils class PatchModelAddDownscale: upscale_methods = ["bicubic", "nearest-exact", "bilinear", "area", "bislerp"] @classmethod def INPUT_TYPES(s): return {"required": { "model": ("MODEL",), "block_number": ("INT", {"default": 3, "min": 1, "max": 32, "step": 1}), "downscale_factor": ("FLOAT", {...
import comfy.sd import comfy.utils import comfy.model_base import comfy.model_management import comfy.model_sampling import torch import folder_paths import json import os from comfy.cli_args import args class ModelMergeSimple: @classmethod def INPUT_TYPES(s): return {"required": { "model1": ("MODEL",), "model2": ("MOD...
import comfy_extras.nodes_model_merging class ModelMergeSD1(comfy_extras.nodes_model_merging.ModelMergeBlocks): CATEGORY = "advanced/model_merging/model_specific" @classmethod def INPUT_TYPES(s): arg_dict = { "model1": ("MODEL",), "model2": ("MODEL",)} argument = ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step...
import torch import comfy.model_management from kornia.morphology import dilation, erosion, opening, closing, gradient, top_hat, bottom_hat class Morphology: @classmethod def INPUT_TYPES(s): return {"required": {"image": ("IMAGE",), "operation": (["erode", "dilate", "open", "close", "gradient", "bottom_hat", "top_hat"]...
import comfy.model_patcher import comfy.samplers class PerturbedAttentionGuidance: @classmethod def INPUT_TYPES(s): return { "required": { "model": ("MODEL",), "scale": ("FLOAT", {"default": 3.0, "min": 0.0, "max": 100.0, "step": 0.1, "round": 0.01}), } } RETURN_TYPES = ("MODEL",) FUNCTION = "patch" CATEGORY = "_for_te...
import torch import comfy.model_management import comfy.sampler_helpers import comfy.samplers import comfy.utils import node_helpers def perp_neg(x, noise_pred_pos, noise_pred_neg, noise_pred_nocond, neg_scale, cond_scale): pos = noise_pred_pos - noise_pred_nocond neg = noise_pred_neg - noise_pred_nocond perp = neg - (...
import torch import torch.nn as nn import folder_paths import comfy.clip_model import comfy.clip_vision import comfy.ops VISION_CONFIG_DICT = { "hidden_size": 1024, "image_size": 224, "intermediate_size": 4096, "num_attention_heads": 16, "num_channels": 3, "num_hidden_layers": 24, "patch_size": 14, "projection_dim": 76...
import numpy as np import torch import torch.nn.functional as F from PIL import Image import math import comfy.utils import comfy.model_management class Blend: def __init__(self): pass @classmethod def INPUT_TYPES(s): return { "required": { "image1": ("IMAGE",), "image2": ("IMAGE",), "blend_factor": ("FLOAT", { "defaul...
import torch class LatentRebatch: @classmethod def INPUT_TYPES(s): return {"required": { "latents": ("LATENT",), "batch_size": ("INT", {"default": 1, "min": 1, "max": 4096}), }} RETURN_TYPES = ("LATENT",) INPUT_IS_LIST = True OUTPUT_IS_LIST = (True, ) FUNCTION = "rebatch" CATEGORY = "latent/batch" @staticmethod def get...
import torch from torch import einsum import torch.nn.functional as F import math from einops import rearrange, repeat from comfy.ldm.modules.attention import optimized_attention import comfy.samplers def attention_basic_with_sim(q, k, v, heads, mask=None, attn_precision=None): b, _, dim_head = q.shape dim_head scale =...
import folder_paths import comfy.sd import comfy.model_management import nodes import torch class TripleCLIPLoader: @classmethod def INPUT_TYPES(s): return {"required": { "clip_name1": (folder_paths.get_filename_list("clip"), ), "clip_name2": (folder_paths.get_filename_list("clip"), ), "clip_name3": (folder_paths.get_f...
import torch import comfy.utils class SD_4XUpscale_Conditioning: @classmethod def INPUT_TYPES(s): return {"required": { "images": ("IMAGE",), "positive": ("CONDITIONING",), "negative": ("CONDITIONING",), "scale_ratio": ("FLOAT", {"default": 4.0, "min": 0.0, "max": 10.0, "step": 0.01}), "noise_augmentation": ("FLOAT", {...
import torch import nodes import comfy.utils def camera_embeddings(elevation, azimuth): elevation = torch.as_tensor([elevation]) azimuth = torch.as_tensor([azimuth]) embeddings = torch.stack( [ torch.deg2rad( (90 - elevation) - (90) ), torch.sin(torch.deg2rad(azimuth)), torch.cos(torch.deg2rad(azimuth)), torch.deg2rad(...
""" This file is part of ComfyUI. Copyright (C) 2024 Stability AI This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program i...
import torch from typing import Tuple, Callable import math def do_nothing(x: torch.Tensor, mode:str=None): return x def mps_gather_workaround(input, dim, index): if input.shape[-1] == 1: return torch.gather( input.unsqueeze(-1), dim - 1 if dim < 0 else dim, index.unsqueeze(-1) ).squeeze(-1) else: return torch.gather(i...
import os import logging from spandrel import ModelLoader, ImageModelDescriptor from comfy import model_management import torch import comfy.utils import folder_paths try: from spandrel_extra_arches import EXTRA_REGISTRY from spandrel import MAIN_REGISTRY MAIN_REGISTRY.add(*EXTRA_REGISTRY) logging.info("Successfully im...
import nodes import torch import comfy.utils import comfy.sd import folder_paths import comfy_extras.nodes_model_merging class ImageOnlyCheckpointLoader: @classmethod def INPUT_TYPES(s): return {"required": { "ckpt_name": (folder_paths.get_filename_list("checkpoints"), ), }} RETURN_TYPES = ("MODEL", "CLIP_VISION", "VAE...
import nodes import folder_paths MAX_RESOLUTION = nodes.MAX_RESOLUTION class WebcamCapture(nodes.LoadImage): @classmethod def INPUT_TYPES(s): return { "required": { "image": ("WEBCAM", {}), "width": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}), "height": ("INT", {"default": 0, "min": 0, "max": MA...
from spandrel import ModelLoader def load_state_dict(state_dict): print("WARNING: comfy_extras.chainner_models is deprecated and has been replaced by the spandrel library.") return ModelLoader().load_from_state_dict(state_dict).eval()
from PIL import Image, ImageOps from io import BytesIO import numpy as np import struct import comfy.utils import time class SaveImageWebsocket: @classmethod def INPUT_TYPES(s): return {"required": {"images": ("IMAGE", ),} } RETURN_TYPES = () FUNCTION = "save_images" OUTPUT_NODE = True CATEGORY = "api/image" def save_i...
model: base_learning_rate: 1.0e-04 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn mon...
model: base_learning_rate: 1.0e-04 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn mon...
model: base_learning_rate: 1.0e-04 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn mon...
model: base_learning_rate: 1.0e-04 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn mon...
model: base_learning_rate: 1.0e-04 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn mon...
model: base_learning_rate: 7.5e-05 target: ldm.models.diffusion.ddpm.LatentInpaintDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: hybrid...
model: base_learning_rate: 1.0e-4 target: ldm.models.diffusion.ddpm.LatentDiffusion params: parameterization: "v" linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioni...
model: base_learning_rate: 1.0e-4 target: ldm.models.diffusion.ddpm.LatentDiffusion params: parameterization: "v" linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioni...
model: base_learning_rate: 1.0e-4 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn moni...
model: base_learning_rate: 1.0e-4 target: ldm.models.diffusion.ddpm.LatentDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: crossattn moni...
model: base_learning_rate: 5.0e-05 target: ldm.models.diffusion.ddpm.LatentInpaintDiffusion params: linear_start: 0.00085 linear_end: 0.0120 num_timesteps_cond: 1 log_every_t: 200 timesteps: 1000 first_stage_key: "jpg" cond_stage_key: "txt" image_size: 64 channels: 4 cond_stage_trainable: false conditioning_key: hybrid...
import json from urllib import request, parse import random prompt_text = """ { "3": { "class_type": "KSampler", "inputs": { "cfg": 8, "denoise": 1, "latent_image": [ "5", 0 ], "model": [ "4", 0 ], "negative": [ "7", 0 ], "positive": [ "6", 0 ], "sampler_name": "euler", "scheduler": "normal", "seed": 8566257, "steps": ...
import websocket import uuid import json import urllib.request import urllib.parse server_address = "127.0.0.1:8188" client_id = str(uuid.uuid4()) def queue_prompt(prompt): p = {"prompt": prompt, "client_id": client_id} data = json.dumps(p).encode('utf-8') req = urllib.request.Request("http: return json.loads(urllib.re...
import websocket import uuid import json import urllib.request import urllib.parse server_address = "127.0.0.1:8188" client_id = str(uuid.uuid4()) def queue_prompt(prompt): p = {"prompt": prompt, "client_id": client_id} data = json.dumps(p).encode('utf-8') req = urllib.request.Request("http: return json.loads(urllib.re...
import os import pytest def pytest_addoption(parser): parser.addoption('--output_dir', action="store", default='tests/inference/samples', help='Output directory for generated images') parser.addoption("--listen", type=str, default="127.0.0.1", metavar="IP", nargs="?", const="0.0.0.0", help="Specify the IP address to li...
Additional requirements for running tests: ``` pip install pytest pip install websocket-client==1.6.1 opencv-python==4.6.0.66 scikit-image==0.21.0 ``` Run inference tests: ``` pytest tests/inference ``` Compares images in 2 directories to ensure they are the same 1) Run an inference test to save a directory of "ground ...
import os import pytest def pytest_addoption(parser): parser.addoption('--baseline_dir', action="store", default='tests/inference/baseline', help='Directory for ground-truth images') parser.addoption('--test_dir', action="store", default='tests/inference/samples', help='Directory for images to test') parser.addoption('...
import datetime import numpy as np import os from PIL import Image import pytest from pytest import fixture from typing import Tuple, List from cv2 import imread, cvtColor, COLOR_BGR2RGB from skimage.metrics import structural_similarity as ssim """ This test suite compares images in 2 directories by file name The direc...
from copy import deepcopy from io import BytesIO from urllib import request import numpy import os from PIL import Image import pytest from pytest import fixture import time import torch from typing import Union import json import subprocess import websocket import uuid import urllib.request import urllib.parse from co...
{ "4": { "inputs": { "ckpt_name": "sd_xl_base_1.0.safetensors" }, "class_type": "CheckpointLoaderSimple" }, "5": { "inputs": { "width": 1024, "height": 1024, "batch_size": 1 }, "class_type": "EmptyLatentImage" }, "6": { "inputs": { "text": "a photo of a cat", "clip": [ "4", 1 ] }, "class_type": "CLIPTextEncode" }, "10"...
{ "presets": ["@babel/preset-env"], "plugins": ["babel-plugin-transform-import-meta"] }
{ "name": "comfui-tests", "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "comfui-tests", "version": "1.0.0", "license": "GPL-3.0", "devDependencies": { "@babel/preset-env": "^7.22.20", "@types/jest": "^29.5.5", "babel-plugin-transform-import-meta": "^2.2.1", "jest": "^29.7.0", "...
{ "name": "comfui-tests", "version": "1.0.0", "description": "UI tests", "main": "index.js", "scripts": { "test": "jest", "test:generate": "node setup.js" }, "repository": { "type": "git", "url": "git+https: }, "keywords": [ "comfyui", "test" ], "author": "comfyanonymous", "license": "GPL-3.0", "bugs": { "url": "https:...
{ "compilerOptions": { "baseUrl": ".", "paths": { "/*": ["./*"] }, "lib": ["DOM", "ES2022"] }, "include": ["."] }