diffgentor 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- diffgentor-0.1.0/.github/workflows/publish.yml +80 -0
- diffgentor-0.1.0/.gitignore +207 -0
- diffgentor-0.1.0/.gitmodules +15 -0
- diffgentor-0.1.0/AGENTS.md +213 -0
- diffgentor-0.1.0/LICENSE +201 -0
- diffgentor-0.1.0/PKG-INFO +213 -0
- diffgentor-0.1.0/README.md +125 -0
- diffgentor-0.1.0/diffgentor/__init__.py +22 -0
- diffgentor-0.1.0/diffgentor/__main__.py +10 -0
- diffgentor-0.1.0/diffgentor/backends/__init__.py +11 -0
- diffgentor-0.1.0/diffgentor/backends/base.py +216 -0
- diffgentor-0.1.0/diffgentor/backends/editing/__init__.py +10 -0
- diffgentor-0.1.0/diffgentor/backends/editing/bagel.py +272 -0
- diffgentor-0.1.0/diffgentor/backends/editing/diffusers_editing.py +470 -0
- diffgentor-0.1.0/diffgentor/backends/editing/dreamomni2.py +337 -0
- diffgentor-0.1.0/diffgentor/backends/editing/emu35.py +316 -0
- diffgentor-0.1.0/diffgentor/backends/editing/flux_kontext.py +262 -0
- diffgentor-0.1.0/diffgentor/backends/editing/google_genai_editing.py +408 -0
- diffgentor-0.1.0/diffgentor/backends/editing/hunyuan_image_3.py +246 -0
- diffgentor-0.1.0/diffgentor/backends/editing/openai_editing.py +311 -0
- diffgentor-0.1.0/diffgentor/backends/editing/registry.py +103 -0
- diffgentor-0.1.0/diffgentor/backends/editing/step1x.py +192 -0
- diffgentor-0.1.0/diffgentor/backends/editing/strategies/__init__.py +15 -0
- diffgentor-0.1.0/diffgentor/backends/editing/strategies/base.py +134 -0
- diffgentor-0.1.0/diffgentor/backends/editing/strategies/implementations.py +120 -0
- diffgentor-0.1.0/diffgentor/backends/editing/strategies/registry.py +104 -0
- diffgentor-0.1.0/diffgentor/backends/registry.py +71 -0
- diffgentor-0.1.0/diffgentor/backends/t2i/__init__.py +13 -0
- diffgentor-0.1.0/diffgentor/backends/t2i/diffusers_backend.py +550 -0
- diffgentor-0.1.0/diffgentor/backends/t2i/google_genai_backend.py +409 -0
- diffgentor-0.1.0/diffgentor/backends/t2i/openai_backend.py +298 -0
- diffgentor-0.1.0/diffgentor/backends/t2i/xdit_backend.py +406 -0
- diffgentor-0.1.0/diffgentor/cli/__init__.py +5 -0
- diffgentor-0.1.0/diffgentor/cli/main.py +479 -0
- diffgentor-0.1.0/diffgentor/config.py +413 -0
- diffgentor-0.1.0/diffgentor/launcher/__init__.py +5 -0
- diffgentor-0.1.0/diffgentor/launcher/launcher.py +415 -0
- diffgentor-0.1.0/diffgentor/models/__init__.py +1 -0
- diffgentor-0.1.0/diffgentor/models/third_party/__init__.py +1 -0
- diffgentor-0.1.0/diffgentor/optimizations/__init__.py +10 -0
- diffgentor-0.1.0/diffgentor/optimizations/base.py +98 -0
- diffgentor-0.1.0/diffgentor/optimizations/manager.py +108 -0
- diffgentor-0.1.0/diffgentor/optimizations/optimizers.py +360 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/__init__.py +18 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/base.py +199 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/flux2.py +378 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/glm_image.py +156 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/qwen_image_edit.py +203 -0
- diffgentor-0.1.0/diffgentor/prompt_enhance/registry.py +112 -0
- diffgentor-0.1.0/diffgentor/utils/__init__.py +38 -0
- diffgentor-0.1.0/diffgentor/utils/api_pool.py +446 -0
- diffgentor-0.1.0/diffgentor/utils/data.py +896 -0
- diffgentor-0.1.0/diffgentor/utils/distributed.py +116 -0
- diffgentor-0.1.0/diffgentor/utils/env.py +454 -0
- diffgentor-0.1.0/diffgentor/utils/exceptions.py +204 -0
- diffgentor-0.1.0/diffgentor/utils/image.py +276 -0
- diffgentor-0.1.0/diffgentor/utils/logging.py +327 -0
- diffgentor-0.1.0/diffgentor/utils/task_distribution.py +39 -0
- diffgentor-0.1.0/diffgentor/workers/__init__.py +5 -0
- diffgentor-0.1.0/diffgentor/workers/base.py +317 -0
- diffgentor-0.1.0/diffgentor/workers/edit_worker.py +551 -0
- diffgentor-0.1.0/diffgentor/workers/t2i_worker.py +310 -0
- diffgentor-0.1.0/docs/editing/README.md +230 -0
- diffgentor-0.1.0/docs/editing/bagel.md +114 -0
- diffgentor-0.1.0/docs/editing/diffusers.md +294 -0
- diffgentor-0.1.0/docs/editing/dreamomni2.md +142 -0
- diffgentor-0.1.0/docs/editing/emu35.md +109 -0
- diffgentor-0.1.0/docs/editing/flux_kontext.md +107 -0
- diffgentor-0.1.0/docs/editing/google_genai.md +245 -0
- diffgentor-0.1.0/docs/editing/hunyuan_image_3.md +205 -0
- diffgentor-0.1.0/docs/editing/openai.md +223 -0
- diffgentor-0.1.0/docs/editing/step1x.md +92 -0
- diffgentor-0.1.0/docs/env_vars.md +179 -0
- diffgentor-0.1.0/docs/optimization/README.md +213 -0
- diffgentor-0.1.0/docs/optimization/batch_inference.md +444 -0
- diffgentor-0.1.0/docs/optimization/memory.md +331 -0
- diffgentor-0.1.0/docs/optimization/multi_gpu.md +387 -0
- diffgentor-0.1.0/docs/optimization/speed.md +410 -0
- diffgentor-0.1.0/docs/optimization.md +109 -0
- diffgentor-0.1.0/docs/prompt_enhance.md +334 -0
- diffgentor-0.1.0/docs/t2i/README.md +299 -0
- diffgentor-0.1.0/docs/t2i/google_genai.md +239 -0
- diffgentor-0.1.0/pyproject.toml +91 -0
- diffgentor-0.1.0/uv.lock +4205 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*" # Trigger on tags like v0.1.0, v1.0.0, etc.
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build distribution
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Update version from tag
|
|
17
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
18
|
+
run: |
|
|
19
|
+
VERSION=${GITHUB_REF#refs/tags/v}
|
|
20
|
+
echo "Updating pyproject.toml version to $VERSION"
|
|
21
|
+
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" pyproject.toml
|
|
22
|
+
cat pyproject.toml | grep "^version"
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.11"
|
|
28
|
+
|
|
29
|
+
- name: Install build dependencies
|
|
30
|
+
run: |
|
|
31
|
+
python -m pip install --upgrade pip
|
|
32
|
+
pip install build
|
|
33
|
+
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: python -m build
|
|
36
|
+
|
|
37
|
+
- name: Upload distribution artifacts
|
|
38
|
+
uses: actions/upload-artifact@v4
|
|
39
|
+
with:
|
|
40
|
+
name: python-package-distributions
|
|
41
|
+
path: dist/
|
|
42
|
+
|
|
43
|
+
create-release:
|
|
44
|
+
name: Create GitHub Release
|
|
45
|
+
needs: build
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
permissions:
|
|
48
|
+
contents: write # Required for creating releases
|
|
49
|
+
steps:
|
|
50
|
+
- name: Download distribution artifacts
|
|
51
|
+
uses: actions/download-artifact@v4
|
|
52
|
+
with:
|
|
53
|
+
name: python-package-distributions
|
|
54
|
+
path: dist/
|
|
55
|
+
|
|
56
|
+
- name: Create GitHub Release
|
|
57
|
+
uses: softprops/action-gh-release@v2
|
|
58
|
+
with:
|
|
59
|
+
files: dist/*
|
|
60
|
+
generate_release_notes: true
|
|
61
|
+
|
|
62
|
+
publish-to-pypi:
|
|
63
|
+
name: Publish to PyPI
|
|
64
|
+
needs: build
|
|
65
|
+
runs-on: ubuntu-latest
|
|
66
|
+
environment:
|
|
67
|
+
name: pypi
|
|
68
|
+
url: https://pypi.org/p/diffgentor
|
|
69
|
+
permissions:
|
|
70
|
+
id-token: write # Required for trusted publishing
|
|
71
|
+
|
|
72
|
+
steps:
|
|
73
|
+
- name: Download distribution artifacts
|
|
74
|
+
uses: actions/download-artifact@v4
|
|
75
|
+
with:
|
|
76
|
+
name: python-package-distributions
|
|
77
|
+
path: dist/
|
|
78
|
+
|
|
79
|
+
- name: Publish to PyPI
|
|
80
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[submodule "diffgentor/models/third_party/emu35"]
|
|
2
|
+
path = diffgentor/models/third_party/emu35
|
|
3
|
+
url = https://github.com/diffgentor/Emu3.5
|
|
4
|
+
[submodule "diffgentor/models/third_party/step1x_edit"]
|
|
5
|
+
path = diffgentor/models/third_party/step1x_edit
|
|
6
|
+
url = https://github.com/diffgentor/Step1X-Edit
|
|
7
|
+
[submodule "diffgentor/models/third_party/bagel"]
|
|
8
|
+
path = diffgentor/models/third_party/bagel
|
|
9
|
+
url = https://github.com/diffgentor/Bagel
|
|
10
|
+
[submodule "diffgentor/models/third_party/dreamomni2"]
|
|
11
|
+
path = diffgentor/models/third_party/dreamomni2
|
|
12
|
+
url = https://github.com/diffgentor/DreamOmni2
|
|
13
|
+
[submodule "diffgentor/models/third_party/flux1"]
|
|
14
|
+
path = diffgentor/models/third_party/flux1
|
|
15
|
+
url = https://github.com/diffgentor/flux
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: diffgentor_agent
|
|
3
|
+
description: Expert developer for the diffgentor visual generation data synthesis project
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
You are an expert Python developer for the diffgentor project - a unified visual generation data synthesis factory.
|
|
7
|
+
|
|
8
|
+
## Your Role
|
|
9
|
+
|
|
10
|
+
- You are fluent in Python 3.10+ and familiar with deep learning frameworks (PyTorch, diffusers, transformers)
|
|
11
|
+
- You specialize in image generation and editing pipelines, distributed inference, and API integrations
|
|
12
|
+
- Your task: maintain and extend the diffgentor codebase for T2I (text-to-image) and image editing capabilities
|
|
13
|
+
|
|
14
|
+
## Project Knowledge
|
|
15
|
+
|
|
16
|
+
### Tech Stack
|
|
17
|
+
|
|
18
|
+
- **Python:** 3.10+
|
|
19
|
+
- **Core Dependencies:** PyTorch >=2.3.0, diffusers >=0.31.0, transformers >=4.40.0
|
|
20
|
+
- **Optional:** xDiT (multi-GPU), OpenAI API, xformers, DeepCache, torchao, bitsandbytes
|
|
21
|
+
- **Build System:** hatchling (pyproject.toml)
|
|
22
|
+
- **Code Style:** black (line-length=120), ruff for linting
|
|
23
|
+
|
|
24
|
+
### File Structure
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
diffgentor/
|
|
28
|
+
├── __init__.py # Package init
|
|
29
|
+
├── __main__.py # Entry point
|
|
30
|
+
├── config.py # Configuration classes (BackendConfig, EditingConfig, OptimizationConfig)
|
|
31
|
+
├── backends/ # Backend implementations
|
|
32
|
+
│ ├── base.py # Base backend class
|
|
33
|
+
│ ├── registry.py # Backend registry
|
|
34
|
+
│ ├── editing/ # Editing backends (openai, google_genai, step1x, bagel, etc.)
|
|
35
|
+
│ └── t2i/ # T2I backends (diffusers, xdit)
|
|
36
|
+
├── cli/ # CLI interface
|
|
37
|
+
│ └── main.py # Argument parsing, subcommands (t2i, edit)
|
|
38
|
+
├── launcher/ # Distributed launcher
|
|
39
|
+
│ └── launcher.py # Multi-process/GPU coordination
|
|
40
|
+
├── models/ # Model definitions
|
|
41
|
+
│ └── third_party/ # Third-party model integrations, git submodules
|
|
42
|
+
├── optimizations/ # Optimization utilities
|
|
43
|
+
│ └── manager.py # VAE slicing, torch.compile, attention backends, cache
|
|
44
|
+
├── prompt_enhance/ # Prompt enhancement module
|
|
45
|
+
│ ├── base.py # Base PromptEnhancer class
|
|
46
|
+
│ ├── registry.py # Enhancer registry
|
|
47
|
+
│ ├── flux2.py # Flux2 style enhancer (diffusers/API modes)
|
|
48
|
+
│ ├── qwen_image_edit.py
|
|
49
|
+
│ └── glm_image.py
|
|
50
|
+
├── utils/ # Utility functions
|
|
51
|
+
│ ├── env.py # Environment variable utilities (DG_ prefix)
|
|
52
|
+
│ ├── api_pool.py # API endpoint pool with load balancing
|
|
53
|
+
│ ├── distributed.py # Distributed training utilities
|
|
54
|
+
│ ├── data.py # Data loading/saving
|
|
55
|
+
│ ├── image.py # Image processing
|
|
56
|
+
│ └── logging.py # Logging utilities
|
|
57
|
+
└── workers/ # Worker processes
|
|
58
|
+
├── edit_worker.py # Image editing worker
|
|
59
|
+
└── t2i_worker.py # T2I generation worker
|
|
60
|
+
docs/ # Documentation
|
|
61
|
+
temp/ # Temporary files, experiments (git-ignored mostly)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Supported Backends
|
|
65
|
+
|
|
66
|
+
| Backend | Type | Description |
|
|
67
|
+
|---------|------|-------------|
|
|
68
|
+
| `diffusers` | T2I / Editing | HuggingFace diffusers with auto pipeline detection |
|
|
69
|
+
| `xdit` | T2I | Multi-GPU inference with xDiT parallelism |
|
|
70
|
+
| `openai` | T2I / Editing | OpenAI API (GPT-Image, DALL-E) |
|
|
71
|
+
| `google_genai` | T2I / Editing | Google GenAI (Gemini native image models) |
|
|
72
|
+
| `step1x` | Editing | Step1X-Edit model |
|
|
73
|
+
| `bagel` | Editing | ByteDance BAGEL model |
|
|
74
|
+
| `emu35` | Editing | BAAI Emu3.5 model |
|
|
75
|
+
| `dreamomni2` | Editing | DreamOmni2 (FLUX.1-Kontext + Qwen2.5-VL) |
|
|
76
|
+
| `flux_kontext_official` | Editing | BFL official Flux Kontext |
|
|
77
|
+
| `hunyuan_image_3` | Editing | Tencent HunyuanImage-3.0-Instruct with CoT reasoning |
|
|
78
|
+
|
|
79
|
+
## Commands You Can Use
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Install dependencies
|
|
83
|
+
pip install -e .
|
|
84
|
+
pip install -e ".[all]"
|
|
85
|
+
|
|
86
|
+
# Run T2I generation
|
|
87
|
+
diffgentor t2i --backend diffusers --model_name black-forest-labs/FLUX.1-dev --prompt "A cat"
|
|
88
|
+
|
|
89
|
+
# Run image editing
|
|
90
|
+
diffgentor edit --backend diffusers --model_name Qwen/Qwen-Image-Edit-2511 --input data.csv
|
|
91
|
+
|
|
92
|
+
# Run image editing with custom output filenames (from CSV/Parquet column)
|
|
93
|
+
diffgentor edit --backend diffusers --model_name Qwen/Qwen-Image-Edit-2511 --input data.csv --output_name_column output_path
|
|
94
|
+
|
|
95
|
+
# Lint code
|
|
96
|
+
ruff check diffgentor/
|
|
97
|
+
black --check diffgentor/
|
|
98
|
+
|
|
99
|
+
# Format code
|
|
100
|
+
black diffgentor/
|
|
101
|
+
|
|
102
|
+
# Type check
|
|
103
|
+
mypy diffgentor/
|
|
104
|
+
|
|
105
|
+
# Run tests
|
|
106
|
+
pytest tests/
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Custom Output Filename Support
|
|
110
|
+
|
|
111
|
+
**Default behavior** (without `--output_name_column`):
|
|
112
|
+
- Output files are named `{index:06d}.png` (e.g., `000000.png`, `000001.png`)
|
|
113
|
+
- For multiple images per prompt: `{index:06d}_{sub_index:02d}.png` (e.g., `000000_00.png`)
|
|
114
|
+
|
|
115
|
+
**With `--output_name_column`**: Specify a column in the input CSV/Parquet file to use as the output filename:
|
|
116
|
+
|
|
117
|
+
- If the column value is `aaa/bb/1`, output will be saved as `output_dir/aaa/bb/1.png`
|
|
118
|
+
- If the column value is `aaa/bb/1.jpg`, output will be saved as `output_dir/aaa/bb/1.jpg`
|
|
119
|
+
- Supported formats: `.png`, `.jpg`, `.jpeg` (other extensions default to `.png`)
|
|
120
|
+
- Parent directories are automatically created
|
|
121
|
+
- For multiple images per prompt, sub-index is appended: `aaa/bb/1_00.png`, `aaa/bb/1_01.png`
|
|
122
|
+
|
|
123
|
+
## Code Style Guidelines
|
|
124
|
+
|
|
125
|
+
### General Rules
|
|
126
|
+
|
|
127
|
+
- **Write all code comments in English**
|
|
128
|
+
- Line length: 120 characters max
|
|
129
|
+
- Use type hints for function signatures
|
|
130
|
+
- Follow PEP 8 with black formatting
|
|
131
|
+
- Import order: stdlib, third-party, local (handled by ruff/isort)
|
|
132
|
+
|
|
133
|
+
### Environment Variables
|
|
134
|
+
|
|
135
|
+
**All environment variables MUST be prefixed with `DG_`**
|
|
136
|
+
|
|
137
|
+
Use the `diffgentor.utils.env` module for accessing environment variables:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
# Good - use helper functions
|
|
141
|
+
from diffgentor.utils.env import get_env_str, get_env_int, get_env_float, get_env_bool
|
|
142
|
+
|
|
143
|
+
api_key = get_env_str("PROMPT_ENHANCER_API_KEY") # Reads DG_PROMPT_ENHANCER_API_KEY
|
|
144
|
+
timeout = get_env_int("OPENAI_TIMEOUT", 300) # Reads DG_OPENAI_TIMEOUT with default
|
|
145
|
+
|
|
146
|
+
# Bad - direct os.environ access without DG_ prefix
|
|
147
|
+
api_key = os.environ.get("API_KEY") # Wrong! Missing DG_ prefix
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Naming convention: `DG_{COMPONENT}_{PARAM}`
|
|
151
|
+
|
|
152
|
+
Examples:
|
|
153
|
+
- `DG_STEP1X_VERSION=v1.1`
|
|
154
|
+
- `DG_BAGEL_CFG_TEXT_SCALE=3.0`
|
|
155
|
+
- `DG_PROMPT_ENHANCER_API_KEY=xxx`
|
|
156
|
+
- `DG_FLUX2_ENHANCER_MODE=api`
|
|
157
|
+
- `DG_XDIT_ULYSSES_DEGREE=4`
|
|
158
|
+
- `DG_XDIT_RING_DEGREE=2`
|
|
159
|
+
- `DG_HUNYUAN_IMAGE_3_MOE_IMPL=flashinfer`
|
|
160
|
+
- `DG_HUNYUAN_IMAGE_3_GPUS_PER_MODEL=4`
|
|
161
|
+
|
|
162
|
+
### CLI Arguments vs Environment Variables
|
|
163
|
+
|
|
164
|
+
**Only common/shared parameters should be added to CLI arguments.** Model-specific parameters (e.g., bagel's `cfg_text_scale`, step1x's `size_level`, emu35's `vq_path`, xDiT's `ulysses_degree`) MUST be configured via `DG_*` environment variables, NOT CLI arguments.
|
|
165
|
+
|
|
166
|
+
- **CLI args**: Common parameters shared across backends (e.g., `--model_name`, `--batch_size`, `--num_inference_steps`)
|
|
167
|
+
- **Env vars**: Model-specific parameters (e.g., `DG_BAGEL_CFG_TEXT_SCALE`, `DG_STEP1X_VERSION`, `DG_EMU35_VQ_PATH`, `DG_XDIT_ULYSSES_DEGREE`)
|
|
168
|
+
|
|
169
|
+
### Distributed Logging
|
|
170
|
+
|
|
171
|
+
The logging system is designed for distributed environments with the following behavior:
|
|
172
|
+
|
|
173
|
+
- **Terminal output**: Only `local_rank=0` process on each node outputs to terminal
|
|
174
|
+
- **File output**: All processes write to individual log files (`nodeX_processY.log`)
|
|
175
|
+
- **Third-party libraries**: Automatically suppresses diffusers/transformers/tqdm output for non-main processes
|
|
176
|
+
- **stdout/stderr redirect**: Captures all `print()` calls to the logging system
|
|
177
|
+
|
|
178
|
+
**CLI option:**
|
|
179
|
+
- `--log_dir`: Log directory path (default: `output_dir/logs/yyyymmdd_hhmm`)
|
|
180
|
+
|
|
181
|
+
**Key modules:**
|
|
182
|
+
- `diffgentor.utils.logging.LoggingConfig`: Logging configuration dataclass
|
|
183
|
+
- `diffgentor.utils.logging.setup_logging()`: Initialize distributed logging system
|
|
184
|
+
- `diffgentor.utils.logging.StreamRedirect`: Redirect stdout/stderr to logger
|
|
185
|
+
|
|
186
|
+
## Boundaries
|
|
187
|
+
|
|
188
|
+
### ✅ Always Do
|
|
189
|
+
|
|
190
|
+
- Write all code comments in English
|
|
191
|
+
- Use `DG_` prefix for all environment variables
|
|
192
|
+
- Use `diffgentor.utils.env` helpers for env var access
|
|
193
|
+
- Add type hints to function signatures
|
|
194
|
+
- Follow existing code patterns and structure
|
|
195
|
+
- Run `black` and `ruff` before committing
|
|
196
|
+
- Document environment variables in docstrings
|
|
197
|
+
- Update `AGENTS.md` when adding new backends/enhancers/other important features
|
|
198
|
+
- Update related contents in `docs/` when adding/modifying features
|
|
199
|
+
|
|
200
|
+
### ⚠️ Ask First
|
|
201
|
+
|
|
202
|
+
- Before modifying core config classes (`config.py`)
|
|
203
|
+
- Before changing CLI argument structure (`cli/main.py`)
|
|
204
|
+
- Before modifying the base backend interface (`backends/base.py`)
|
|
205
|
+
- Before adding new third-party dependencies to `pyproject.toml`
|
|
206
|
+
|
|
207
|
+
### 🚫 Never Do
|
|
208
|
+
|
|
209
|
+
- Never use environment variables without `DG_` prefix
|
|
210
|
+
- Never write comments in languages other than English
|
|
211
|
+
- Never commit API keys, secrets, or credentials
|
|
212
|
+
- Never modify `.git/` or `.gitmodules` directly
|
|
213
|
+
- Never bypass the registry pattern when adding backends/enhancers
|