Skip to content

Commit

Permalink
Merge pull request #201 from Haidra-Org/main
Browse files Browse the repository at this point in the history
feat:
  • Loading branch information
tazlin authored Feb 24, 2024
2 parents 406bf57 + f06072d commit 61cacbe
Show file tree
Hide file tree
Showing 20 changed files with 458 additions and 88 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/maintests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ on:
- '.github/workflows/prtests.yml'
- '.github/workflows/release.yml'
jobs:
build:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run pre-commit
uses: pre-commit/[email protected]

build:
runs-on: self-hosted
env:
HORDELIB_TESTING: "no-cuda"
HORDELIB_CI_ONGOING: "1"
TESTS_ONGOING: "1"
CIVIT_API_TOKEN: ${{ secrets.CIVIT_API_TOKEN }}
strategy:
Expand All @@ -33,8 +39,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade -r requirements.dev.txt
- name: Run lint/format/mypy check
run: tox -e pre-commit
- name: Check build_helper.py hordelib imports have no breaking dependency changes
run: tox -e test-build-helper
- name: Build unit test environment, confirm CUDA is available on host
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/prtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ on:
- '.github/workflows/prtests.yml'
- '.github/workflows/release.yml'
jobs:
build:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run pre-commit
uses: pre-commit/[email protected]

build:
runs-on: self-hosted
env:
HORDELIB_TESTING: "no-cuda"
HORDELIB_CI_ONGOING: "1"
TESTS_ONGOING: "1"
CIVIT_API_TOKEN: ${{ secrets.CIVIT_API_TOKEN }}
strategy:
Expand All @@ -38,8 +44,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install --upgrade -r requirements.dev.txt
- name: Run lint/format/mypy check
run: tox -e pre-commit
- name: Check build_helper.py hordelib imports have no breaking dependency changes
run: tox -e test-build-helper
- name: Build unit test environment, confirm CUDA is available on host
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.2.0
hooks:
- id: black
exclude: ^hordelib/nodes/.*\..*$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
rev: v0.2.2
hooks:
- id: ruff
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
3 changes: 1 addition & 2 deletions examples/run_memory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

hordelib.initialise(setup_logging=False)

from hordelib.comfy_horde import cleanup
from hordelib.horde import HordeLib
from hordelib.settings import UserSettings
from hordelib.shared_model_manager import SharedModelManager
Expand Down Expand Up @@ -155,7 +154,7 @@ def main():
model_index += 1
how_far -= 1
# That would have pushed something to disk, force a memory cleanup
cleanup()
# cleanup()
report_ram()

logger.warning("Loaded all models")
Expand Down
37 changes: 15 additions & 22 deletions hordelib/comfy_horde.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@


# isort: off
def do_comfy_import(force_normal_vram_mode: bool = False, extra_comfyui_args: list[str] | None = None) -> None:
def do_comfy_import(
force_normal_vram_mode: bool = False,
extra_comfyui_args: list[str] | None = None,
disable_smart_memory: bool = False,
) -> None:
global _comfy_current_loaded_models
global _comfy_load_models_gpu
global _comfy_nodes, _comfy_PromptExecutor, _comfy_validate_prompt
Expand All @@ -109,9 +113,9 @@ def do_comfy_import(force_normal_vram_mode: bool = False, extra_comfyui_args: li
global _comfy_free_memory, _comfy_cleanup_models, _comfy_soft_empty_cache
global _canny, _hed, _leres, _midas, _mlsd, _openpose, _pidinet, _uniformer

logger.info("Disabling smart memory")

sys.argv.append("--disable-smart-memory")
if disable_smart_memory:
logger.info("Disabling smart memory")
sys.argv.append("--disable-smart-memory")

if force_normal_vram_mode:
logger.info("Forcing normal vram mode")
Expand Down Expand Up @@ -222,8 +226,8 @@ def recursive_output_delete_if_changed_hijack(prompt: dict, old_prompt, outputs,
return _comfy_recursive_output_delete_if_changed(prompt, old_prompt, outputs, current_item)


def cleanup():
_comfy_soft_empty_cache()
# def cleanup():
# _comfy_soft_empty_cache()


def unload_all_models_vram():
Expand Down Expand Up @@ -271,17 +275,6 @@ def get_torch_free_vram_mb():
return round(_comfy_get_free_memory() / (1024 * 1024))


def garbage_collect():
logger.debug("Comfy_Horde garbage_collect called")
gc.collect()
if not torch.cuda.is_available():
logger.debug("CUDA not available, skipping cuda empty cache")
return
if torch.version.cuda:
torch.cuda.empty_cache()
torch.cuda.ipc_collect()


class Comfy_Horde:
"""Handles horde-specific behavior against ComfyUI."""

Expand Down Expand Up @@ -718,11 +711,11 @@ def _run_pipeline(self, pipeline: dict, params: dict) -> list[dict] | None:

stdio.replay()

# Check if there are any resource to clean up
cleanup()
if time.time() - self._gc_timer > Comfy_Horde.GC_TIME:
self._gc_timer = time.time()
garbage_collect()
# # Check if there are any resource to clean up
# cleanup()
# if time.time() - self._gc_timer > Comfy_Horde.GC_TIME:
# self._gc_timer = time.time()
# garbage_collect()

return self.images

Expand Down
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 = "18c151b3e3f6838fab4028e7a8ba526e30e610d3"
COMFYUI_VERSION = "f81dbe26e2e363c28ad043db67b59c11bb33f446"
"""The exact version of ComfyUI version to load."""

REMOTE_PROXY = ""
Expand Down
Loading

0 comments on commit 61cacbe

Please sign in to comment.