diffusers-workflow 0.4.0a3__py3-none-any.whl
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.
- diffusers_workflow-0.4.0a3.dist-info/METADATA +310 -0
- diffusers_workflow-0.4.0a3.dist-info/RECORD +171 -0
- diffusers_workflow-0.4.0a3.dist-info/WHEEL +5 -0
- diffusers_workflow-0.4.0a3.dist-info/entry_points.txt +6 -0
- diffusers_workflow-0.4.0a3.dist-info/licenses/LICENSE +201 -0
- diffusers_workflow-0.4.0a3.dist-info/top_level.txt +1 -0
- dw/__init__.py +353 -0
- dw/arguments.py +906 -0
- dw/cache_blocks.json +16 -0
- dw/cache_blocks.py +145 -0
- dw/community_pipelines/pipeline_flux_rf_inversion.py +1184 -0
- dw/events.py +78 -0
- dw/hub_cache.py +289 -0
- dw/introspection.py +458 -0
- dw/log_setup.py +45 -0
- dw/pipeline_processors/chain.py +750 -0
- dw/pipeline_processors/config_objects.py +235 -0
- dw/pipeline_processors/pipeline.py +1687 -0
- dw/pipeline_processors/remote.py +18 -0
- dw/previous_results.py +259 -0
- dw/prompt_weighting.py +378 -0
- dw/repl.py +298 -0
- dw/repl_commands.py +808 -0
- dw/repl_worker.py +129 -0
- dw/result.py +850 -0
- dw/run.py +92 -0
- dw/schema.py +24 -0
- dw/security.py +379 -0
- dw/serve.py +70 -0
- dw/server/__init__.py +2 -0
- dw/server/app.py +588 -0
- dw/server/jobs.py +547 -0
- dw/server/ui/assets/abap-08VXUWAP.js +1 -0
- dw/server/ui/assets/apex-BWPQTe0t.js +1 -0
- dw/server/ui/assets/azcli-Bc_sGQ0U.js +1 -0
- dw/server/ui/assets/bat-i0X4ZdIN.js +1 -0
- dw/server/ui/assets/bicep-B5-_aFwp.js +2 -0
- dw/server/ui/assets/cameligo-DMUM7wLl.js +1 -0
- dw/server/ui/assets/clojure-Cm7r79vr.js +1 -0
- dw/server/ui/assets/codicon-Brq4_Ui5.ttf +0 -0
- dw/server/ui/assets/coffee-Ba7i2nA0.js +1 -0
- dw/server/ui/assets/cpp-C7h46wYY.js +1 -0
- dw/server/ui/assets/csharp-BKxtCVv1.js +1 -0
- dw/server/ui/assets/csp-bTuwJoIa.js +1 -0
- dw/server/ui/assets/css-DIMkf-bt.js +3 -0
- dw/server/ui/assets/css.worker-B3ciXF_0.js +93 -0
- dw/server/ui/assets/cssMode-CEh6hWi2.js +1 -0
- dw/server/ui/assets/cypher-CVaqCwHa.js +1 -0
- dw/server/ui/assets/dart-onAF5SnQ.js +1 -0
- dw/server/ui/assets/dockerfile-DZFCIeNp.js +1 -0
- dw/server/ui/assets/ecl-D05T4iGw.js +1 -0
- dw/server/ui/assets/editor-jjEx9u7D.css +1 -0
- dw/server/ui/assets/editor.api-CExg3_mM.js +847 -0
- dw/server/ui/assets/editor.worker-q-txB4vs.js +30 -0
- dw/server/ui/assets/elixir-6RTg0lbw.js +1 -0
- dw/server/ui/assets/flow9-C5_-GSwl.js +1 -0
- dw/server/ui/assets/freemarker2-DH6orYh2.js +3 -0
- dw/server/ui/assets/fsharp-C8Ef5oNN.js +1 -0
- dw/server/ui/assets/go-C-y9NEjX.js +1 -0
- dw/server/ui/assets/graphql-fmXr3nnJ.js +1 -0
- dw/server/ui/assets/handlebars-CbrMVW4Q.js +1 -0
- dw/server/ui/assets/hcl-CpzslTdj.js +1 -0
- dw/server/ui/assets/html-YDNPZw2M.js +1 -0
- dw/server/ui/assets/html.worker-C93Ht9o9.js +506 -0
- dw/server/ui/assets/htmlMode-B_zSGWO2.js +1 -0
- dw/server/ui/assets/index-B7-VcYS-.css +1 -0
- dw/server/ui/assets/index-D_EiPU3b.js +13 -0
- dw/server/ui/assets/ini-sBoK_t0W.js +1 -0
- dw/server/ui/assets/java-BEtHBSE6.js +1 -0
- dw/server/ui/assets/javascript-dYuBvioq.js +1 -0
- dw/server/ui/assets/json.worker-B2V3pomh.js +62 -0
- dw/server/ui/assets/jsonMode-CUqLM39V.js +7 -0
- dw/server/ui/assets/julia-Bri6UV-V.js +1 -0
- dw/server/ui/assets/kotlin-BOotOW0E.js +1 -0
- dw/server/ui/assets/less-B9JPFI3C.js +2 -0
- dw/server/ui/assets/lexon-CfSJPG6W.js +1 -0
- dw/server/ui/assets/liquid-D6vxBzMv.js +1 -0
- dw/server/ui/assets/lspLanguageFeatures-1WJ2palX.js +4 -0
- dw/server/ui/assets/lua-CsQS60Ue.js +1 -0
- dw/server/ui/assets/m3-D-oSqn_W.js +1 -0
- dw/server/ui/assets/markdown-Cimd5fb3.js +1 -0
- dw/server/ui/assets/mdx-SHQb6vmD.js +1 -0
- dw/server/ui/assets/mips-CIPQ_RoX.js +1 -0
- dw/server/ui/assets/monaco--ixms01u.css +1 -0
- dw/server/ui/assets/monaco-CP-s5rcP.js +56 -0
- dw/server/ui/assets/msdax-DauUninz.js +1 -0
- dw/server/ui/assets/mysql-SOo6toE5.js +1 -0
- dw/server/ui/assets/objective-c-FvmIjYaQ.js +1 -0
- dw/server/ui/assets/pascal-DrH0SRf2.js +1 -0
- dw/server/ui/assets/pascaligo-D-ptJ9y-.js +1 -0
- dw/server/ui/assets/perl-oz_6vUea.js +1 -0
- dw/server/ui/assets/pgsql-DTj74zXo.js +1 -0
- dw/server/ui/assets/php-nr791fC2.js +1 -0
- dw/server/ui/assets/pla-CopQ2nXW.js +1 -0
- dw/server/ui/assets/postiats-43DmfD33.js +1 -0
- dw/server/ui/assets/powerquery-D3hlyOfw.js +1 -0
- dw/server/ui/assets/powershell-DmHpPYUd.js +1 -0
- dw/server/ui/assets/protobuf-C531GsRP.js +2 -0
- dw/server/ui/assets/pug-Z5eAx3Zn.js +1 -0
- dw/server/ui/assets/python-x0_EGHq9.js +1 -0
- dw/server/ui/assets/qsharp-DkqhCAOL.js +1 -0
- dw/server/ui/assets/r-BwWrilGY.js +1 -0
- dw/server/ui/assets/razor-BZC4LQDP.js +1 -0
- dw/server/ui/assets/redis-ClamHrr6.js +1 -0
- dw/server/ui/assets/redshift-DT7zqm-g.js +1 -0
- dw/server/ui/assets/restructuredtext-BYgofb2h.js +1 -0
- dw/server/ui/assets/ruby-DezsRK8O.js +1 -0
- dw/server/ui/assets/rust-DdL9SqIa.js +1 -0
- dw/server/ui/assets/sb-CcwsVR0C.js +1 -0
- dw/server/ui/assets/scala-DHpiXF5c.js +1 -0
- dw/server/ui/assets/scheme-BeGwcela.js +1 -0
- dw/server/ui/assets/scss-gp-XZpBa.js +3 -0
- dw/server/ui/assets/shell-CC2rA5mh.js +1 -0
- dw/server/ui/assets/solidity-BEEn4gHE.js +1 -0
- dw/server/ui/assets/sophia-CRfGWb83.js +1 -0
- dw/server/ui/assets/sparql-D_Lu-MrJ.js +1 -0
- dw/server/ui/assets/sql-NEE52Syq.js +1 -0
- dw/server/ui/assets/st-DbInun42.js +1 -0
- dw/server/ui/assets/swift-Bxkupp3x.js +1 -0
- dw/server/ui/assets/systemverilog-Bz4Y3fRF.js +1 -0
- dw/server/ui/assets/tcl-DISqw1ZD.js +1 -0
- dw/server/ui/assets/ts.worker-D7T1-Ig5.js +67738 -0
- dw/server/ui/assets/tsMode-BTfA6SbD.js +11 -0
- dw/server/ui/assets/twig-De2hgUGE.js +1 -0
- dw/server/ui/assets/typescript-CWA4MsNk.js +1 -0
- dw/server/ui/assets/typespec-B8J7ngcE.js +1 -0
- dw/server/ui/assets/vb-DV3o63ZY.js +1 -0
- dw/server/ui/assets/wgsl-DpFanUEy.js +298 -0
- dw/server/ui/assets/workers-CWU0uvj5.js +1 -0
- dw/server/ui/assets/xml-KmfTm3rg.js +1 -0
- dw/server/ui/assets/yaml-nFO_dDS6.js +1 -0
- dw/server/ui/index.html +17 -0
- dw/settings.py +77 -0
- dw/step.py +132 -0
- dw/tasks/audio_utils.py +266 -0
- dw/tasks/background_remover.py +43 -0
- dw/tasks/borders.py +113 -0
- dw/tasks/concat_videos.py +80 -0
- dw/tasks/depth_estimator.py +54 -0
- dw/tasks/diffusion_upscale.py +109 -0
- dw/tasks/format_messages.py +24 -0
- dw/tasks/gather.py +139 -0
- dw/tasks/image_to_text.py +43 -0
- dw/tasks/image_utils.py +661 -0
- dw/tasks/interpolate_frames.py +227 -0
- dw/tasks/model_cache.py +39 -0
- dw/tasks/pair_audio.py +58 -0
- dw/tasks/qr_code.py +19 -0
- dw/tasks/restore_faces.py +175 -0
- dw/tasks/rife_model.py +192 -0
- dw/tasks/segment.py +121 -0
- dw/tasks/task.py +474 -0
- dw/tasks/tensor_image.py +57 -0
- dw/tasks/text_generation.py +168 -0
- dw/tasks/text_sections.py +80 -0
- dw/tasks/upscale.py +203 -0
- dw/tasks/video_utils.py +154 -0
- dw/tasks/zoe_depth.py +71 -0
- dw/teacache.py +376 -0
- dw/teacache_models.json +99 -0
- dw/test.py +29 -0
- dw/type_helpers.py +68 -0
- dw/validate.py +43 -0
- dw/variables.py +153 -0
- dw/worker.py +517 -0
- dw/workflow.py +553 -0
- dw/workflow_schema.json +1157 -0
- dw/workflows/augment_prompt.json +65 -0
- dw/workflows/describe_image.json +58 -0
- dw/workflows/h3_context_ir.json +57 -0
- dw/workflows/test.json +31 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import torch
|
|
3
|
+
|
|
4
|
+
logger = logging.getLogger("dw")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_quantization_configuration(configuration):
|
|
8
|
+
"""
|
|
9
|
+
Get the appropriate quantization configuration based on the input configuration.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
configuration: Dictionary containing quantization settings
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
Quantization configuration object or None if no valid configuration found
|
|
16
|
+
"""
|
|
17
|
+
logger.debug(f"Processing quantization configuration: {configuration}")
|
|
18
|
+
|
|
19
|
+
quantization_config = configuration.get("quantization_config", None)
|
|
20
|
+
if quantization_config is None:
|
|
21
|
+
logger.debug("No quantization configuration found")
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
return create_quantization_config(quantization_config)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def create_quantization_config(quantization_config):
|
|
28
|
+
"""
|
|
29
|
+
Create a quantization configuration object from its definition.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
quantization_config: Dictionary holding the config type and its arguments
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Quantization configuration object
|
|
36
|
+
"""
|
|
37
|
+
logger.info("Loading quantization configuration...")
|
|
38
|
+
logger.debug(f"Quantization parameters: {quantization_config}")
|
|
39
|
+
try:
|
|
40
|
+
quantization_config_type = quantization_config["configuration"]["config_type"]
|
|
41
|
+
# Some quantization configs (e.g. TorchAoConfig) require argument values
|
|
42
|
+
# to be instances rather than classes. realize_args converts *_type keys to
|
|
43
|
+
# classes; instantiate them here with no args so callers can write e.g.
|
|
44
|
+
# "quant_type": "torchao.quantization.Int8WeightOnlyConfig" in JSON.
|
|
45
|
+
args = {
|
|
46
|
+
k: v() if isinstance(v, type) else v
|
|
47
|
+
for k, v in quantization_config["arguments"].items()
|
|
48
|
+
}
|
|
49
|
+
return quantization_config_type(**args)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logger.error(f"Failed to create quantization_config: {str(e)}", exc_info=True)
|
|
52
|
+
raise
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_load_components_arguments(configuration):
|
|
56
|
+
"""
|
|
57
|
+
Get the arguments for a modular pipeline's load_components(), with any quantization
|
|
58
|
+
configurations built from their definitions.
|
|
59
|
+
|
|
60
|
+
load_components() hands its arguments to each component's from_pretrained, looking a
|
|
61
|
+
dict value up under the component's own name - so quantization is declared per
|
|
62
|
+
component, and a component the map does not name is loaded unquantized.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
configuration: Pipeline configuration dictionary
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
Dictionary of arguments for load_components(), or None when the pipeline does not
|
|
69
|
+
load its components separately
|
|
70
|
+
"""
|
|
71
|
+
load_components_arguments = configuration.get("load_components", None)
|
|
72
|
+
if load_components_arguments is None:
|
|
73
|
+
return None
|
|
74
|
+
|
|
75
|
+
load_components_arguments = dict(load_components_arguments)
|
|
76
|
+
quantization_configs = load_components_arguments.get("quantization_config", None)
|
|
77
|
+
if quantization_configs is not None:
|
|
78
|
+
logger.debug(
|
|
79
|
+
f"Building quantization configurations for: {list(quantization_configs.keys())}"
|
|
80
|
+
)
|
|
81
|
+
load_components_arguments["quantization_config"] = {
|
|
82
|
+
component_name: create_quantization_config(definition)
|
|
83
|
+
for component_name, definition in quantization_configs.items()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return load_components_arguments
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def get_group_offload_configuration(configuration, default_device):
|
|
90
|
+
"""
|
|
91
|
+
Get the appropriate group offload configuration based on the input configuration.
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
configuration: Dictionary containing group offload settings
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
Group offload configuration object or None if no valid configuration found
|
|
98
|
+
https://huggingface.co/docs/diffusers/optimization/memory#group-offloading
|
|
99
|
+
"""
|
|
100
|
+
logger.debug(f"Processing group offload configuration: {configuration}")
|
|
101
|
+
|
|
102
|
+
group_offload_config = configuration.get("group_offload", None)
|
|
103
|
+
if group_offload_config is not None:
|
|
104
|
+
logger.info("Loading group offload configuration...")
|
|
105
|
+
logger.debug(f"Group offload parameters: {group_offload_config}")
|
|
106
|
+
# replace device references with device objects
|
|
107
|
+
group_offload_config["onload_device"] = torch.device(
|
|
108
|
+
group_offload_config.get("onload_device", default_device)
|
|
109
|
+
)
|
|
110
|
+
group_offload_config["offload_device"] = torch.device(
|
|
111
|
+
group_offload_config.get("offload_device", "cpu")
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
return group_offload_config
|
|
115
|
+
|
|
116
|
+
logger.debug("No group offload configuration found")
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _resolve_mag_ratios(mag_ratios):
|
|
121
|
+
"""Resolve a mag_ratios declaration into what MagCacheConfig accepts.
|
|
122
|
+
|
|
123
|
+
The ratios are checkpoint-dependent, so a workflow either spells them out as
|
|
124
|
+
a per-step array or names one of the presets diffusers ships in
|
|
125
|
+
diffusers.hooks.mag_cache - "flux" resolving to FLUX_MAG_RATIOS. The lookup
|
|
126
|
+
is dynamic, so a preset added by a later diffusers release works here with no
|
|
127
|
+
change, the same way quantization config_type does.
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
mag_ratios: A preset name, or a list of per-step ratios
|
|
131
|
+
|
|
132
|
+
Returns:
|
|
133
|
+
The ratios to hand to MagCacheConfig
|
|
134
|
+
"""
|
|
135
|
+
if not isinstance(mag_ratios, str):
|
|
136
|
+
return mag_ratios
|
|
137
|
+
|
|
138
|
+
from diffusers.hooks import mag_cache
|
|
139
|
+
|
|
140
|
+
ratios = getattr(mag_cache, f"{mag_ratios.upper()}_MAG_RATIOS", None)
|
|
141
|
+
if ratios is None:
|
|
142
|
+
available = sorted(
|
|
143
|
+
name.removesuffix("_MAG_RATIOS").lower()
|
|
144
|
+
for name in dir(mag_cache)
|
|
145
|
+
if name.endswith("_MAG_RATIOS")
|
|
146
|
+
)
|
|
147
|
+
raise ValueError(
|
|
148
|
+
f"Unknown mag_ratios preset: {mag_ratios}. "
|
|
149
|
+
f"Available presets: {available}. "
|
|
150
|
+
f"A list of per-step ratios can be given instead."
|
|
151
|
+
)
|
|
152
|
+
return ratios
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
# Arguments each cache type forwards to its diffusers config, when present.
|
|
156
|
+
# Anything omitted keeps the diffusers default.
|
|
157
|
+
_MAG_CACHE_KEYS = (
|
|
158
|
+
"threshold",
|
|
159
|
+
"num_inference_steps",
|
|
160
|
+
"max_skip_steps",
|
|
161
|
+
"retention_ratio",
|
|
162
|
+
"calibrate",
|
|
163
|
+
)
|
|
164
|
+
_TAYLORSEER_CACHE_KEYS = ("cache_interval", "max_order")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def get_cache_configuration(configuration):
|
|
168
|
+
"""
|
|
169
|
+
Get the appropriate diffusers cache configuration based on the input configuration.
|
|
170
|
+
|
|
171
|
+
Args:
|
|
172
|
+
configuration: Dictionary containing cache settings
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
Cache configuration object or None if no valid configuration found
|
|
176
|
+
"""
|
|
177
|
+
logger.debug(f"Processing cache configuration: {configuration}")
|
|
178
|
+
|
|
179
|
+
cache_config = configuration.get("cache", None)
|
|
180
|
+
if cache_config is not None:
|
|
181
|
+
# Imported here rather than at module scope - the cache configs live in
|
|
182
|
+
# diffusers.hooks, which drags in peft (~2s) every startup otherwise
|
|
183
|
+
from diffusers import (
|
|
184
|
+
FirstBlockCacheConfig,
|
|
185
|
+
FasterCacheConfig,
|
|
186
|
+
MagCacheConfig,
|
|
187
|
+
TaylorSeerCacheConfig,
|
|
188
|
+
TextKVCacheConfig,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
logger.info("Loading cache configuration...")
|
|
192
|
+
logger.debug(f"Cache parameters: {cache_config}")
|
|
193
|
+
try:
|
|
194
|
+
cache_type = cache_config["type"]
|
|
195
|
+
|
|
196
|
+
if cache_type == "first_block":
|
|
197
|
+
config = FirstBlockCacheConfig(
|
|
198
|
+
threshold=cache_config.get("threshold", 0.05),
|
|
199
|
+
)
|
|
200
|
+
elif cache_type == "faster":
|
|
201
|
+
config = FasterCacheConfig()
|
|
202
|
+
elif cache_type == "text_kv":
|
|
203
|
+
config = TextKVCacheConfig()
|
|
204
|
+
elif cache_type == "mag":
|
|
205
|
+
kwargs = {
|
|
206
|
+
key: cache_config[key]
|
|
207
|
+
for key in _MAG_CACHE_KEYS
|
|
208
|
+
if key in cache_config
|
|
209
|
+
}
|
|
210
|
+
# Checkpoint-dependent, and required unless calibrating - without
|
|
211
|
+
# forwarding it MagCacheConfig rejects every configuration
|
|
212
|
+
if "mag_ratios" in cache_config:
|
|
213
|
+
kwargs["mag_ratios"] = _resolve_mag_ratios(
|
|
214
|
+
cache_config["mag_ratios"]
|
|
215
|
+
)
|
|
216
|
+
config = MagCacheConfig(**kwargs)
|
|
217
|
+
elif cache_type == "taylorseer":
|
|
218
|
+
kwargs = {
|
|
219
|
+
key: cache_config[key]
|
|
220
|
+
for key in _TAYLORSEER_CACHE_KEYS
|
|
221
|
+
if key in cache_config
|
|
222
|
+
}
|
|
223
|
+
config = TaylorSeerCacheConfig(**kwargs)
|
|
224
|
+
else:
|
|
225
|
+
raise ValueError(f"Unknown cache type: {cache_type}")
|
|
226
|
+
|
|
227
|
+
return config
|
|
228
|
+
except Exception as e:
|
|
229
|
+
logger.error(
|
|
230
|
+
f"Failed to create cache configuration: {str(e)}", exc_info=True
|
|
231
|
+
)
|
|
232
|
+
raise
|
|
233
|
+
|
|
234
|
+
logger.debug("No cache configuration found")
|
|
235
|
+
return None
|