IMMORTALJAY commited on
Commit
81ca5a9
1 Parent(s): adb4a08

Upload 8 files

Browse files
Files changed (8) hide show
  1. .gitignore +41 -0
  2. CONTRIBUTING.md +89 -0
  3. LICENSE +21 -0
  4. README.md +107 -12
  5. mkdocs.yml +104 -0
  6. pyproject.toml +172 -0
  7. requirements.docs.txt +2 -0
  8. requirements.lock +442 -0
.gitignore ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # compilation and distribution
2
+ __pycache__/
3
+ *.py[cod]
4
+ dist/
5
+
6
+ # virtual environments
7
+ venv/
8
+
9
+ # unit tests
10
+ .pytest_cache/
11
+
12
+ # tests' model weights
13
+ tests/weights/
14
+ tests/repos/
15
+ tests/datasets/
16
+
17
+ # ruff
18
+ .ruff_cache
19
+
20
+ # vscode
21
+ .vscode
22
+
23
+ # Weights & Biases (offline trainings)
24
+ wandb/
25
+
26
+ # macos
27
+ .DS_Store
28
+
29
+ # model weights
30
+ *.safetensors
31
+
32
+ # env variable definitions file
33
+ .env
34
+
35
+ # lock files
36
+ requirements-dev.lock
37
+
38
+ # coverage.py
39
+ htmlcov/
40
+ .coverage
41
+ .coverage.*
CONTRIBUTING.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ We are happy to accept contributions from everyone. Feel free to browse our [bounty list](https://www.finegrain.ai/bounties) to find a task you would like to work on.
2
+
3
+ This document describes the process for contributing to Refiners.
4
+
5
+ ## Licensing
6
+
7
+ Refiners is a library that is freely available to use and modify under the MIT License. It's essential to exercise caution when using external code, as any code that can affect the licensing of Refiners, including proprietary code, should not be copied and pasted. It's worth noting that some open-source licenses can also be problematic. For instance, we'd need to redistribute an Apache 2.0 license if you're using code from an Apache 2.0 codebase.
8
+
9
+ ## Design principles
10
+
11
+ We do not enforce strict rules on the design of the code, but we do have a few guidelines that we try to follow:
12
+
13
+ - No dead code. We keep the codebase clean and remove unnecessary code/functionality.
14
+ - No unnecessary dependencies. We keep the number of dependencies to a minimum and only add new ones if necessary.
15
+ - Separate concerns. We separate the code into different modules and avoid having too many dependencies between modules. In particular, we try not to revisit existing code/models when adding new functionality. Instead, we add new functionality in a separate module with the `Adapter` pattern.
16
+ - Declarative style. We make the code as declarative, self-documenting, and easily read as possible. By reading the model's `repr`, you should understand how it works. We use explicit names for the different components of the models or the variables in the code.
17
+
18
+ ## Setting up your environment
19
+
20
+ We use [Rye](https://rye-up.com/guide/installation/) to manage our development environment. Please follow the instructions on the Rye website to install it.
21
+
22
+ Once Rye is installed, you can clone the repository and run `rye sync` to install the dependencies.
23
+
24
+ ## Linting
25
+
26
+ We use the standard integration of [ruff](https://docs.astral.sh/ruff/) in Rye to lint and format our code. You can lint your code by running:
27
+
28
+ ```bash
29
+ rye fmt
30
+ rye lint --fix
31
+ ```
32
+
33
+ We also enforce strict type checking with [pyright](https://github.com/microsoft/pyright). You can run the type checker with:
34
+
35
+ ```bash
36
+ rye run pyright
37
+ ```
38
+
39
+ ## Running the tests
40
+
41
+ Running end-to-end tests is pretty compute-intensive, and you must convert all the model weights to the correct format before you can run them.
42
+
43
+ First, install test dependencies with:
44
+
45
+ ```bash
46
+ rye sync --all-features
47
+ ```
48
+
49
+ Then, download and convert all the necessary weights. Be aware that this will use around 100 GB of disk space:
50
+
51
+ ```bash
52
+ python scripts/prepare_test_weights.py
53
+ ```
54
+
55
+ Some tests require cloning the original implementation of the model as they use `torch.hub.load`:
56
+
57
+ ```bash
58
+ git clone [email protected]:facebookresearch/dinov2.git tests/repos/dinov2
59
+ ```
60
+
61
+ Finally, run the tests:
62
+
63
+ ```bash
64
+ rye run pytest
65
+ ```
66
+
67
+ The `-k` option is handy to run a subset of tests that match a given expression, e.g.:
68
+
69
+ ```bash
70
+ rye run pytest -k diffusion_std_init_image
71
+ ```
72
+
73
+ You can enforce running tests on CPU. Tests that require a GPU will be skipped.
74
+
75
+ ```bash
76
+ REFINERS_TEST_DEVICE=cpu rye run pytest
77
+ ```
78
+
79
+ You can collect [code coverage](https://github.com/nedbat/coveragepy) data while running tests with, e.g.:
80
+
81
+ ```bash
82
+ rye run test-cov
83
+ ```
84
+
85
+ Then, browse the corresponding HTML report with:
86
+
87
+ ```bash
88
+ rye run serve-cov-report
89
+ ```
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 to present Lagon Technologies and individual contributors.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,12 +1,107 @@
1
- ---
2
- title: Image Enhancer
3
- emoji: 🚀
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 4.44.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/finegrain-ai/refiners/main/assets/logo_dark.png">
5
+ <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/finegrain-ai/refiners/main/assets/logo_light.png">
6
+ <img alt="Finegrain Refiners Library" width="352" height="128" style="max-width: 100%;">
7
+ </picture>
8
+
9
+ **The simplest way to train and run adapters on top of foundation models**
10
+
11
+ [**Manifesto**](https://refine.rs/home/why/) |
12
+ [**Docs**](https://refine.rs) |
13
+ [**Guides**](https://refine.rs/guides/adapting_sdxl/) |
14
+ [**Discussions**](https://github.com/finegrain-ai/refiners/discussions) |
15
+ [**Discord**](https://discord.gg/mCmjNUVV7d)
16
+
17
+ ______________________________________________________________________
18
+
19
+ [![dependencies - Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://github.com/astral-sh/rye)
20
+ [![linting - Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
21
+ [![packaging - Hatch](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
22
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/refiners)](https://pypi.org/project/refiners/)
23
+ [![PyPI - Status](https://badge.fury.io/py/refiners.svg)](https://pypi.org/project/refiners/)
24
+ [![license](https://img.shields.io/badge/license-MIT-blue)](/LICENSE) \
25
+ [![code bounties](https://img.shields.io/badge/code-bounties-blue)](https://finegrain.ai/bounties)
26
+ [![Discord](https://img.shields.io/discord/1179456777406922913?logo=discord&logoColor=white&color=%235765F2)](https://discord.gg/mCmjNUVV7d)
27
+ [![HuggingFace - Refiners](https://img.shields.io/badge/refiners-ffd21e?logo=huggingface&labelColor=555)](https://huggingface.co/refiners)
28
+ [![HuggingFace - Finegrain](https://img.shields.io/badge/finegrain-ffd21e?logo=huggingface&labelColor=555)](https://huggingface.co/finegrain)
29
+ [![ComfyUI Registry](https://img.shields.io/badge/ComfyUI_Registry-comfyui--refiners-1a56db)](https://registry.comfy.org/publishers/finegrain/nodes/comfyui-refiners)
30
+
31
+ </div>
32
+
33
+ ## Latest News 🔥
34
+
35
+ - Added [ELLA](https://arxiv.org/abs/2403.05135) for better prompts handling (contributed by [@ily-R](https://github.com/ily-R))
36
+ - Added the Box Segmenter all-in-one solution ([model](https://huggingface.co/finegrain/finegrain-box-segmenter), [HF Space](https://huggingface.co/spaces/finegrain/finegrain-object-cutter))
37
+ - Added [MVANet](https://arxiv.org/abs/2404.07445) for high resolution segmentation
38
+ - Added [IC-Light](https://github.com/lllyasviel/IC-Light) to manipulate the illumination of images
39
+ - Added Multi Upscaler for high-resolution image generation, inspired from [Clarity Upscaler](https://github.com/philz1337x/clarity-upscaler) ([HF Space](https://huggingface.co/spaces/finegrain/enhancer))
40
+ - Added [HQ-SAM](https://arxiv.org/abs/2306.01567) for high quality mask prediction with Segment Anything
41
+ - Added [SDXL-Lightning](https://arxiv.org/abs/2402.13929)
42
+ - Added [Latent Consistency Models](https://arxiv.org/abs/2310.04378) and [LCM-LoRA](https://arxiv.org/abs/2311.05556) for Stable Diffusion XL
43
+ - Added [Style Aligned adapter](https://arxiv.org/abs/2312.02133) to Stable Diffusion models
44
+ - Added [ControlLoRA (v2) adapter](https://github.com/HighCWu/control-lora-v2) to Stable Diffusion XL
45
+ - Added [Euler's method](https://arxiv.org/abs/2206.00364) to solvers (contributed by [@israfelsr](https://github.com/israfelsr))
46
+ - Added [DINOv2](https://github.com/facebookresearch/dinov2) for high-performance visual features (contributed by [@Laurent2916](https://github.com/Laurent2916))
47
+ - Added [FreeU](https://github.com/ChenyangSi/FreeU) for improved quality at no cost (contributed by [@isamu-isozaki](https://github.com/isamu-isozaki))
48
+ - Added [Restart Sampling](https://github.com/Newbeeer/diffusion_restart_sampling) for improved image generation ([example](https://github.com/Newbeeer/diffusion_restart_sampling/issues/4))
49
+ - Added [Self-Attention Guidance](https://github.com/KU-CVLAB/Self-Attention-Guidance/) to avoid e.g. too smooth images ([example](https://github.com/SusungHong/Self-Attention-Guidance/issues/4))
50
+ - Added [T2I-Adapter](https://github.com/TencentARC/T2I-Adapter) for extra guidance ([example](https://github.com/TencentARC/T2I-Adapter/discussions/93))
51
+ - Added [MultiDiffusion](https://github.com/omerbt/MultiDiffusion) for e.g. panorama images
52
+ - Added [IP-Adapter](https://github.com/tencent-ailab/IP-Adapter), aka image prompt ([example](https://github.com/tencent-ailab/IP-Adapter/issues/92))
53
+ - Added [Segment Anything](https://github.com/facebookresearch/segment-anything) to foundation models
54
+ - Added [SDXL 1.0](https://github.com/Stability-AI/generative-models) to foundation models
55
+ - Made possible to add new concepts to the CLIP text encoder, e.g. via [Textual Inversion](https://arxiv.org/abs/2208.01618)
56
+
57
+ ## Installation
58
+
59
+ The current recommended way to install Refiners is from source using [Rye](https://rye-up.com/):
60
+
61
+ ```bash
62
+ git clone "[email protected]:finegrain-ai/refiners.git"
63
+ cd refiners
64
+ rye sync --all-features
65
+ ```
66
+
67
+ ## Documentation
68
+
69
+ Refiners comes with a MkDocs-based documentation website available at https://refine.rs. You will find there a [quick start guide](https://refine.rs/getting-started/recommended/), a description of the [key concepts](https://refine.rs/concepts/chain/), as well as in-depth foundation model adaptation [guides](https://refine.rs/guides/adapting_sdxl/).
70
+
71
+ ## Awesome Adaptation Papers
72
+
73
+ If you're interested in understanding the diversity of use cases for foundation model adaptation (potentially beyond the specific adapters supported by Refiners), we suggest you take a look at these outstanding papers:
74
+
75
+ - [ControlNet](https://arxiv.org/abs/2302.05543)
76
+ - [T2I-Adapter](https://arxiv.org/abs/2302.08453)
77
+ - [IP-Adapter](https://arxiv.org/abs/2308.06721)
78
+ - [Medical SAM Adapter](https://arxiv.org/abs/2304.12620)
79
+ - [3DSAM-adapter](https://arxiv.org/abs/2306.13465)
80
+ - [SAM-adapter](https://arxiv.org/abs/2304.09148)
81
+ - [Cross Modality Attention Adapter](https://arxiv.org/abs/2307.01124)
82
+ - [UniAdapter](https://arxiv.org/abs/2302.06605)
83
+
84
+ ## Projects using Refiners
85
+
86
+ - https://github.com/brycedrennan/imaginAIry
87
+
88
+ ## Credits
89
+
90
+ We took inspiration from these great projects:
91
+
92
+ - [tinygrad](https://github.com/tinygrad/tinygrad) - For something between PyTorch and [karpathy/micrograd](https://github.com/karpathy/micrograd)
93
+ - [Composer](https://github.com/mosaicml/composer) - A PyTorch Library for Efficient Neural Network Training
94
+ - [Keras](https://github.com/keras-team/keras) - Deep Learning for humans
95
+
96
+ ## Citation
97
+
98
+ ```bibtex
99
+ @misc{the-finegrain-team-2023-refiners,
100
+ author = {Benjamin Trom and Pierre Chapuis and Cédric Deltheil},
101
+ title = {Refiners: The simplest way to train and run adapters on top of foundation models},
102
+ year = {2023},
103
+ publisher = {GitHub},
104
+ journal = {GitHub repository},
105
+ howpublished = {\url{https://github.com/finegrain-ai/refiners}}
106
+ }
107
+ ```
mkdocs.yml ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ site_name: Refiners
2
+ site_description: A micro framework on top of PyTorch with first class citizen APIs for foundation model adaptation
3
+ repo_name: Refiners
4
+ repo_url: https://github.com/finegrain-ai/refiners
5
+ edit_uri: edit/main/docs/
6
+ copyright: © Lagon Technologies
7
+ theme:
8
+ favicon: assets/favicon.svg
9
+ logo: assets/favicon.svg
10
+ name: material
11
+ custom_dir: docs/overrides
12
+ palette:
13
+ primary: deep orange
14
+ accent: deep orange
15
+ features:
16
+ - navigation.tabs
17
+ - navigation.sections
18
+ - navigation.top
19
+ - navigation.tracking
20
+ - navigation.expand
21
+ - navigation.path
22
+ - toc.follow
23
+ - navigation.tabs.sticky
24
+ - content.code.copy
25
+ - announce.dismiss
26
+ plugins:
27
+ - search
28
+ - tags
29
+ - literate-nav:
30
+ nav_file: SUMMARY.md
31
+ - mkdocstrings:
32
+ handlers:
33
+ python:
34
+ import:
35
+ - https://docs.python.org/3/objects.inv
36
+ - https://pytorch.org/docs/master/objects.inv
37
+ - https://docs.kidger.site/jaxtyping/objects.inv
38
+ options:
39
+ show_bases: true
40
+ show_source: true
41
+ show_root_toc_entry: false
42
+ show_symbol_type_heading: true
43
+ show_symbol_type_toc: true
44
+ show_if_no_docstring: false
45
+ filters:
46
+ - "!^_"
47
+ docstring_options:
48
+ ignore_init_summary: true
49
+ merge_init_into_class: true
50
+ separate_signature: true
51
+ show_signature_annotations: true
52
+ signature_crossrefs: true
53
+ watch:
54
+ - src/refiners
55
+ extra_css:
56
+ - stylesheets/extra.css
57
+ nav:
58
+ - Home:
59
+ - Welcome: index.md
60
+ - Manifesto: home/why.md
61
+ - Getting started:
62
+ - getting-started/recommended.md
63
+ - getting-started/advanced.md
64
+ - Key Concepts:
65
+ - concepts/chain.md
66
+ - concepts/context.md
67
+ - concepts/adapter/index.md
68
+ - Guides:
69
+ - Adapting SDXL: guides/adapting_sdxl/index.md
70
+ - Training 101: guides/training_101/index.md
71
+ - API Reference:
72
+ - Refiners: reference/
73
+ extra:
74
+ social:
75
+ - icon: fontawesome/brands/discord
76
+ link: https://discord.gg/mCmjNUVV7d
77
+ - icon: fontawesome/brands/github
78
+ link: https://github.com/finegrain-ai/refiners
79
+ - icon: fontawesome/brands/twitter
80
+ link: https://twitter.com/finegrain_ai
81
+ - icon: fontawesome/brands/linkedin
82
+ link: https://www.linkedin.com/company/finegrain-ai/
83
+ markdown_extensions:
84
+ - admonition
85
+ - attr_list
86
+ - footnotes
87
+ - pymdownx.highlight:
88
+ anchor_linenums: true
89
+ line_spans: __span
90
+ pygments_lang_class: true
91
+ - pymdownx.inlinehilite
92
+ - pymdownx.snippets
93
+ - pymdownx.superfences
94
+ - pymdownx.details
95
+ - pymdownx.tabbed:
96
+ alternate_style: true
97
+ - pymdownx.emoji:
98
+ emoji_index: !!python/name:material.extensions.emoji.twemoji
99
+ emoji_generator: !!python/name:material.extensions.emoji.to_svg
100
+ - toc:
101
+ permalink: true
102
+ validation:
103
+ links:
104
+ absolute_links: info # use relative_to_docs when we switch to mkdocs 1.6
pyproject.toml ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "refiners"
3
+ dynamic = ["version"]
4
+ description = "The simplest way to train and run adapters on top of foundation models"
5
+ authors = [{ name = "The Finegrain Team", email = "[email protected]" }]
6
+ license = { text = "MIT License" }
7
+ dependencies = [
8
+ "torch>=2.1.1",
9
+ "safetensors>=0.4.5",
10
+ "pillow>=10.4.0",
11
+ "jaxtyping>=0.2.23",
12
+ "packaging>=23.2",
13
+ "numpy>=1.26.4",
14
+ ]
15
+ readme = "README.md"
16
+ requires-python = ">= 3.10"
17
+ classifiers = [
18
+ "Typing :: Typed",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: Science/Research",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Topic :: Software Development :: Libraries :: Python Modules",
24
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
25
+ "License :: OSI Approved :: MIT License",
26
+ ]
27
+
28
+ [project.urls]
29
+ source = "https://github.com/finegrain-ai/refiners"
30
+ documentation = "https://refine.rs/"
31
+
32
+ [project.optional-dependencies]
33
+ training = [
34
+ "bitsandbytes>=0.41.2.post2",
35
+ "pydantic>=2.5.2",
36
+ "prodigyopt>=1.0",
37
+ "torchvision>=0.16.1",
38
+ "loguru>=0.7.2",
39
+ "wandb>=0.16.0",
40
+ "neptune>=1.10.4",
41
+ "datasets>=2.15.0",
42
+ "tomli>=2.0.1",
43
+ "gitpython>=3.1.43",
44
+ ]
45
+ test = [
46
+ "diffusers>=0.26.1",
47
+ "transformers>=4.35.2",
48
+ "piq>=0.8.0",
49
+ "torchvision>=0.16.1",
50
+ # An unofficial Python package for Meta AI's Segment Anything Model:
51
+ # https://github.com/opengeos/segment-anything
52
+ "segment-anything-py>=1.0",
53
+ # Official Python package for HQ-SAM
54
+ "segment-anything-hq>=0.3",
55
+ # HQ-SAM missing dependency:
56
+ # https://github.com/SysCV/sam-hq/pull/59
57
+ "timm>=0.5.0",
58
+ "sentencepiece>=0.2.0",
59
+ ]
60
+ conversion = [
61
+ "diffusers>=0.26.1",
62
+ "transformers>=4.35.2",
63
+ "segment-anything-py>=1.0",
64
+ "requests>=2.26.0",
65
+ "tqdm>=4.62.3",
66
+ "gdown>=5.2.0",
67
+ ]
68
+ doc = [
69
+ # required by mkdocs to format the signatures
70
+ "black>=24.1.1",
71
+ "mkdocs-material>=9.5.6",
72
+ "mkdocstrings[python]>=0.24.0",
73
+ "mkdocs-literate-nav>=0.6.1",
74
+ ]
75
+ solutions = [
76
+ "huggingface-hub>=0.24.6",
77
+ ]
78
+
79
+ [build-system]
80
+ requires = ["hatchling", "hatch-vcs"]
81
+ build-backend = "hatchling.build"
82
+
83
+ [tool.hatch.version]
84
+ source = "vcs"
85
+ fallback-version = '0.0.0'
86
+
87
+ [tool.rye]
88
+ managed = true
89
+ dev-dependencies = [
90
+ "pyright==1.1.372",
91
+ "docformatter>=1.7.5",
92
+ "pytest>=8.0.0",
93
+ "coverage>=7.4.1",
94
+ "typos>=1.18.2",
95
+ "comfy-cli>=1.1.6",
96
+ ]
97
+
98
+
99
+ [tool.hatch.metadata]
100
+ allow-direct-references = true
101
+
102
+ [tool.rye.scripts]
103
+ serve-docs = "mkdocs serve"
104
+ test-cov = "coverage run -m pytest"
105
+ # Work around for "Couldn't parse" errors due to e.g. opencv-python:
106
+ # https://github.com/nedbat/coveragepy/issues/1653
107
+ build-html-cov = { cmd = "coverage html", env = { PYTHONWARNINGS = "ignore:Couldn't parse::coverage.report_core" } }
108
+ serve-cov-report = { chain = [
109
+ "build-html-cov",
110
+ "python -m http.server 8080 -b 127.0.0.1 -d htmlcov",
111
+ ] }
112
+
113
+ [tool.black]
114
+ line-length = 120
115
+
116
+ [tool.ruff]
117
+ src = ["src"] # see https://docs.astral.sh/ruff/settings/#src
118
+ line-length = 120
119
+
120
+ [tool.ruff.lint]
121
+ select = [
122
+ "I", # isort
123
+ ]
124
+ ignore = [
125
+ "F722", # forward-annotation-syntax-error, because of Jaxtyping
126
+ "E731", # do-not-assign-lambda
127
+ ]
128
+
129
+ [tool.ruff.lint.isort]
130
+ # Allow this kind of import on a single line:
131
+ #
132
+ # from torch import device as Device, dtype as DType
133
+ #
134
+ combine-as-imports = true
135
+
136
+ [tool.docformatter]
137
+ black = true
138
+
139
+ [tool.pyright]
140
+ include = ["src/refiners", "tests", "scripts"]
141
+ strict = ["*"]
142
+ exclude = ["**/__pycache__", "tests/weights"]
143
+ reportMissingTypeStubs = "warning"
144
+
145
+ [tool.coverage.run]
146
+ branch = true
147
+ source = ["src/refiners"]
148
+
149
+ # Also apply to HTML output, where appropriate
150
+ [tool.coverage.report]
151
+ ignore_errors = true # see `build-html-cov` for details
152
+ exclude_also = [
153
+ "def __repr__",
154
+ "raise NotImplementedError",
155
+ "if TYPE_CHECKING:",
156
+ "class .*\\bProtocol\\):",
157
+ "@(abc\\.)?abstractmethod",
158
+ ]
159
+
160
+ [tool.typos.default]
161
+ extend-ignore-identifiers-re = ["NDArray*", "interm", "af000ded"]
162
+
163
+ [tool.typos.default.extend-words]
164
+ adaptee = "adaptee" # Common name for an adapter's target
165
+
166
+ [tool.pytest.ini_options]
167
+ filterwarnings = [
168
+ "ignore::UserWarning:segment_anything_hq.modeling.tiny_vit_sam.*",
169
+ "ignore::DeprecationWarning:timm.models.layers.*",
170
+ "ignore::DeprecationWarning:timm.models.registry.*"
171
+ ]
172
+ addopts = "--import-mode=importlib"
requirements.docs.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ -e file:.[training]
2
+ -e file:.[doc]
requirements.lock ADDED
@@ -0,0 +1,442 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # generated by rye
2
+ # use `rye lock` or `rye sync` to update this lockfile
3
+ #
4
+ # last locked with the following flags:
5
+ # pre: false
6
+ # features: []
7
+ # all-features: true
8
+ # with-sources: false
9
+ # generate-hashes: false
10
+ # universal: false
11
+
12
+ -e file:.
13
+ aiohappyeyeballs==2.3.4
14
+ # via aiohttp
15
+ aiohttp==3.10.0
16
+ # via datasets
17
+ # via fsspec
18
+ aiosignal==1.3.1
19
+ # via aiohttp
20
+ annotated-types==0.7.0
21
+ # via pydantic
22
+ arrow==1.3.0
23
+ # via isoduration
24
+ async-timeout==4.0.3
25
+ # via aiohttp
26
+ attrs==23.2.0
27
+ # via aiohttp
28
+ # via jsonschema
29
+ # via referencing
30
+ babel==2.15.0
31
+ # via mkdocs-material
32
+ backports-strenum==1.3.1
33
+ # via griffe
34
+ beautifulsoup4==4.12.3
35
+ # via gdown
36
+ bitsandbytes==0.43.3
37
+ # via refiners
38
+ black==24.4.2
39
+ # via refiners
40
+ boto3==1.34.152
41
+ # via neptune
42
+ botocore==1.34.152
43
+ # via boto3
44
+ # via s3transfer
45
+ bravado==11.0.3
46
+ # via neptune
47
+ bravado-core==6.1.1
48
+ # via bravado
49
+ certifi==2024.7.4
50
+ # via requests
51
+ # via sentry-sdk
52
+ charset-normalizer==3.3.2
53
+ # via requests
54
+ click==8.1.7
55
+ # via black
56
+ # via mkdocs
57
+ # via mkdocstrings
58
+ # via neptune
59
+ # via wandb
60
+ colorama==0.4.6
61
+ # via griffe
62
+ # via mkdocs-material
63
+ datasets==2.20.0
64
+ # via refiners
65
+ diffusers==0.29.2
66
+ # via refiners
67
+ dill==0.3.8
68
+ # via datasets
69
+ # via multiprocess
70
+ docker-pycreds==0.4.0
71
+ # via wandb
72
+ filelock==3.15.4
73
+ # via datasets
74
+ # via diffusers
75
+ # via gdown
76
+ # via huggingface-hub
77
+ # via torch
78
+ # via transformers
79
+ # via triton
80
+ fqdn==1.5.1
81
+ # via jsonschema
82
+ frozenlist==1.4.1
83
+ # via aiohttp
84
+ # via aiosignal
85
+ fsspec==2024.5.0
86
+ # via datasets
87
+ # via huggingface-hub
88
+ # via torch
89
+ future==1.0.0
90
+ # via neptune
91
+ gdown==5.2.0
92
+ # via refiners
93
+ ghp-import==2.1.0
94
+ # via mkdocs
95
+ gitdb==4.0.11
96
+ # via gitpython
97
+ gitpython==3.1.43
98
+ # via neptune
99
+ # via refiners
100
+ # via wandb
101
+ griffe==0.48.0
102
+ # via mkdocstrings-python
103
+ huggingface-hub==0.24.6
104
+ # via datasets
105
+ # via diffusers
106
+ # via refiners
107
+ # via timm
108
+ # via tokenizers
109
+ # via transformers
110
+ idna==3.7
111
+ # via jsonschema
112
+ # via requests
113
+ # via yarl
114
+ importlib-metadata==8.2.0
115
+ # via diffusers
116
+ importlib-resources==6.4.0
117
+ # via swagger-spec-validator
118
+ isoduration==20.11.0
119
+ # via jsonschema
120
+ jaxtyping==0.2.33
121
+ # via refiners
122
+ jinja2==3.1.4
123
+ # via mkdocs
124
+ # via mkdocs-material
125
+ # via mkdocstrings
126
+ # via torch
127
+ jmespath==1.0.1
128
+ # via boto3
129
+ # via botocore
130
+ jsonpointer==3.0.0
131
+ # via jsonschema
132
+ jsonref==1.1.0
133
+ # via bravado-core
134
+ jsonschema==4.23.0
135
+ # via bravado-core
136
+ # via swagger-spec-validator
137
+ jsonschema-specifications==2023.12.1
138
+ # via jsonschema
139
+ loguru==0.7.2
140
+ # via refiners
141
+ markdown==3.6
142
+ # via mkdocs
143
+ # via mkdocs-autorefs
144
+ # via mkdocs-material
145
+ # via mkdocstrings
146
+ # via pymdown-extensions
147
+ markupsafe==2.1.5
148
+ # via jinja2
149
+ # via mkdocs
150
+ # via mkdocs-autorefs
151
+ # via mkdocstrings
152
+ mergedeep==1.3.4
153
+ # via mkdocs
154
+ # via mkdocs-get-deps
155
+ mkdocs==1.6.0
156
+ # via mkdocs-autorefs
157
+ # via mkdocs-literate-nav
158
+ # via mkdocs-material
159
+ # via mkdocstrings
160
+ mkdocs-autorefs==1.0.1
161
+ # via mkdocstrings
162
+ mkdocs-get-deps==0.2.0
163
+ # via mkdocs
164
+ mkdocs-literate-nav==0.6.1
165
+ # via refiners
166
+ mkdocs-material==9.5.30
167
+ # via refiners
168
+ mkdocs-material-extensions==1.3.1
169
+ # via mkdocs-material
170
+ mkdocstrings==0.25.2
171
+ # via mkdocstrings-python
172
+ # via refiners
173
+ mkdocstrings-python==1.10.7
174
+ # via mkdocstrings
175
+ monotonic==1.6
176
+ # via bravado
177
+ mpmath==1.3.0
178
+ # via sympy
179
+ msgpack==1.0.8
180
+ # via bravado
181
+ # via bravado-core
182
+ multidict==6.0.5
183
+ # via aiohttp
184
+ # via yarl
185
+ multiprocess==0.70.16
186
+ # via datasets
187
+ mypy-extensions==1.0.0
188
+ # via black
189
+ neptune==1.10.4
190
+ # via refiners
191
+ networkx==3.3
192
+ # via torch
193
+ numpy==2.0.1
194
+ # via bitsandbytes
195
+ # via datasets
196
+ # via diffusers
197
+ # via pandas
198
+ # via pyarrow
199
+ # via refiners
200
+ # via torchvision
201
+ # via transformers
202
+ nvidia-cublas-cu12==12.1.3.1
203
+ # via nvidia-cudnn-cu12
204
+ # via nvidia-cusolver-cu12
205
+ # via torch
206
+ nvidia-cuda-cupti-cu12==12.1.105
207
+ # via torch
208
+ nvidia-cuda-nvrtc-cu12==12.1.105
209
+ # via torch
210
+ nvidia-cuda-runtime-cu12==12.1.105
211
+ # via torch
212
+ nvidia-cudnn-cu12==9.1.0.70
213
+ # via torch
214
+ nvidia-cufft-cu12==11.0.2.54
215
+ # via torch
216
+ nvidia-curand-cu12==10.3.2.106
217
+ # via torch
218
+ nvidia-cusolver-cu12==11.4.5.107
219
+ # via torch
220
+ nvidia-cusparse-cu12==12.1.0.106
221
+ # via nvidia-cusolver-cu12
222
+ # via torch
223
+ nvidia-nccl-cu12==2.20.5
224
+ # via torch
225
+ nvidia-nvjitlink-cu12==12.6.20
226
+ # via nvidia-cusolver-cu12
227
+ # via nvidia-cusparse-cu12
228
+ nvidia-nvtx-cu12==12.1.105
229
+ # via torch
230
+ oauthlib==3.2.2
231
+ # via neptune
232
+ # via requests-oauthlib
233
+ packaging==24.1
234
+ # via black
235
+ # via datasets
236
+ # via huggingface-hub
237
+ # via mkdocs
238
+ # via neptune
239
+ # via refiners
240
+ # via transformers
241
+ paginate==0.5.6
242
+ # via mkdocs-material
243
+ pandas==2.2.2
244
+ # via datasets
245
+ # via neptune
246
+ pathspec==0.12.1
247
+ # via black
248
+ # via mkdocs
249
+ pillow==10.4.0
250
+ # via diffusers
251
+ # via neptune
252
+ # via refiners
253
+ # via torchvision
254
+ piq==0.8.0
255
+ # via refiners
256
+ platformdirs==4.2.2
257
+ # via black
258
+ # via mkdocs-get-deps
259
+ # via mkdocstrings
260
+ # via wandb
261
+ prodigyopt==1.0
262
+ # via refiners
263
+ protobuf==5.27.3
264
+ # via wandb
265
+ psutil==6.0.0
266
+ # via neptune
267
+ # via wandb
268
+ pyarrow==17.0.0
269
+ # via datasets
270
+ pyarrow-hotfix==0.6
271
+ # via datasets
272
+ pydantic==2.8.2
273
+ # via refiners
274
+ pydantic-core==2.20.1
275
+ # via pydantic
276
+ pygments==2.18.0
277
+ # via mkdocs-material
278
+ pyjwt==2.9.0
279
+ # via neptune
280
+ pymdown-extensions==10.9
281
+ # via mkdocs-material
282
+ # via mkdocstrings
283
+ pysocks==1.7.1
284
+ # via requests
285
+ python-dateutil==2.9.0.post0
286
+ # via arrow
287
+ # via botocore
288
+ # via bravado
289
+ # via bravado-core
290
+ # via ghp-import
291
+ # via pandas
292
+ pytz==2024.1
293
+ # via bravado-core
294
+ # via pandas
295
+ pyyaml==6.0.1
296
+ # via bravado
297
+ # via bravado-core
298
+ # via datasets
299
+ # via huggingface-hub
300
+ # via mkdocs
301
+ # via mkdocs-get-deps
302
+ # via pymdown-extensions
303
+ # via pyyaml-env-tag
304
+ # via swagger-spec-validator
305
+ # via timm
306
+ # via transformers
307
+ # via wandb
308
+ pyyaml-env-tag==0.1
309
+ # via mkdocs
310
+ referencing==0.35.1
311
+ # via jsonschema
312
+ # via jsonschema-specifications
313
+ regex==2024.7.24
314
+ # via diffusers
315
+ # via mkdocs-material
316
+ # via transformers
317
+ requests==2.32.3
318
+ # via bravado
319
+ # via bravado-core
320
+ # via datasets
321
+ # via diffusers
322
+ # via gdown
323
+ # via huggingface-hub
324
+ # via mkdocs-material
325
+ # via neptune
326
+ # via refiners
327
+ # via requests-oauthlib
328
+ # via transformers
329
+ # via wandb
330
+ requests-oauthlib==2.0.0
331
+ # via neptune
332
+ rfc3339-validator==0.1.4
333
+ # via jsonschema
334
+ rfc3986-validator==0.1.1
335
+ # via jsonschema
336
+ rpds-py==0.19.1
337
+ # via jsonschema
338
+ # via referencing
339
+ s3transfer==0.10.2
340
+ # via boto3
341
+ safetensors==0.4.5
342
+ # via diffusers
343
+ # via refiners
344
+ # via timm
345
+ # via transformers
346
+ segment-anything-hq==0.3
347
+ # via refiners
348
+ segment-anything-py==1.0.1
349
+ # via refiners
350
+ sentencepiece==0.2.0
351
+ # via refiners
352
+ sentry-sdk==2.12.0
353
+ # via wandb
354
+ setproctitle==1.3.3
355
+ # via wandb
356
+ setuptools==72.1.0
357
+ # via wandb
358
+ simplejson==3.19.2
359
+ # via bravado
360
+ # via bravado-core
361
+ six==1.16.0
362
+ # via bravado
363
+ # via bravado-core
364
+ # via docker-pycreds
365
+ # via neptune
366
+ # via python-dateutil
367
+ # via rfc3339-validator
368
+ smmap==5.0.1
369
+ # via gitdb
370
+ soupsieve==2.6
371
+ # via beautifulsoup4
372
+ swagger-spec-validator==3.0.4
373
+ # via bravado-core
374
+ # via neptune
375
+ sympy==1.13.1
376
+ # via torch
377
+ timm==1.0.8
378
+ # via refiners
379
+ tokenizers==0.19.1
380
+ # via transformers
381
+ tomli==2.0.1
382
+ # via black
383
+ # via refiners
384
+ torch==2.4.0
385
+ # via bitsandbytes
386
+ # via refiners
387
+ # via segment-anything-hq
388
+ # via segment-anything-py
389
+ # via timm
390
+ # via torchvision
391
+ torchvision==0.19.0
392
+ # via piq
393
+ # via refiners
394
+ # via segment-anything-hq
395
+ # via segment-anything-py
396
+ # via timm
397
+ tqdm==4.66.4
398
+ # via datasets
399
+ # via gdown
400
+ # via huggingface-hub
401
+ # via refiners
402
+ # via transformers
403
+ transformers==4.43.3
404
+ # via refiners
405
+ triton==3.0.0
406
+ # via torch
407
+ typeguard==2.13.3
408
+ # via jaxtyping
409
+ types-python-dateutil==2.9.0.20240316
410
+ # via arrow
411
+ typing-extensions==4.12.2
412
+ # via black
413
+ # via bravado
414
+ # via huggingface-hub
415
+ # via neptune
416
+ # via pydantic
417
+ # via pydantic-core
418
+ # via swagger-spec-validator
419
+ # via torch
420
+ tzdata==2024.1
421
+ # via pandas
422
+ uri-template==1.3.0
423
+ # via jsonschema
424
+ urllib3==2.2.2
425
+ # via botocore
426
+ # via neptune
427
+ # via requests
428
+ # via sentry-sdk
429
+ wandb==0.17.5
430
+ # via refiners
431
+ watchdog==4.0.1
432
+ # via mkdocs
433
+ webcolors==24.6.0
434
+ # via jsonschema
435
+ websocket-client==1.8.0
436
+ # via neptune
437
+ xxhash==3.4.1
438
+ # via datasets
439
+ yarl==1.9.4
440
+ # via aiohttp
441
+ zipp==3.19.2
442
+ # via importlib-metadata