From 4c7792ed011b233cdb6e9e42327085f4d66701f2 Mon Sep 17 00:00:00 2001 From: Hameer Abbasi Date: Mon, 21 Aug 2023 10:23:08 +0000 Subject: [PATCH] Add pre-commit. --- .git-blame-ignore-revs | 1 + .github/workflows/on_pull_request.yaml | 15 ++--- .gitignore | 1 + .gitmodules | 2 +- .markdownlint.json | 2 +- .pre-commit-config.yaml | 66 +++++++++++++++++++ README.md | 32 +++++++++ configs/alt-diffusion-inference.yaml | 2 +- configs/v2-inference-768-v.yaml | 2 +- html/licenses.html | 2 +- javascript/amethyst-nightfall.css | 3 +- javascript/black-orange.css | 4 +- javascript/panZoom.js | 16 ++--- modules/dml/__init__.py | 2 +- modules/dml/memory_amd/driver/atiadlxx.py | 2 +- .../dml/memory_amd/driver/atiadlxx_defines.py | 2 +- .../memory_amd/driver/atiadlxx_structures.py | 2 +- modules/sd_hijack_utils.py | 20 +++--- modules/textual_inversion/learn_schedule.py | 3 +- train/templates/style.txt | 2 +- train/templates/style_filewords.txt | 2 +- train/templates/subject.txt | 2 +- train/templates/subject_filewords.txt | 2 +- train/templates/unknown.txt | 2 +- train/templates/unknown_filewords.txt | 2 +- 25 files changed, 144 insertions(+), 47 deletions(-) create mode 100644 .git-blame-ignore-revs create mode 100644 .pre-commit-config.yaml diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..4331ab5b3 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1 @@ +522dc5b4ff2a61e576aa9fb4ac3ab9274d4f26dd diff --git a/.github/workflows/on_pull_request.yaml b/.github/workflows/on_pull_request.yaml index 5805f7669..21063f7d0 100644 --- a/.github/workflows/on_pull_request.yaml +++ b/.github/workflows/on_pull_request.yaml @@ -16,16 +16,15 @@ jobs: python-version: 3.10.6 cache: pip cache-dependency-path: requirements.txt - - name: run-ruff + - name: install-pylint run: | python -m pip install --upgrade pip - pip install ruff - ruff . - # - name: run-pylint - # run: | - # python -m pip install --upgrade pip - # pip install pylint - # pylint $(git ls-files '*.py') + pip install pylint + - name: pre-commit + uses: pre-commit-ci/lite-action@v1.0.1 + if: always() + with: + msg: apply code formatting and linting auto-fixes - name: test-startup run: | export COMMANDLINE_ARGS="--debug --test" diff --git a/.gitignore b/.gitignore index ef9015660..bde1bf3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ package-lock.json venv .history cache +**/.DS_Store # all models and temp files *.log diff --git a/.gitmodules b/.gitmodules index a4cf860dc..8eecc252a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -33,7 +33,7 @@ url = https://github.com/KohakuBlueleaf/a1111-sd-webui-lycoris ignore = dirty [submodule "extensions-builtin/multidiffusion-upscaler-for-automatic1111"] - path = extensions-builtin/multidiffusion-upscaler-for-automatic1111 + path = extensions-builtin/multidiffusion-upscaler-for-automatic1111 url = https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111 ignore = dirty [submodule "extensions-builtin/sd-webui-agent-scheduler"] diff --git a/.markdownlint.json b/.markdownlint.json index e07c835be..bf0052c11 100644 --- a/.markdownlint.json +++ b/.markdownlint.json @@ -6,4 +6,4 @@ "MD033": false, "MD036": false, "MD041": false -} \ No newline at end of file +} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..7bb4cce9e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,66 @@ +# To use: +# +# pre-commit run -a +# +# Or: +# +# pre-commit install # (runs every time you commit in git) +# +# To update this file: +# +# pre-commit autoupdate +# +# See https://github.com/pre-commit/pre-commit + +ci: + autoupdate_commit_msg: "chore: update pre-commit hooks" + autofix_commit_msg: "style: pre-commit fixes" + +repos: +# Standard hooks +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + args: ["--allow-multiple-documents"] + - id: debug-statements + - id: end-of-file-fixer + - id: mixed-line-ending + - id: trailing-whitespace + exclude: | + (?x)^( + .*\.md| + .github/ISSUE_TEMPLATE/.*\.yml + )$ + +- repo: https://github.com/charliermarsh/ruff-pre-commit + rev: 'v0.0.285' + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: [] + +# Black, the code formatter, natively supports pre-commit +# - repo: https://github.com/psf/black +# rev: 23.7.0 +# hooks: +# - id: black +# exclude: ^(docs) + +# Changes tabs to spaces +# - repo: https://github.com/Lucas-C/pre-commit-hooks +# rev: v1.5.3 +# hooks: +# - id: remove-tabs +# exclude: ^(docs) diff --git a/README.md b/README.md index d2bccd752..af96e2241 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ All Individual features are not listed here, instead check [ChangeLog](CHANGELOG Including built-in support for `torch.compile` - Support for multiple backends! **original** and **diffusers** +<<<<<<< HEAD +<<<<<<< HEAD - Support for multiple diffusion models! Stable Diffusion, SD-XL, Kandinsky, DeepFloyd IF, etc. - Fully multiplatform with platform specific autodetection and tuning performed on install @@ -39,6 +41,36 @@ All Individual features are not listed here, instead check [ChangeLog](CHANGELOG - Broad compatibility with existing extensions ecosystem and new extensions manager - Built in installer with automatic updates and dependency management - Modernized UI (still based on Gradio) with theme support +======= +- Support for multiple diffusion models! + Stable Diffusion, SD-XL, Kandinsky, DeepFloyd IF, etc. +- Fully multiplatform with platform specific autodetection and tuning performed on install + Windows / Linux / MacOS with CPU / nVidia / AMD / IntelArc / DirectML +- Improved prompt parser +- Enhanced *Lora*/*Locon*/*Lyco* code supporting latest trends in training +- Built-in queue management +- Advanced metadata caching and handling to speed up operations +- Enterprise level logging and hardened API +- Modern localization and hints engine +- Broad compatibility with existing extensions ecosystem and new extensions manager +- Built in installer with automatic updates and dependency management +- Modernized UI (still based on Gradio) with theme support +>>>>>>> 26aee894 (Add pre-commit.) +======= +- Support for multiple diffusion models! + Stable Diffusion, SD-XL, Kandinsky, DeepFloyd IF, etc. +- Fully multiplatform with platform specific autodetection and tuning performed on install + Windows / Linux / MacOS with CPU / nVidia / AMD / Intel / DirectML +- Improved prompt parser +- Enhanced *Lora*/*Locon*/*Lyco* code supporting latest trends in training +- Built-in queue management +- Advanced metadata caching and handling to speed up operations +- Enterprise level logging and hardened API +- Modern localization and hints engine +- Broad compatibility with existing extensions ecosystem and new extensions manager +- Built in installer with automatic updates and dependency management +- Modernized UI (still based on Gradio) with theme support +>>>>>>> 75d5f19f (Exclude *.md from trailing-whitespace hook.) ## Backend support diff --git a/configs/alt-diffusion-inference.yaml b/configs/alt-diffusion-inference.yaml index cfbee72d7..e145ea4e5 100644 --- a/configs/alt-diffusion-inference.yaml +++ b/configs/alt-diffusion-inference.yaml @@ -69,4 +69,4 @@ model: cond_stage_config: target: modules.xlmr.BertSeriesModelWithTransformation params: - name: "XLMR-Large" \ No newline at end of file + name: "XLMR-Large" diff --git a/configs/v2-inference-768-v.yaml b/configs/v2-inference-768-v.yaml index 513cd635c..8ec8dfbfe 100644 --- a/configs/v2-inference-768-v.yaml +++ b/configs/v2-inference-768-v.yaml @@ -65,4 +65,4 @@ model: target: ldm.modules.encoders.modules.FrozenOpenCLIPEmbedder params: freeze: True - layer: "penultimate" \ No newline at end of file + layer: "penultimate" diff --git a/html/licenses.html b/html/licenses.html index ef6f2c0a4..2ad803052 100644 --- a/html/licenses.html +++ b/html/licenses.html @@ -687,4 +687,4 @@

