Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: latest comfyui, intial pyinstaller support #182

Merged
merged 8 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.1.1
hooks:
- id: black
exclude: ^hordelib/nodes/.*\..*$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.2.1
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.8.0'
hooks:
- id: mypy
exclude: ^examples/.*$ # FIXME
additional_dependencies: [pydantic, strenum, types-colorama, types-docutils, types-Pillow, types-psutil, types-Pygments, types-pywin32, types-PyYAML, types-regex, types-requests, types-setuptools, types-tabulate, types-tqdm, types-urllib3]
additional_dependencies: [pydantic, strenum, types-colorama, types-docutils, types-Pillow, types-psutil, types-Pygments, types-pywin32, types-PyYAML, types-regex, types-requests, types-setuptools, types-tabulate, types-tqdm, types-urllib3, horde_sdk]
10 changes: 10 additions & 0 deletions hordelib/__pyinstaller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pathlib


def get_hook_dirs() -> list[str]:
return [str(pathlib.Path(__file__).parent / "pyinstaller_hooks")]


def get_PyInstaller_tests() -> list[str]:
return [] # FIXME
return [str(pathlib.Path(__file__).parent / "pyinstaller_tests")]
2 changes: 1 addition & 1 deletion hordelib/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from hordelib.config_path import get_hordelib_path

COMFYUI_VERSION = "b4e915e74560bd2c090f9b4ed6b73b0781b7050e"
COMFYUI_VERSION = "c5a369a33ddb622827552716d9b0119035a2e666"
"""The exact version of ComfyUI version to load."""

REMOTE_PROXY = ""
Expand Down
25 changes: 14 additions & 11 deletions hordelib/model_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,17 +498,20 @@ def download_file(
response.raise_for_status()

# Write the content to file in chunks
with open(partial_pathname, "ab") as f, tqdm(
# all optional kwargs
unit="B",
initial=partial_size,
unit_scale=True,
unit_divisor=1024,
miniters=1,
desc=filename,
total=remote_file_size + partial_size,
# disable=UserSettings.download_progress_callback is not None,
) as pbar:
with (
open(partial_pathname, "ab") as f,
tqdm(
# all optional kwargs
unit="B",
initial=partial_size,
unit_scale=True,
unit_divisor=1024,
miniters=1,
desc=filename,
total=remote_file_size + partial_size,
# disable=UserSettings.download_progress_callback is not None,
) as pbar,
):
downloaded = partial_size
for chunk in response.iter_content(chunk_size=1024 * 1024 * 16):
response.raise_for_status()
Expand Down
7 changes: 4 additions & 3 deletions hordelib/model_manager/hyper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Home for the controller class ModelManager, and related meta information."""

import os
import threading
from collections.abc import Callable, Iterable
Expand Down Expand Up @@ -180,9 +181,9 @@ def init_model_managers(
self.active_model_managers.append(
resolve_manager_to_load_type(
multiprocessing_lock=multiprocessing_lock,
civitai_api_token=os.environ["CIVIT_API_TOKEN"]
if "CIVIT_API_TOKEN" in os.environ.keys()
else None,
civitai_api_token=(
os.environ["CIVIT_API_TOKEN"] if "CIVIT_API_TOKEN" in os.environ.keys() else None
),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def __init__(self):
)
modelpath = os.path.join(builtins.annotator_ckpts_path, "network-bsds500.pth")
if not os.path.exists(modelpath):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(remote_model_path, model_dir=builtins.annotator_ckpts_path)
self.netNetwork = Network(modelpath).to(model_management.get_torch_device()).eval()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def download_model_if_not_existed():
# if os.path.exists(old_model_path):
# model_path = old_model_path
if not os.path.exists(model_path):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(remote_model_path_leres, model_dir=builtins.annotator_ckpts_path)
os.rename(os.path.join(builtins.annotator_ckpts_path, "res101.pth"), model_path)
Expand All @@ -66,7 +66,7 @@ def apply_leres(input_image, thr_a, thr_b):
""" if boost and pix2pixmodel is None:
pix2pixmodel_path = os.path.join(builtins.annotator_ckpts_path, "latest_net_G.pth")
if not os.path.exists(pix2pixmodel_path):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url
load_file_from_url(remote_model_path_pix2pix, model_dir=builtins.annotator_ckpts_path)
opt = TestOptions().parse()
Expand All @@ -84,7 +84,6 @@ def apply_leres(input_image, thr_a, thr_b):
height, width, dim = input_image.shape

with torch.no_grad():

if boost:
depth = estimateboost(input_image, model, 0, pix2pixmodel, max(width, height))
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@ def get_func(func_name):
function in this module or the path to a function relative to the base
'modeling' module.
"""
if func_name == '':
if func_name == "":
return None
try:
parts = func_name.split('.')
parts = func_name.split(".")
# Refers to a function in this module
if len(parts) == 1:
return globals()[parts[0]]
# Otherwise, assume we're referencing a module under modeling
module_name = 'comfy_controlnet_preprocessors.leres.leres.' + '.'.join(parts[:-1])
module_name = "hordelib.nodes.comfy_controlnet_preprocessors.leres.leres." + ".".join(parts[:-1])
module = importlib.import_module(module_name)
return getattr(module, parts[-1])
except Exception:
print('Failed to f1ind function: %s', func_name)
print("Failed to f1ind function: %s", func_name)
raise


def load_ckpt(args, depth_model, shift_model, focal_model):
"""
Load checkpoint.
Expand All @@ -32,13 +33,10 @@ def load_ckpt(args, depth_model, shift_model, focal_model):
print("loading checkpoint %s" % args.load_ckpt)
checkpoint = torch.load(args.load_ckpt)
if shift_model is not None:
shift_model.load_state_dict(strip_prefix_if_present(checkpoint['shift_model'], 'module.'),
strict=True)
shift_model.load_state_dict(strip_prefix_if_present(checkpoint["shift_model"], "module."), strict=True)
if focal_model is not None:
focal_model.load_state_dict(strip_prefix_if_present(checkpoint['focal_model'], 'module.'),
strict=True)
depth_model.load_state_dict(strip_prefix_if_present(checkpoint['depth_model'], "module."),
strict=True)
focal_model.load_state_dict(strip_prefix_if_present(checkpoint["focal_model"], "module."), strict=True)
depth_model.load_state_dict(strip_prefix_if_present(checkpoint["depth_model"], "module."), strict=True)
del checkpoint
torch.cuda.empty_cache()

Expand Down
2 changes: 1 addition & 1 deletion hordelib/nodes/comfy_controlnet_preprocessors/midas/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def load_model(model_type):

elif model_type == "dpt_hybrid": # DPT-Hybrid
if not os.path.exists(model_path):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(remote_model_path, model_dir=builtins.annotator_ckpts_path)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MLSDdetector:
def __init__(self):
model_path = os.path.join(builtins.annotator_ckpts_path, "mlsd_large_512_fp32.pth")
if not os.path.exists(model_path):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(remote_model_path, model_dir=builtins.annotator_ckpts_path)
model = MobileV2_MLSD_Large()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self):
hand_modelpath = os.path.join(builtins.annotator_ckpts_path, "hand_pose_model.pth")

