From 023468e25b2773161c459055a8913db0f378da19 Mon Sep 17 00:00:00 2001 From: Dowon Date: Sat, 15 Feb 2025 11:07:45 +0900 Subject: [PATCH 1/8] update versions --- .pre-commit-config.yaml | 4 ++-- install.py | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9979309..f975873 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,12 +19,12 @@ repos: - id: mixed-line-ending - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.4.1 + rev: v3.5.1 hooks: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.1 + rev: v0.9.6 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/install.py b/install.py index 1868c07..d9c7a8a 100644 --- a/install.py +++ b/install.py @@ -8,10 +8,6 @@ from importlib.metadata import version # python >= 3.8 from packaging.version import parse import_name = {"py-cpuinfo": "cpuinfo", "protobuf": "google.protobuf"} -custom_requirements = { - "ultralytics": "ultralytics>=8.3.0,!=8.3.41,!=8.3.42,!=8.3.45,!=8.3.46" -} -excluded_versions = {"ultralytics": ("8.3.41", "8.3.42", "8.3.45", "8.3.46")} def is_installed( @@ -20,7 +16,6 @@ def is_installed( max_version: str | None = None, ): name = import_name.get(package, package) - excluded = excluded_versions.get(package, ()) try: spec = importlib.util.find_spec(name) except ModuleNotFoundError: @@ -39,10 +34,7 @@ def is_installed( try: pkg_version = version(package) - return ( - parse(min_version) <= parse(pkg_version) <= parse(max_version) - and pkg_version not in excluded - ) + return parse(min_version) <= parse(pkg_version) <= parse(max_version) except Exception: return False @@ -54,7 +46,7 @@ def run_pip(*args): def install(): deps = [ # requirements - ("ultralytics", "8.3.0", None), + ("ultralytics", "8.3.75", None), ("mediapipe", "0.10.13", "0.10.15"), ("rich", "13.0.0", None), ] @@ -62,9 +54,7 @@ def install(): pkgs = [] for pkg, low, high in deps: if not is_installed(pkg, low, high): - if pkg in custom_requirements: - cmd = custom_requirements[pkg] - elif low and high: + if low and high: cmd = f"{pkg}>={low},<={high}" elif low: cmd = f"{pkg}>={low}" From 589412052dd504ffb38d1bd0ae403b92f7ec1464 Mon Sep 17 00:00:00 2001 From: Dowon Date: Sat, 15 Feb 2025 11:09:31 +0900 Subject: [PATCH 2/8] style: ignore A005 --- aaaaaa/traceback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aaaaaa/traceback.py b/aaaaaa/traceback.py index 4119a9b..85631e3 100644 --- a/aaaaaa/traceback.py +++ b/aaaaaa/traceback.py @@ -1,4 +1,4 @@ -from __future__ import annotations +from __future__ import annotations # noqa: A005 import io import platform From 06100063b3c0886d9c0bc416f79f29a59b46417e Mon Sep 17 00:00:00 2001 From: Dowon Date: Tue, 18 Feb 2025 20:18:42 +0900 Subject: [PATCH 3/8] feat: change unsafe pickling --- aaaaaa/helper.py | 13 ++++++++++++- scripts/!adetailer.py | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/aaaaaa/helper.py b/aaaaaa/helper.py index ae19003..db1a371 100644 --- a/aaaaaa/helper.py +++ b/aaaaaa/helper.py @@ -1,15 +1,17 @@ from __future__ import annotations +import os from contextlib import contextmanager from copy import copy from typing import TYPE_CHECKING, Any, Union +from unittest.mock import patch import torch from PIL import Image from typing_extensions import Protocol from modules import safe -from modules.shared import opts +from modules.shared import cmd_opts, opts if TYPE_CHECKING: # 타입 체커가 빨간 줄을 긋지 않게 하는 편법 @@ -36,6 +38,15 @@ def change_torch_load(): torch.load = orig +@contextmanager +def disable_safe_unpickle(): + with ( + patch.dict(os.environ, {"TORCH_FORCE_NO_WEIGHTS_ONLY_LOAD": "1"}, clear=False), + patch.object(cmd_opts, "disable_safe_unpickle", True), + ): + yield + + @contextmanager def pause_total_tqdm(): orig = opts.data.get("multiple_tqdm", True) diff --git a/scripts/!adetailer.py b/scripts/!adetailer.py index 406e1b5..1c032cb 100644 --- a/scripts/!adetailer.py +++ b/scripts/!adetailer.py @@ -18,8 +18,8 @@ import modules from aaaaaa.conditional import create_binary_mask, schedulers from aaaaaa.helper import ( PPImage, - change_torch_load, copy_extra_params, + disable_safe_unpickle, pause_total_tqdm, preserve_prompts, ) @@ -825,8 +825,8 @@ class AfterDetailerScript(scripts.Script): pred = mediapipe_predict(args.ad_model, pp.image, args.ad_confidence) else: - with change_torch_load(): - ad_model = self.get_ad_model(args.ad_model) + ad_model = self.get_ad_model(args.ad_model) + with disable_safe_unpickle(): pred = ultralytics_predict( ad_model, image=pp.image, From 941b7c7dfbd0fd1a061fd4a21a69c85e45858efc Mon Sep 17 00:00:00 2001 From: Dowon Date: Tue, 18 Feb 2025 23:01:44 +0900 Subject: [PATCH 4/8] fix: use mock.patch on total_tqdm patch --- aaaaaa/helper.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/aaaaaa/helper.py b/aaaaaa/helper.py index db1a371..a296cd1 100644 --- a/aaaaaa/helper.py +++ b/aaaaaa/helper.py @@ -49,12 +49,8 @@ def disable_safe_unpickle(): @contextmanager def pause_total_tqdm(): - orig = opts.data.get("multiple_tqdm", True) - try: - opts.data["multiple_tqdm"] = False + with patch.dict(opts.data, {"multiple_tqdm": False}, clear=False): yield - finally: - opts.data["multiple_tqdm"] = orig @contextmanager From 0ce0a2183b5244da6790f74305e757bef40fafef Mon Sep 17 00:00:00 2001 From: Dowon Date: Sat, 22 Feb 2025 10:01:28 +0900 Subject: [PATCH 5/8] chore: update tools --- .github/workflows/test.yml | 11 ++--------- .pre-commit-config.yaml | 2 +- Taskfile.yml | 5 ++--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b8be5e4..7383ad6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,16 +22,9 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: astral-sh/setup-uv@v5 with: python-version: ${{ matrix.python-version }} - - uses: astral-sh/setup-uv@v3 - - - name: Install dependencies - run: | - uv pip install --system ".[test]" - - name: Run tests - run: pytest -v + run: uv run --all-extras pytest -v diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f975873..ae1c46e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.6 + rev: v0.9.7 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/Taskfile.yml b/Taskfile.yml index bd3c8f1..494885f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -10,13 +10,12 @@ tasks: cmds: - echo "$PYTHON" - echo "$WEBUI" - - echo "$UV_PYTHON" silent: true launch: dir: "{{.WEBUI}}" cmds: - - "{{.PYTHON}} launch.py --xformers --api" + - "{{.PYTHON}} launch.py --xformers --api {{ .CLI_ARGS }}" silent: true lint: @@ -29,4 +28,4 @@ tasks: update-torch: cmds: - - "{{.PYTHON}} -m uv pip install -U torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu124" + - "{{.PYTHON}} -m uv pip install -U torch torchvision torchaudio xformers --extra-index-url https://download.pytorch.org/whl/cu126" From d9250a3d9abd7bf2e8047bf37c54623bc93911fd Mon Sep 17 00:00:00 2001 From: Dowon Date: Sat, 22 Feb 2025 10:01:42 +0900 Subject: [PATCH 6/8] fix: misc --- adetailer/common.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/adetailer/common.py b/adetailer/common.py index 4d1fdcc..9fb5e45 100644 --- a/adetailer/common.py +++ b/adetailer/common.py @@ -39,8 +39,9 @@ def hf_download(file: str, repo_id: str = REPO_ID, check_remote: bool = True) -> with suppress(Exception): return hf_hub_download(repo_id, file, local_files_only=True) - msg = f"[-] ADetailer: Failed to load model {file!r} from huggingface" - print(msg) + if check_remote: + msg = f"[-] ADetailer: Failed to load model {file!r} from huggingface" + print(msg) return "INVALID" From 408f1fbccbcce973c061e26209ae2b8f622b5db4 Mon Sep 17 00:00:00 2001 From: Dowon Date: Mon, 10 Mar 2025 20:35:38 +0900 Subject: [PATCH 7/8] chore: v25.3.0 --- CHANGELOG.md | 5 +++++ adetailer/__version__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07d0f66..a805d31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 2025-03-10 + +- v25.3.0 +- unsafe pickling 방법 변경 + ## 2024-11-13 - v24.11.1 diff --git a/adetailer/__version__.py b/adetailer/__version__.py index 891aa8c..d024107 100644 --- a/adetailer/__version__.py +++ b/adetailer/__version__.py @@ -1 +1 @@ -__version__ = "24.11.1" +__version__ = "25.3.0" From e6098dd2dd9f993654d160b62380406526efc9ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 20:36:34 +0900 Subject: [PATCH 8/8] [pre-commit.ci] pre-commit autoupdate (#753) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/rbubley/mirrors-prettier: v3.5.1 → v3.5.3](https://github.com/rbubley/mirrors-prettier/compare/v3.5.1...v3.5.3) - [github.com/astral-sh/ruff-pre-commit: v0.9.6 → v0.9.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.6...v0.9.9) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dowon --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ae1c46e..0413861 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,12 +19,12 @@ repos: - id: mixed-line-ending - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.5.1 + rev: v3.5.3 hooks: - id: prettier - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.7 + rev: v0.9.9 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix]