Fluminato
Browse files- .fluminaignore +166 -0
- .gitattributes +5 -0
- config.json +20 -0
- configs/config-dev-1-RTX6000ADA.json +0 -57
- configs/config-dev-cuda0.json +0 -56
- configs/config-dev-eval.json +0 -57
- configs/config-dev-gigaquant.json +0 -58
- configs/config-dev-offload-1-4080.json +0 -58
- configs/config-dev-offload-1-4090.json +0 -58
- configs/config-dev-offload.json +0 -58
- configs/config-dev-prequant.json +0 -57
- configs/config-dev.json +9 -9
- configs/config-schnell-cuda0.json +0 -57
- fireworks.json +1 -0
- flumina.py +326 -0
- requirements.txt +4 -1
.fluminaignore
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.git/
|
2 |
+
.gitmodules
|
3 |
+
|
4 |
+
# Byte-compiled / optimized / DLL files
|
5 |
+
__pycache__/
|
6 |
+
*.py[cod]
|
7 |
+
*$py.class
|
8 |
+
|
9 |
+
# C extensions
|
10 |
+
*.so
|
11 |
+
|
12 |
+
# Distribution / packaging
|
13 |
+
.Python
|
14 |
+
build/
|
15 |
+
develop-eggs/
|
16 |
+
dist/
|
17 |
+
downloads/
|
18 |
+
eggs/
|
19 |
+
.eggs/
|
20 |
+
lib/
|
21 |
+
lib64/
|
22 |
+
parts/
|
23 |
+
sdist/
|
24 |
+
var/
|
25 |
+
wheels/
|
26 |
+
share/python-wheels/
|
27 |
+
*.egg-info/
|
28 |
+
.installed.cfg
|
29 |
+
*.egg
|
30 |
+
MANIFEST
|
31 |
+
|
32 |
+
# PyInstaller
|
33 |
+
# Usually these files are written by a python script from a template
|
34 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
35 |
+
*.manifest
|
36 |
+
*.spec
|
37 |
+
|
38 |
+
# Installer logs
|
39 |
+
pip-log.txt
|
40 |
+
pip-delete-this-directory.txt
|
41 |
+
|
42 |
+
# Unit test / coverage reports
|
43 |
+
htmlcov/
|
44 |
+
.tox/
|
45 |
+
.nox/
|
46 |
+
.coverage
|
47 |
+
.coverage.*
|
48 |
+
.cache
|
49 |
+
nosetests.xml
|
50 |
+
coverage.xml
|
51 |
+
*.cover
|
52 |
+
*.py,cover
|
53 |
+
.hypothesis/
|
54 |
+
.pytest_cache/
|
55 |
+
cover/
|
56 |
+
|
57 |
+
# Translations
|
58 |
+
*.mo
|
59 |
+
*.pot
|
60 |
+
|
61 |
+
# Django stuff:
|
62 |
+
*.log
|
63 |
+
local_settings.py
|
64 |
+
db.sqlite3
|
65 |
+
db.sqlite3-journal
|
66 |
+
|
67 |
+
# Flask stuff:
|
68 |
+
instance/
|
69 |
+
.webassets-cache
|
70 |
+
|
71 |
+
# Scrapy stuff:
|
72 |
+
.scrapy
|
73 |
+
|
74 |
+
# Sphinx documentation
|
75 |
+
docs/_build/
|
76 |
+
|
77 |
+
# PyBuilder
|
78 |
+
.pybuilder/
|
79 |
+
target/
|
80 |
+
|
81 |
+
# Jupyter Notebook
|
82 |
+
.ipynb_checkpoints
|
83 |
+
|
84 |
+
# IPython
|
85 |
+
profile_default/
|
86 |
+
ipython_config.py
|
87 |
+
|
88 |
+
# pyenv
|
89 |
+
# For a library or package, you might want to ignore these files since the code is
|
90 |
+
# intended to run in multiple environments; otherwise, check them in:
|
91 |
+
# .python-version
|
92 |
+
|
93 |
+
# pipenv
|
94 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
95 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
96 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
97 |
+
# install all needed dependencies.
|
98 |
+
#Pipfile.lock
|
99 |
+
|
100 |
+
# poetry
|
101 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
102 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
103 |
+
# commonly ignored for libraries.
|
104 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
105 |
+
#poetry.lock
|
106 |
+
|
107 |
+
# pdm
|
108 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
109 |
+
#pdm.lock
|
110 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
111 |
+
# in version control.
|
112 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
113 |
+
.pdm.toml
|
114 |
+
.pdm-python
|
115 |
+
.pdm-build/
|
116 |
+
|
117 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
118 |
+
__pypackages__/
|
119 |
+
|
120 |
+
# Celery stuff
|
121 |
+
celerybeat-schedule
|
122 |
+
celerybeat.pid
|
123 |
+
|
124 |
+
# SageMath parsed files
|
125 |
+
*.sage.py
|
126 |
+
|
127 |
+
# Environments
|
128 |
+
.env
|
129 |
+
.venv
|
130 |
+
env/
|
131 |
+
venv/
|
132 |
+
ENV/
|
133 |
+
env.bak/
|
134 |
+
venv.bak/
|
135 |
+
|
136 |
+
# Spyder project settings
|
137 |
+
.spyderproject
|
138 |
+
.spyproject
|
139 |
+
|
140 |
+
# Rope project settings
|
141 |
+
.ropeproject
|
142 |
+
|
143 |
+
# mkdocs documentation
|
144 |
+
/site
|
145 |
+
|
146 |
+
# mypy
|
147 |
+
.mypy_cache/
|
148 |
+
.dmypy.json
|
149 |
+
dmypy.json
|
150 |
+
|
151 |
+
# Pyre type checker
|
152 |
+
.pyre/
|
153 |
+
|
154 |
+
# pytype static type analyzer
|
155 |
+
.pytype/
|
156 |
+
|
157 |
+
# Cython debug symbols
|
158 |
+
cython_debug/
|
159 |
+
|
160 |
+
# PyCharm
|
161 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
162 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
163 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
164 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
165 |
+
#.idea/
|
166 |
+
.DS_Store
|
.gitattributes
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
flux1-dev.safetensors filter=lfs diff=lfs merge=lfs -text
|
2 |
+
ae.safetensors filter=lfs diff=lfs merge=lfs -text
|
3 |
+
t5-v1_1-xxl-encoder-bf16//*.safetensor filter=lfs diff=lfs merge=lfs -text
|
4 |
+
t5-v1_1-xxl-encoder-bf16//spiece.model filter=lfs diff=lfs merge=lfs -text
|
5 |
+
t5-v1_1-xxl-encoder-bf16/model.safetensors filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"config_path": "configs/config-dev.json",
|
3 |
+
"flow_model_path": "flux1-dev.safetensors",
|
4 |
+
"model_version": "flux-dev",
|
5 |
+
"flux_device": "cuda",
|
6 |
+
"autoencoder_path": null,
|
7 |
+
"autoencoder_device": "cuda",
|
8 |
+
"text_enc_path": null,
|
9 |
+
"text_enc_device": "cuda",
|
10 |
+
"num_to_quant": 20,
|
11 |
+
"compile": false,
|
12 |
+
"quant_text_enc": "qfloat8",
|
13 |
+
"quant_ae": false,
|
14 |
+
"offload_flow": false,
|
15 |
+
"offload_ae": true,
|
16 |
+
"offload_text_enc": true,
|
17 |
+
"prequantized_flow": false,
|
18 |
+
"quantize_modulation": true,
|
19 |
+
"quantize_flow_embedder_layers": false
|
20 |
+
}
|
configs/config-dev-1-RTX6000ADA.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"flow_quantization_dtype": "qfloat8",
|
51 |
-
"text_enc_quantization_dtype": "qfloat8",
|
52 |
-
"compile_extras": true,
|
53 |
-
"compile_blocks": true,
|
54 |
-
"offload_text_encoder": false,
|
55 |
-
"offload_vae": false,
|
56 |
-
"offload_flow": false
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-cuda0.json
DELETED
@@ -1,56 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"text_enc_quantization_dtype": "qfloat8",
|
51 |
-
"compile_extras": false,
|
52 |
-
"compile_blocks": false,
|
53 |
-
"offload_ae": false,
|
54 |
-
"offload_text_enc": false,
|
55 |
-
"offload_flow": false
|
56 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-eval.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:1",
|
45 |
-
"ae_device": "cuda:1",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"flow_quantization_dtype": "qfloat8",
|
51 |
-
"text_enc_quantization_dtype": "qfloat8",
|
52 |
-
"compile_extras": false,
|
53 |
-
"compile_blocks": false,
|
54 |
-
"offload_ae": false,
|
55 |
-
"offload_text_enc": false,
|
56 |
-
"offload_flow": false
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-gigaquant.json
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"num_to_quant": 220,
|
51 |
-
"flow_quantization_dtype": "qint4",
|
52 |
-
"text_enc_quantization_dtype": "qint4",
|
53 |
-
"ae_quantization_dtype": "qint4",
|
54 |
-
"clip_quantization_dtype": "qint4",
|
55 |
-
"compile_extras": false,
|
56 |
-
"compile_blocks": false,
|
57 |
-
"quantize_extras": true
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-offload-1-4080.json
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"flow_quantization_dtype": "qfloat8",
|
51 |
-
"text_enc_quantization_dtype": "qint4",
|
52 |
-
"ae_quantization_dtype": "qfloat8",
|
53 |
-
"compile_extras": true,
|
54 |
-
"compile_blocks": true,
|
55 |
-
"offload_text_encoder": true,
|
56 |
-
"offload_vae": true,
|
57 |
-
"offload_flow": true
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-offload-1-4090.json
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"flow_quantization_dtype": "qfloat8",
|
51 |
-
"text_enc_quantization_dtype": "qint4",
|
52 |
-
"ae_quantization_dtype": "qfloat8",
|
53 |
-
"compile_extras": true,
|
54 |
-
"compile_blocks": true,
|
55 |
-
"offload_text_encoder": true,
|
56 |
-
"offload_vae": true,
|
57 |
-
"offload_flow": false
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-offload.json
DELETED
@@ -1,58 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir/flux1-dev.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"flow_quantization_dtype": "qfloat8",
|
51 |
-
"text_enc_quantization_dtype": "qint4",
|
52 |
-
"ae_quantization_dtype": "qfloat8",
|
53 |
-
"compile_extras": false,
|
54 |
-
"compile_blocks": false,
|
55 |
-
"offload_text_encoder": true,
|
56 |
-
"offload_vae": true,
|
57 |
-
"offload_flow": true
|
58 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev-prequant.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-dev",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": true
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/flux-fp16-acc/flux_fp8.safetensors",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:1",
|
45 |
-
"ae_device": "cuda:1",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"text_enc_quantization_dtype": "qfloat8",
|
51 |
-
"compile_extras": false,
|
52 |
-
"compile_blocks": false,
|
53 |
-
"prequantized_flow": true,
|
54 |
-
"offload_ae": false,
|
55 |
-
"offload_text_enc": false,
|
56 |
-
"offload_flow": false
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configs/config-dev.json
CHANGED
@@ -34,16 +34,16 @@
|
|
34 |
"scale_factor": 0.3611,
|
35 |
"shift_factor": 0.1159
|
36 |
},
|
37 |
-
"ckpt_path": "
|
38 |
-
"ae_path": "
|
39 |
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
-
"repo_flow": "flux1-dev.
|
41 |
-
"repo_ae": "ae.
|
42 |
"text_enc_max_length": 512,
|
43 |
-
"text_enc_path": "
|
44 |
-
"text_enc_device": "cuda
|
45 |
-
"ae_device": "cuda
|
46 |
-
"flux_device": "cuda
|
47 |
"flow_dtype": "float16",
|
48 |
"ae_dtype": "bfloat16",
|
49 |
"text_enc_dtype": "bfloat16",
|
@@ -54,4 +54,4 @@
|
|
54 |
"offload_ae": false,
|
55 |
"offload_text_enc": false,
|
56 |
"offload_flow": false
|
57 |
-
}
|
|
|
34 |
"scale_factor": 0.3611,
|
35 |
"shift_factor": 0.1159
|
36 |
},
|
37 |
+
"ckpt_path": "flux1-dev.safetensors",
|
38 |
+
"ae_path": "ae.safetensors",
|
39 |
"repo_id": "black-forest-labs/FLUX.1-dev",
|
40 |
+
"repo_flow": "flux1-dev.safetensors",
|
41 |
+
"repo_ae": "ae.safetensors",
|
42 |
"text_enc_max_length": 512,
|
43 |
+
"text_enc_path": "t5-v1_1-xxl-encoder-bf16",
|
44 |
+
"text_enc_device": "cuda",
|
45 |
+
"ae_device": "cuda",
|
46 |
+
"flux_device": "cuda",
|
47 |
"flow_dtype": "float16",
|
48 |
"ae_dtype": "bfloat16",
|
49 |
"text_enc_dtype": "bfloat16",
|
|
|
54 |
"offload_ae": false,
|
55 |
"offload_text_enc": false,
|
56 |
"offload_flow": false
|
57 |
+
}
|
configs/config-schnell-cuda0.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"version": "flux-schnell",
|
3 |
-
"params": {
|
4 |
-
"in_channels": 64,
|
5 |
-
"vec_in_dim": 768,
|
6 |
-
"context_in_dim": 4096,
|
7 |
-
"hidden_size": 3072,
|
8 |
-
"mlp_ratio": 4.0,
|
9 |
-
"num_heads": 24,
|
10 |
-
"depth": 19,
|
11 |
-
"depth_single_blocks": 38,
|
12 |
-
"axes_dim": [
|
13 |
-
16,
|
14 |
-
56,
|
15 |
-
56
|
16 |
-
],
|
17 |
-
"theta": 10000,
|
18 |
-
"qkv_bias": true,
|
19 |
-
"guidance_embed": false
|
20 |
-
},
|
21 |
-
"ae_params": {
|
22 |
-
"resolution": 256,
|
23 |
-
"in_channels": 3,
|
24 |
-
"ch": 128,
|
25 |
-
"out_ch": 3,
|
26 |
-
"ch_mult": [
|
27 |
-
1,
|
28 |
-
2,
|
29 |
-
4,
|
30 |
-
4
|
31 |
-
],
|
32 |
-
"num_res_blocks": 2,
|
33 |
-
"z_channels": 16,
|
34 |
-
"scale_factor": 0.3611,
|
35 |
-
"shift_factor": 0.1159
|
36 |
-
},
|
37 |
-
"ckpt_path": "/big/generator-ui/flux-testing/flux/model-dir-schnell/flux1-schnell.sft",
|
38 |
-
"ae_path": "/big/generator-ui/flux-testing/flux/model-dir-schnell/ae.sft",
|
39 |
-
"repo_id": "black-forest-labs/FLUX.1-schnell",
|
40 |
-
"repo_flow": "flux1-schnell.sft",
|
41 |
-
"repo_ae": "ae.sft",
|
42 |
-
"text_enc_max_length": 256,
|
43 |
-
"text_enc_path": "city96/t5-v1_1-xxl-encoder-bf16",
|
44 |
-
"text_enc_device": "cuda:0",
|
45 |
-
"ae_device": "cuda:0",
|
46 |
-
"flux_device": "cuda:0",
|
47 |
-
"flow_dtype": "float16",
|
48 |
-
"ae_dtype": "bfloat16",
|
49 |
-
"text_enc_dtype": "bfloat16",
|
50 |
-
"text_enc_quantization_dtype": "qfloat8",
|
51 |
-
"ae_quantization_dtype": "qfloat8",
|
52 |
-
"compile_extras": false,
|
53 |
-
"compile_blocks": false,
|
54 |
-
"offload_ae": false,
|
55 |
-
"offload_text_enc": false,
|
56 |
-
"offload_flow": false
|
57 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fireworks.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"_is_flumina_model": true}
|
flumina.py
ADDED
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# flumina.py
|
2 |
+
import torch
|
3 |
+
import io
|
4 |
+
import json
|
5 |
+
from fireworks.flumina import FluminaModule, main as flumina_main
|
6 |
+
from fireworks.flumina.route import post
|
7 |
+
import pydantic
|
8 |
+
from pydantic import BaseModel
|
9 |
+
from fastapi import Header
|
10 |
+
from fastapi.responses import Response
|
11 |
+
import math
|
12 |
+
import os
|
13 |
+
import re
|
14 |
+
import PIL.Image as Image
|
15 |
+
from typing import Optional, Set, Tuple
|
16 |
+
|
17 |
+
from flux_pipeline import FluxPipeline
|
18 |
+
from util import load_config, ModelVersion
|
19 |
+
|
20 |
+
# Util
|
21 |
+
def _aspect_ratio_to_width_height(aspect_ratio: str) -> Tuple[int, int]:
|
22 |
+
"""
|
23 |
+
Convert specified aspect ratio to a height/width pair.
|
24 |
+
"""
|
25 |
+
if ":" not in aspect_ratio:
|
26 |
+
raise ValueError(
|
27 |
+
f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be in w:h format, e.g. 16:9"
|
28 |
+
)
|
29 |
+
|
30 |
+
w, h = aspect_ratio.split(":")
|
31 |
+
try:
|
32 |
+
w, h = int(w), int(h)
|
33 |
+
except ValueError:
|
34 |
+
raise ValueError(
|
35 |
+
f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be in w:h format, e.g. 16:9"
|
36 |
+
)
|
37 |
+
|
38 |
+
valid_aspect_ratios = [
|
39 |
+
(1, 1),
|
40 |
+
(21, 9),
|
41 |
+
(16, 9),
|
42 |
+
(3, 2),
|
43 |
+
(5, 4),
|
44 |
+
(4, 5),
|
45 |
+
(2, 3),
|
46 |
+
(9, 16),
|
47 |
+
(9, 21),
|
48 |
+
]
|
49 |
+
if (w, h) not in valid_aspect_ratios:
|
50 |
+
raise ValueError(
|
51 |
+
f"Invalid aspect ratio: {aspect_ratio}. Aspect ratio must be one of {valid_aspect_ratios}"
|
52 |
+
)
|
53 |
+
|
54 |
+
# We consider megapixel not 10^6 pixels but 2^20 (1024x1024) pixels
|
55 |
+
TARGET_SIZE_MP = 1
|
56 |
+
target_size = TARGET_SIZE_MP * 2**20
|
57 |
+
|
58 |
+
width = math.sqrt(target_size / (w * h)) * w
|
59 |
+
height = math.sqrt(target_size / (w * h)) * h
|
60 |
+
|
61 |
+
PAD_MULTIPLE = 64
|
62 |
+
|
63 |
+
if PAD_MULTIPLE:
|
64 |
+
width = width // PAD_MULTIPLE * PAD_MULTIPLE
|
65 |
+
height = height // PAD_MULTIPLE * PAD_MULTIPLE
|
66 |
+
|
67 |
+
return int(width), int(height)
|
68 |
+
|
69 |
+
|
70 |
+
def encode_image(
|
71 |
+
image: Image.Image, mime_type: str, jpeg_quality: int = 95
|
72 |
+
) -> bytes:
|
73 |
+
buffered = io.BytesIO()
|
74 |
+
if mime_type == "image/jpeg":
|
75 |
+
if jpeg_quality < 0 or jpeg_quality > 100:
|
76 |
+
raise ValueError(
|
77 |
+
f"jpeg_quality must be between 0 and 100, not {jpeg_quality}"
|
78 |
+
)
|
79 |
+
image.save(buffered, format="JPEG", quality=jpeg_quality)
|
80 |
+
elif mime_type == "image/png":
|
81 |
+
image.save(buffered, format="PNG")
|
82 |
+
else:
|
83 |
+
raise ValueError(f"invalid mime_type {mime_type}")
|
84 |
+
return buffered.getvalue()
|
85 |
+
|
86 |
+
|
87 |
+
def parse_accept_header(accept: str) -> str:
|
88 |
+
# Split the string into the comma-separated components
|
89 |
+
parts = accept.split(",")
|
90 |
+
weighted_types = []
|
91 |
+
|
92 |
+
for part in parts:
|
93 |
+
# Use a regular expression to extract the media type and the optional q-factor
|
94 |
+
match = re.match(
|
95 |
+
r"(?P<media_type>[^;]+)(;q=(?P<q_factor>\d+(\.\d+)?))?", part.strip()
|
96 |
+
)
|
97 |
+
if match:
|
98 |
+
media_type = match.group("media_type")
|
99 |
+
q_factor = (
|
100 |
+
float(match.group("q_factor")) if match.group("q_factor") else 1.0
|
101 |
+
)
|
102 |
+
weighted_types.append((media_type, q_factor))
|
103 |
+
else:
|
104 |
+
raise ValueError(f"Malformed Accept header value: {part.strip()}")
|
105 |
+
|
106 |
+
# Sort the media types by q-factor, descending
|
107 |
+
sorted_types = sorted(weighted_types, key=lambda x: x[1], reverse=True)
|
108 |
+
|
109 |
+
for media_type, _ in sorted_types:
|
110 |
+
if media_type in {"image/jpeg", "image/png"}:
|
111 |
+
return media_type
|
112 |
+
|
113 |
+
raise ValueError(f"Accept header did not include ones of supported MIME types: image/jpeg, image/png")
|
114 |
+
|
115 |
+
|
116 |
+
# Define request and response schemata
|
117 |
+
class Text2ImageRequest(BaseModel):
|
118 |
+
prompt: str
|
119 |
+
aspect_ratio: str = "16:9"
|
120 |
+
guidance_scale: float = 3.5
|
121 |
+
num_inference_steps: int = 30
|
122 |
+
seed: int = 0
|
123 |
+
|
124 |
+
|
125 |
+
class Error(BaseModel):
|
126 |
+
object: str = "error"
|
127 |
+
type: str = "invalid_request_error"
|
128 |
+
message: str
|
129 |
+
|
130 |
+
|
131 |
+
class ErrorResponse(BaseModel):
|
132 |
+
error: Error = pydantic.Field(default_factory=Error)
|
133 |
+
|
134 |
+
|
135 |
+
class BillingInfo(BaseModel):
|
136 |
+
steps: int
|
137 |
+
height: int
|
138 |
+
width: int
|
139 |
+
is_control_net: bool = False
|
140 |
+
|
141 |
+
|
142 |
+
class FluminaModule(FluminaModule):
|
143 |
+
def __init__(self):
|
144 |
+
super().__init__()
|
145 |
+
|
146 |
+
# Read configuration from config.json
|
147 |
+
with open('config.json', 'r') as f:
|
148 |
+
config_data = json.load(f)
|
149 |
+
|
150 |
+
# Now, we need to construct the config and load the model
|
151 |
+
if 'config_path' in config_data:
|
152 |
+
self.pipeline = FluxPipeline.load_pipeline_from_config_path(
|
153 |
+
config_data['config_path'],
|
154 |
+
flow_model_path=config_data.get('flow_model_path', None)
|
155 |
+
)
|
156 |
+
else:
|
157 |
+
model_version = (
|
158 |
+
ModelVersion.flux_dev
|
159 |
+
if config_data.get('model_version', 'flux-dev') == "flux-dev"
|
160 |
+
else ModelVersion.flux_schnell
|
161 |
+
)
|
162 |
+
config = load_config(
|
163 |
+
model_version,
|
164 |
+
flux_path=config_data.get('flow_model_path', None),
|
165 |
+
flux_device=config_data.get('flux_device', 'cuda:0'),
|
166 |
+
ae_path=config_data.get('autoencoder_path', None),
|
167 |
+
ae_device=config_data.get('autoencoder_device', 'cuda:0'),
|
168 |
+
text_enc_path=config_data.get('text_enc_path', None),
|
169 |
+
text_enc_device=config_data.get('text_enc_device', 'cuda:0'),
|
170 |
+
flow_dtype="float16",
|
171 |
+
text_enc_dtype="bfloat16",
|
172 |
+
ae_dtype="bfloat16",
|
173 |
+
num_to_quant=config_data.get('num_to_quant', 20),
|
174 |
+
compile_extras=config_data.get('compile', False),
|
175 |
+
compile_blocks=config_data.get('compile', False),
|
176 |
+
quant_text_enc=(
|
177 |
+
None
|
178 |
+
if config_data.get('quant_text_enc', 'qfloat8') == "bf16"
|
179 |
+
else config_data.get('quant_text_enc', 'qfloat8')
|
180 |
+
),
|
181 |
+
quant_ae=config_data.get('quant_ae', False),
|
182 |
+
offload_flow=config_data.get('offload_flow', False),
|
183 |
+
offload_ae=config_data.get('offload_ae', True),
|
184 |
+
offload_text_enc=config_data.get('offload_text_enc', True),
|
185 |
+
prequantized_flow=config_data.get('prequantized_flow', False),
|
186 |
+
quantize_modulation=config_data.get('quantize_modulation', True),
|
187 |
+
quantize_flow_embedder_layers=config_data.get(
|
188 |
+
'quantize_flow_embedder_layers', False
|
189 |
+
),
|
190 |
+
)
|
191 |
+
self.pipeline = FluxPipeline.load_pipeline_from_config(config)
|
192 |
+
|
193 |
+
# Initialize LoRA adapters
|
194 |
+
self.lora_adapters: Set[str] = set()
|
195 |
+
self.active_lora_adapter: Optional[str] = None
|
196 |
+
self._test_return_sync_response = False
|
197 |
+
|
198 |
+
def _error_response(self, code: int, message: str) -> Response:
|
199 |
+
response_json = ErrorResponse(
|
200 |
+
error=Error(message=message),
|
201 |
+
).json()
|
202 |
+
if self._test_return_sync_response:
|
203 |
+
return response_json
|
204 |
+
else:
|
205 |
+
return Response(
|
206 |
+
response_json,
|
207 |
+
status_code=code,
|
208 |
+
media_type="application/json",
|
209 |
+
)
|
210 |
+
|
211 |
+
def _image_response(
|
212 |
+
self, image_bytes: bytes, mime_type: str, billing_info: BillingInfo
|
213 |
+
):
|
214 |
+
if self._test_return_sync_response:
|
215 |
+
return image_bytes
|
216 |
+
else:
|
217 |
+
headers = {'Fireworks-Billing-Properties': billing_info.json()}
|
218 |
+
return Response(
|
219 |
+
image_bytes, status_code=200, media_type=mime_type, headers=headers
|
220 |
+
)
|
221 |
+
|
222 |
+
@post('/text_to_image')
|
223 |
+
async def text_to_image(
|
224 |
+
self,
|
225 |
+
body: Text2ImageRequest,
|
226 |
+
accept: str = Header("image/jpeg"),
|
227 |
+
):
|
228 |
+
mime_type = parse_accept_header(accept)
|
229 |
+
width, height = _aspect_ratio_to_width_height(body.aspect_ratio)
|
230 |
+
img_bio = self.pipeline.generate(
|
231 |
+
prompt=body.prompt,
|
232 |
+
height=height,
|
233 |
+
width=width,
|
234 |
+
guidance=body.guidance_scale,
|
235 |
+
num_steps=body.num_inference_steps,
|
236 |
+
seed=body.seed,
|
237 |
+
)
|
238 |
+
|
239 |
+
billing_info = BillingInfo(
|
240 |
+
steps=body.num_inference_steps,
|
241 |
+
height=height,
|
242 |
+
width=width,
|
243 |
+
)
|
244 |
+
return self._image_response(img_bio.getvalue(), mime_type, billing_info)
|
245 |
+
|
246 |
+
@property
|
247 |
+
def supported_addon_types(self):
|
248 |
+
return ['lora']
|
249 |
+
|
250 |
+
# Addon interface methods adjusted to remove ControlNet support
|
251 |
+
def load_addon(
|
252 |
+
self,
|
253 |
+
addon_account_id: str,
|
254 |
+
addon_model_id: str,
|
255 |
+
addon_type: str,
|
256 |
+
addon_data_path: os.PathLike,
|
257 |
+
):
|
258 |
+
if addon_type not in self.supported_addon_types:
|
259 |
+
raise ValueError(
|
260 |
+
f"Invalid addon type {addon_type}. Supported types: {self.supported_addon_types}"
|
261 |
+
)
|
262 |
+
|
263 |
+
qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
|
264 |
+
|
265 |
+
if addon_type == 'lora':
|
266 |
+
self.pipeline.load_lora_weights(addon_data_path, adapter_name=qualname)
|
267 |
+
self.lora_adapters.add(qualname)
|
268 |
+
else:
|
269 |
+
raise NotImplementedError(
|
270 |
+
f'Addon support for type {addon_type} not implemented'
|
271 |
+
)
|
272 |
+
|
273 |
+
def unload_addon(
|
274 |
+
self, addon_account_id: str, addon_model_id: str, addon_type: str
|
275 |
+
):
|
276 |
+
qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
|
277 |
+
|
278 |
+
if addon_type == 'lora':
|
279 |
+
assert qualname in self.lora_adapters
|
280 |
+
self.pipeline.delete_adapters([qualname])
|
281 |
+
self.lora_adapters.remove(qualname)
|
282 |
+
else:
|
283 |
+
raise NotImplementedError(
|
284 |
+
f'Addon support for type {addon_type} not implemented'
|
285 |
+
)
|
286 |
+
|
287 |
+
def activate_addon(self, addon_account_id: str, addon_model_id: str):
|
288 |
+
qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
|
289 |
+
|
290 |
+
if qualname in self.lora_adapters:
|
291 |
+
if self.active_lora_adapter is not None:
|
292 |
+
raise ValueError(
|
293 |
+
f"LoRA adapter {self.active_lora_adapter} already active. Multi-LoRA not yet supported"
|
294 |
+
)
|
295 |
+
|
296 |
+
self.active_lora_adapter = qualname
|
297 |
+
return
|
298 |
+
|
299 |
+
raise ValueError(f"Unknown addon {qualname}")
|
300 |
+
|
301 |
+
def deactivate_addon(self, addon_account_id: str, addon_model_id: str):
|
302 |
+
qualname = f"accounts/{addon_account_id}/models/{addon_model_id}"
|
303 |
+
|
304 |
+
if self.active_lora_adapter == qualname:
|
305 |
+
self.active_lora_adapter = None
|
306 |
+
else:
|
307 |
+
raise AssertionError(f'Addon {qualname} not loaded!')
|
308 |
+
|
309 |
+
|
310 |
+
if __name__ == "__flumina_main__":
|
311 |
+
f = FluminaModule()
|
312 |
+
flumina_main(f)
|
313 |
+
|
314 |
+
if __name__ == "__main__":
|
315 |
+
f = FluminaModule()
|
316 |
+
f._test_return_sync_response = True
|
317 |
+
import asyncio
|
318 |
+
out = asyncio.run(f.text_to_image(
|
319 |
+
body=Text2ImageRequest(
|
320 |
+
prompt="test"
|
321 |
+
),
|
322 |
+
accept="image/png"
|
323 |
+
))
|
324 |
+
with open("out_image.png", "wb") as f:
|
325 |
+
f.write(out)
|
326 |
+
|
requirements.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
git+https://github.com/aredden/torch-cublas-hgemm.git@master
|
2 |
einops
|
3 |
PyTurboJPEG
|
@@ -13,4 +16,4 @@ accelerate
|
|
13 |
quanto
|
14 |
pydash
|
15 |
pybase64
|
16 |
-
uvicorn
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu124
|
2 |
+
torch>=2.4
|
3 |
+
torchvision
|
4 |
git+https://github.com/aredden/torch-cublas-hgemm.git@master
|
5 |
einops
|
6 |
PyTurboJPEG
|
|
|
16 |
quanto
|
17 |
pydash
|
18 |
pybase64
|
19 |
+
uvicorn
|