if not os.path.exists(hand_modelpath):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(body_model_path, model_dir=builtins.annotator_ckpts_path)
load_file_from_url(hand_model_path, model_dir=builtins.annotator_ckpts_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from einops import rearrange
from .model import pidinet
from comfy_controlnet_preprocessors.util import load_state_dict, load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_state_dict, load_file_from_url
import builtins
import model_management

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

from comfy_controlnet_preprocessors.uniformer.mmseg.apis import init_segmentor, inference_segmentor, show_result_pyplot
from comfy_controlnet_preprocessors.uniformer.mmseg.core.evaluation import get_palette
from hordelib.nodes.comfy_controlnet_preprocessors.uniformer.mmseg.apis import (
init_segmentor,
inference_segmentor,
show_result_pyplot,
)
from hordelib.nodes.comfy_controlnet_preprocessors.uniformer.mmseg.core.evaluation import get_palette
import builtins

import model_management
Expand All @@ -14,7 +18,7 @@ class UniformerDetector:
def __init__(self):
modelpath = os.path.join(builtins.annotator_ckpts_path, "upernet_global_small.pth")
if not os.path.exists(modelpath):
from comfy_controlnet_preprocessors.util import load_file_from_url
from hordelib.nodes.comfy_controlnet_preprocessors.util import load_file_from_url

load_file_from_url(checkpoint_file, model_dir=builtins.annotator_ckpts_path)
config_file = os.path.join(os.path.dirname(__file__), "exp", "upernet_global_small", "config.py")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import torch.nn as nn
import torch.nn.functional as F

from comfy_controlnet_preprocessors.uniformer.mmcv.utils import TORCH_VERSION, build_from_cfg, digit_version
from hordelib.nodes.comfy_controlnet_preprocessors.uniformer.mmcv.utils import (
TORCH_VERSION,
build_from_cfg,
digit_version,
)
from .registry import ACTIVATION_LAYERS

for module in [
nn.ReLU, nn.LeakyReLU, nn.PReLU, nn.RReLU, nn.ReLU6, nn.ELU,
nn.Sigmoid, nn.Tanh
]:
for module in [nn.ReLU, nn.LeakyReLU, nn.PReLU, nn.RReLU, nn.ReLU6, nn.ELU, nn.Sigmoid, nn.Tanh]:
ACTIVATION_LAYERS.register_module(module=module)


@ACTIVATION_LAYERS.register_module(name='Clip')
@ACTIVATION_LAYERS.register_module(name="Clip")
@ACTIVATION_LAYERS.register_module()
class Clamp(nn.Module):
"""Clamp activation layer.
Expand All @@ -28,7 +29,7 @@ class Clamp(nn.Module):
Default to 1.
"""

def __init__(self, min=-1., max=1.):
def __init__(self, min=-1.0, max=1.0):
super(Clamp, self).__init__()
self.min = min
self.max = max
Expand Down Expand Up @@ -71,8 +72,7 @@ def forward(self, input):
return F.gelu(input)


if (TORCH_VERSION == 'parrots'
or digit_version(TORCH_VERSION) < digit_version('1.4')):
if TORCH_VERSION == "parrots" or digit_version(TORCH_VERSION) < digit_version("1.4"):
ACTIVATION_LAYERS.register_module(module=GELU)
else:
ACTIVATION_LAYERS.register_module(module=nn.GELU)
Expand Down
Loading
Loading