TAESD \ No newline at end of file + diff --git a/javascript/amethyst-nightfall.css b/javascript/amethyst-nightfall.css index e209356c7..260d05423 100644 --- a/javascript/amethyst-nightfall.css +++ b/javascript/amethyst-nightfall.css @@ -119,7 +119,7 @@ svg.feather.feather-image, .feather .feather-image { display: none } #txt2img_subseed_strength { margin-top: 0; } #pnginfo_html2_info { margin-top: -18px; background-color: var(--input-background-fill); padding: var(--input-padding) } #txt2img_tools > div > button, #img2img_tools > div > button { filter: hue-rotate(180deg) saturate(0.5); } -#txt2img_tools, #img2img_tools { margin-top: -4px; margin-bottom: -4px; } +#txt2img_tools, #img2img_tools { margin-top: -4px; margin-bottom: -4px; } #txt2img_styles_row { margin-top: -6px; } /* custom elements overrides */ @@ -322,4 +322,3 @@ svg.feather.feather-image, .feather .feather-image { display: none } --size-9: 64px; --size-14: 64px; } - diff --git a/javascript/black-orange.css b/javascript/black-orange.css index dc9d99871..36504c288 100644 --- a/javascript/black-orange.css +++ b/javascript/black-orange.css @@ -114,8 +114,8 @@ svg.feather.feather-image, .feather .feather-image { display: none } #txt2img_settings { min-width: var(--left-column); max-width: var(--left-column); background-color: #111111; padding-top: 16px; } #pnginfo_html2_info { margin-top: -18px; background-color: var(--input-background-fill); padding: var(--input-padding) } #txt2img_tools > div > button, #img2img_tools > div > button { filter: hue-rotate(180deg) saturate(0.5); } -#txt2img_tools, #img2img_tools { margin-top: -4px; margin-bottom: -4px; } -#txt2img_styles_row, #img2img_styles_row { margin-top: -6px; } +#txt2img_tools, #img2img_tools { margin-top: -4px; margin-bottom: -4px; } +#txt2img_styles_row { margin-top: -6px; } /* custom elements overrides */ #steps-animation, #controlnet { border-width: 0; } diff --git a/javascript/panZoom.js b/javascript/panZoom.js index 66dd3e92a..a17751fce 100644 --- a/javascript/panZoom.js +++ b/javascript/panZoom.js @@ -113,7 +113,7 @@ function createPanZoom(domElement, options) { dispose: dispose, moveBy: internalMoveBy, moveTo: moveTo, - smoothMoveTo: smoothMoveTo, + smoothMoveTo: smoothMoveTo, centerOn: centerOn, zoomTo: publicZoomTo, zoomAbs: zoomAbs, @@ -141,7 +141,7 @@ function createPanZoom(domElement, options) { }; eventify(api); - + var initialX = typeof options.initialX === 'number' ? options.initialX : transform.x; var initialY = typeof options.initialY === 'number' ? options.initialY : transform.y; var initialZoom = typeof options.initialZoom === 'number' ? options.initialZoom : transform.scale; @@ -1049,7 +1049,7 @@ function autoRun() { } autoRun(); - + },{"./lib/createTextSelectionInterceptor.js":2,"./lib/domController.js":3,"./lib/kinetic.js":4,"./lib/svgController.js":5,"./lib/transform.js":6,"amator":7,"ngraph.events":9,"wheel":10}],2:[function(require,module,exports){ /** * Disallows selecting text. @@ -1087,7 +1087,7 @@ function createTextSelectionInterceptor(useFake) { function release() { if (!wasCaptured) return; - + wasCaptured = false; window.document.onselectstart = prevSelectStart; if (dragObject) dragObject.ondragstart = prevDragStart; @@ -1107,14 +1107,14 @@ module.exports = makeDomController module.exports.canAttach = isDomElement; function makeDomController(domElement, options) { - var elementValid = isDomElement(domElement); + var elementValid = isDomElement(domElement); if (!elementValid) { throw new Error('panzoom requires DOM element to be attached to the DOM tree') } var owner = domElement.parentElement; domElement.scrollTop = 0; - + if (!options.disableKeyboardInteraction) { owner.setAttribute('tabindex', 0); } @@ -1124,7 +1124,7 @@ function makeDomController(domElement, options) { getOwner: getOwner, applyTransform: applyTransform, } - + return api function getOwner() { @@ -1320,7 +1320,7 @@ function makeSvgController(svgElement, options) { applyTransform: applyTransform, initTransform: initTransform } - + return api function getOwner() { diff --git a/modules/dml/__init__.py b/modules/dml/__init__.py index a36af5da3..724fec9c5 100644 --- a/modules/dml/__init__.py +++ b/modules/dml/__init__.py @@ -95,7 +95,7 @@ def directml_override_opts(): if item.message is not None: shared.log.warning(item.message) shared.log.warning(f'{key} is automatically overriden to {item.value}.') - + if count > 0: shared.log.info(f'{count} options are automatically overriden. If you want to keep them from overriding, run with --experimental argument.') diff --git a/modules/dml/memory_amd/driver/atiadlxx.py b/modules/dml/memory_amd/driver/atiadlxx.py index 81a578a5c..e0b602e28 100644 --- a/modules/dml/memory_amd/driver/atiadlxx.py +++ b/modules/dml/memory_amd/driver/atiadlxx.py @@ -26,7 +26,7 @@ def get_memory_info2(self, adapterIndex: int) -> ADLMemoryInfo2: if ADL2_Adapter_MemoryInfo2_Get(self.context, adapterIndex, C.byref(info)) != ADL_OK: raise RuntimeError("ADL2: Failed to get MemoryInfo2") - + return info def get_dedicated_vram_usage(self, index: int) -> int: diff --git a/modules/dml/memory_amd/driver/atiadlxx_defines.py b/modules/dml/memory_amd/driver/atiadlxx_defines.py index c242b9819..fc1c9d4cb 100644 --- a/modules/dml/memory_amd/driver/atiadlxx_defines.py +++ b/modules/dml/memory_amd/driver/atiadlxx_defines.py @@ -1 +1 @@ -ADL_OK = 0 \ No newline at end of file +ADL_OK = 0 diff --git a/modules/dml/memory_amd/driver/atiadlxx_structures.py b/modules/dml/memory_amd/driver/atiadlxx_structures.py index a68392ec4..c0443592d 100644 --- a/modules/dml/memory_amd/driver/atiadlxx_structures.py +++ b/modules/dml/memory_amd/driver/atiadlxx_structures.py @@ -84,4 +84,4 @@ class _AdapterInfo(C.Structure): AdapterInfo = _AdapterInfo LPAdapterInfo = C.POINTER(_AdapterInfo) -ADL_CONTEXT_HANDLE = C.c_void_p \ No newline at end of file +ADL_CONTEXT_HANDLE = C.c_void_p diff --git a/modules/sd_hijack_utils.py b/modules/sd_hijack_utils.py index f8684475e..d281be635 100644 --- a/modules/sd_hijack_utils.py +++ b/modules/sd_hijack_utils.py @@ -16,13 +16,13 @@ def __new__(cls, orig_func, sub_func, cond_func): orig_func = getattr(resolved_obj, func_path[-1]) setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs)) self.__init__(orig_func, sub_func, cond_func) - return lambda *args, **kwargs: self(*args, **kwargs) - def __init__(self, orig_func, sub_func, cond_func): - self.__orig_func = orig_func - self.__sub_func = sub_func - self.__cond_func = cond_func - def __call__(self, *args, **kwargs): - if not self.__cond_func or self.__cond_func(self.__orig_func, *args, **kwargs): - return self.__sub_func(self.__orig_func, *args, **kwargs) - else: - return self.__orig_func(*args, **kwargs) + return lambda *args, **kwargs: self(*args, **kwargs) + def __init__(self, orig_func, sub_func, cond_func): + self.__orig_func = orig_func + self.__sub_func = sub_func + self.__cond_func = cond_func + def __call__(self, *args, **kwargs): + if not self.__cond_func or self.__cond_func(self.__orig_func, *args, **kwargs): + return self.__sub_func(self.__orig_func, *args, **kwargs) + else: + return self.__orig_func(*args, **kwargs) diff --git a/modules/textual_inversion/learn_schedule.py b/modules/textual_inversion/learn_schedule.py index e1a7f3db6..f12a62824 100644 --- a/modules/textual_inversion/learn_schedule.py +++ b/modules/textual_inversion/learn_schedule.py @@ -30,7 +30,7 @@ def __init__(self, learn_rate, max_steps, cur_step=0): return assert self.rates except (ValueError, AssertionError) as e: - raise Exception('Invalid learning rate schedule. It should be a number or, for example, like "0.001:100, 0.00001:1000, 1e-5:10000" to have lr of 0.001 until step 100, 0.00001 until 1000, and 1e-5 until 10000.') from e + raise RuntimeError('Invalid learning rate schedule. It should be a number or, for example, like "0.001:100, 0.00001:1000, 1e-5:10000" to have lr of 0.001 until step 100, 0.00001 until 1000, and 1e-5 until 10000.') from e def __iter__(self): @@ -75,4 +75,3 @@ def apply(self, optimizer, step_number): for pg in optimizer.param_groups: pg['lr'] = self.learn_rate - diff --git a/train/templates/style.txt b/train/templates/style.txt index 50d710017..b6cd90b7d 100644 --- a/train/templates/style.txt +++ b/train/templates/style.txt @@ -1 +1 @@ -a painting, art by [name] \ No newline at end of file +a painting, art by [name] diff --git a/train/templates/style_filewords.txt b/train/templates/style_filewords.txt index fe817c6bb..2b73960fc 100644 --- a/train/templates/style_filewords.txt +++ b/train/templates/style_filewords.txt @@ -1 +1 @@ -photo of [filewords], art by [name] \ No newline at end of file +photo of [filewords], art by [name] diff --git a/train/templates/subject.txt b/train/templates/subject.txt index a90b6db4b..1c5a3ae93 100644 --- a/train/templates/subject.txt +++ b/train/templates/subject.txt @@ -1 +1 @@ -photo of [name] \ No newline at end of file +photo of [name] diff --git a/train/templates/subject_filewords.txt b/train/templates/subject_filewords.txt index 8bc59729c..be2cbdfe7 100644 --- a/train/templates/subject_filewords.txt +++ b/train/templates/subject_filewords.txt @@ -1 +1 @@ -photo of [name], [filewords] \ No newline at end of file +photo of [name], [filewords] diff --git a/train/templates/unknown.txt b/train/templates/unknown.txt index 43244ad6f..259b7ef34 100644 --- a/train/templates/unknown.txt +++ b/train/templates/unknown.txt @@ -1 +1 @@ -[name] \ No newline at end of file +[name] diff --git a/train/templates/unknown_filewords.txt b/train/templates/unknown_filewords.txt index 877ffae1b..43a4ef17a 100644 --- a/train/templates/unknown_filewords.txt +++ b/train/templates/unknown_filewords.txt @@ -1 +1 @@ -[name], [filewords] \ No newline at end of file +[name], [filewords]