diffusers-workflow 0.4.0__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.
Files changed (260) hide show
  1. diffusers_workflow-0.4.0.dist-info/METADATA +318 -0
  2. diffusers_workflow-0.4.0.dist-info/RECORD +260 -0
  3. diffusers_workflow-0.4.0.dist-info/WHEEL +5 -0
  4. diffusers_workflow-0.4.0.dist-info/entry_points.txt +7 -0
  5. diffusers_workflow-0.4.0.dist-info/licenses/LICENSE +201 -0
  6. diffusers_workflow-0.4.0.dist-info/top_level.txt +2 -0
  7. dw/__init__.py +440 -0
  8. dw/adapter_compatibility.py +226 -0
  9. dw/arguments.py +1231 -0
  10. dw/assessment_rules.py +159 -0
  11. dw/assets.py +130 -0
  12. dw/cache_blocks.json +16 -0
  13. dw/cache_blocks.py +146 -0
  14. dw/community_pipelines/pipeline_flux_rf_inversion.py +1184 -0
  15. dw/content_types.py +150 -0
  16. dw/dissolve_frame_errors.py +121 -0
  17. dw/docs/ACCELERATION.md +352 -0
  18. dw/docs/AGENT_LOOP.md +95 -0
  19. dw/docs/DEPENDENCIES.md +91 -0
  20. dw/docs/IP_ADAPTER.md +109 -0
  21. dw/docs/LORAS.md +131 -0
  22. dw/docs/MCP.md +517 -0
  23. dw/docs/PROMPT_WEIGHTING.md +78 -0
  24. dw/docs/QUANTIZATION.md +230 -0
  25. dw/docs/RECIPES_24GB.md +201 -0
  26. dw/docs/RELEASING.md +195 -0
  27. dw/docs/REMOTE.md +140 -0
  28. dw/docs/REPL_COMMANDS.md +121 -0
  29. dw/docs/REPL_WORKER_GUIDE.md +51 -0
  30. dw/docs/SECURITY.md +272 -0
  31. dw/docs/SECURITY_QUICKREF.md +112 -0
  32. dw/docs/SERVER.md +679 -0
  33. dw/docs/TASKS.md +1741 -0
  34. dw/docs/TESTING.md +71 -0
  35. dw/docs/WORKFLOW_GUIDE.md +2038 -0
  36. dw/docs/WORKSPACES.md +316 -0
  37. dw/download_watch.py +335 -0
  38. dw/elision.py +306 -0
  39. dw/events.py +275 -0
  40. dw/for_each.py +409 -0
  41. dw/host_memory.py +258 -0
  42. dw/host_memory_projection.py +230 -0
  43. dw/hub_cache.py +432 -0
  44. dw/introspection.py +1228 -0
  45. dw/kernel_availability.py +208 -0
  46. dw/locations.py +599 -0
  47. dw/log_setup.py +45 -0
  48. dw/loudness.py +82 -0
  49. dw/media_audio.py +217 -0
  50. dw/media_frames.py +367 -0
  51. dw/media_info.py +297 -0
  52. dw/pipeline_processors/chain.py +821 -0
  53. dw/pipeline_processors/config_objects.py +237 -0
  54. dw/pipeline_processors/pipeline.py +2297 -0
  55. dw/pipeline_processors/remote.py +46 -0
  56. dw/plan.py +920 -0
  57. dw/previous_results.py +411 -0
  58. dw/probe_paths.py +59 -0
  59. dw/prompt_schema.json +48 -0
  60. dw/prompt_weighting.py +378 -0
  61. dw/prompts.py +159 -0
  62. dw/realize.py +250 -0
  63. dw/reference_limits.py +215 -0
  64. dw/reference_names.py +125 -0
  65. dw/repl.py +338 -0
  66. dw/repl_commands.py +836 -0
  67. dw/repl_worker.py +159 -0
  68. dw/result.py +1720 -0
  69. dw/result_fps.py +82 -0
  70. dw/run.py +162 -0
  71. dw/runs.py +768 -0
  72. dw/scalar_result_validation.py +97 -0
  73. dw/schema.py +283 -0
  74. dw/security.py +1038 -0
  75. dw/select_validation.py +115 -0
  76. dw/serve.py +277 -0
  77. dw/server/__init__.py +2 -0
  78. dw/server/app.py +4586 -0
  79. dw/server/assess.py +132 -0
  80. dw/server/catalog_shape.py +487 -0
  81. dw/server/enhancers.py +129 -0
  82. dw/server/exports.py +480 -0
  83. dw/server/guides.py +257 -0
  84. dw/server/jobs.py +1561 -0
  85. dw/server/mcp_mount.py +95 -0
  86. dw/server/netinfo.py +124 -0
  87. dw/server/observed_cost.py +379 -0
  88. dw/server/sysinfo.py +71 -0
  89. dw/server/ui/assets/abap-08VXUWAP.js +1 -0
  90. dw/server/ui/assets/apex-BWPQTe0t.js +1 -0
  91. dw/server/ui/assets/azcli-Bc_sGQ0U.js +1 -0
  92. dw/server/ui/assets/bat-i0X4ZdIN.js +1 -0
  93. dw/server/ui/assets/bicep-B5-_aFwp.js +2 -0
  94. dw/server/ui/assets/cameligo-DMUM7wLl.js +1 -0
  95. dw/server/ui/assets/clojure-Cm7r79vr.js +1 -0
  96. dw/server/ui/assets/codicon-Brq4_Ui5.ttf +0 -0
  97. dw/server/ui/assets/coffee-Ba7i2nA0.js +1 -0
  98. dw/server/ui/assets/cpp-C7h46wYY.js +1 -0
  99. dw/server/ui/assets/csharp-BKxtCVv1.js +1 -0
  100. dw/server/ui/assets/csp-bTuwJoIa.js +1 -0
  101. dw/server/ui/assets/css-DIMkf-bt.js +3 -0
  102. dw/server/ui/assets/css.worker-B3ciXF_0.js +93 -0
  103. dw/server/ui/assets/cssMode-CPznxfY8.js +1 -0
  104. dw/server/ui/assets/cypher-CVaqCwHa.js +1 -0
  105. dw/server/ui/assets/dart-onAF5SnQ.js +1 -0
  106. dw/server/ui/assets/dockerfile-DZFCIeNp.js +1 -0
  107. dw/server/ui/assets/ecl-D05T4iGw.js +1 -0
  108. dw/server/ui/assets/editor-jjEx9u7D.css +1 -0
  109. dw/server/ui/assets/editor.api-CpWcotrd.js +847 -0
  110. dw/server/ui/assets/editor.worker-q-txB4vs.js +30 -0
  111. dw/server/ui/assets/elixir-6RTg0lbw.js +1 -0
  112. dw/server/ui/assets/flow9-C5_-GSwl.js +1 -0
  113. dw/server/ui/assets/freemarker2-CXtRM8N4.js +3 -0
  114. dw/server/ui/assets/fsharp-C8Ef5oNN.js +1 -0
  115. dw/server/ui/assets/go-C-y9NEjX.js +1 -0
  116. dw/server/ui/assets/graphql-fmXr3nnJ.js +1 -0
  117. dw/server/ui/assets/handlebars-N7x-6NMY.js +1 -0
  118. dw/server/ui/assets/hcl-CpzslTdj.js +1 -0
  119. dw/server/ui/assets/html-PhsdjHSr.js +1 -0
  120. dw/server/ui/assets/html.worker-C93Ht9o9.js +506 -0
  121. dw/server/ui/assets/htmlMode-Dgj0SEok.js +1 -0
  122. dw/server/ui/assets/index-3Vw6WAPW.css +1 -0
  123. dw/server/ui/assets/index-DgrYhQd9.js +43 -0
  124. dw/server/ui/assets/ini-sBoK_t0W.js +1 -0
  125. dw/server/ui/assets/java-BEtHBSE6.js +1 -0
  126. dw/server/ui/assets/javascript-BJqN9Qhv.js +1 -0
  127. dw/server/ui/assets/json.worker-B2V3pomh.js +62 -0
  128. dw/server/ui/assets/jsonMode-DbM4SWSv.js +7 -0
  129. dw/server/ui/assets/julia-Bri6UV-V.js +1 -0
  130. dw/server/ui/assets/kotlin-BOotOW0E.js +1 -0
  131. dw/server/ui/assets/less-B9JPFI3C.js +2 -0
  132. dw/server/ui/assets/lexon-CfSJPG6W.js +1 -0
  133. dw/server/ui/assets/liquid-BWr8lEc4.js +1 -0
  134. dw/server/ui/assets/lspLanguageFeatures-C1iGuDyZ.js +4 -0
  135. dw/server/ui/assets/lua-CsQS60Ue.js +1 -0
  136. dw/server/ui/assets/m3-D-oSqn_W.js +1 -0
  137. dw/server/ui/assets/markdown-Cimd5fb3.js +1 -0
  138. dw/server/ui/assets/mdx-DAdMi_0p.js +1 -0
  139. dw/server/ui/assets/mips-CIPQ_RoX.js +1 -0
  140. dw/server/ui/assets/monaco--ixms01u.css +1 -0
  141. dw/server/ui/assets/monaco-BGCeEqaw.js +56 -0
  142. dw/server/ui/assets/msdax-DauUninz.js +1 -0
  143. dw/server/ui/assets/mysql-SOo6toE5.js +1 -0
  144. dw/server/ui/assets/objective-c-FvmIjYaQ.js +1 -0
  145. dw/server/ui/assets/pascal-DrH0SRf2.js +1 -0
  146. dw/server/ui/assets/pascaligo-D-ptJ9y-.js +1 -0
  147. dw/server/ui/assets/perl-oz_6vUea.js +1 -0
  148. dw/server/ui/assets/pgsql-DTj74zXo.js +1 -0
  149. dw/server/ui/assets/php-nr791fC2.js +1 -0
  150. dw/server/ui/assets/pla-CopQ2nXW.js +1 -0
  151. dw/server/ui/assets/postiats-43DmfD33.js +1 -0
  152. dw/server/ui/assets/powerquery-D3hlyOfw.js +1 -0
  153. dw/server/ui/assets/powershell-DmHpPYUd.js +1 -0
  154. dw/server/ui/assets/protobuf-C531GsRP.js +2 -0
  155. dw/server/ui/assets/pug-Z5eAx3Zn.js +1 -0
  156. dw/server/ui/assets/python-Bcn70HdC.js +1 -0
  157. dw/server/ui/assets/qsharp-DkqhCAOL.js +1 -0
  158. dw/server/ui/assets/r-BwWrilGY.js +1 -0
  159. dw/server/ui/assets/razor-D1HmNnby.js +1 -0
  160. dw/server/ui/assets/redis-ClamHrr6.js +1 -0
  161. dw/server/ui/assets/redshift-DT7zqm-g.js +1 -0
  162. dw/server/ui/assets/restructuredtext-BYgofb2h.js +1 -0
  163. dw/server/ui/assets/ruby-DezsRK8O.js +1 -0
  164. dw/server/ui/assets/rust-DdL9SqIa.js +1 -0
  165. dw/server/ui/assets/sb-CcwsVR0C.js +1 -0
  166. dw/server/ui/assets/scala-DHpiXF5c.js +1 -0
  167. dw/server/ui/assets/scheme-BeGwcela.js +1 -0
  168. dw/server/ui/assets/scss-gp-XZpBa.js +3 -0
  169. dw/server/ui/assets/shell-CC2rA5mh.js +1 -0
  170. dw/server/ui/assets/solidity-BEEn4gHE.js +1 -0
  171. dw/server/ui/assets/sophia-CRfGWb83.js +1 -0
  172. dw/server/ui/assets/sparql-D_Lu-MrJ.js +1 -0
  173. dw/server/ui/assets/sql-NEE52Syq.js +1 -0
  174. dw/server/ui/assets/st-DbInun42.js +1 -0
  175. dw/server/ui/assets/swift-Bxkupp3x.js +1 -0
  176. dw/server/ui/assets/systemverilog-Bz4Y3fRF.js +1 -0
  177. dw/server/ui/assets/tcl-DISqw1ZD.js +1 -0
  178. dw/server/ui/assets/ts.worker-D7T1-Ig5.js +67738 -0
  179. dw/server/ui/assets/tsMode-D6u0XmOW.js +11 -0
  180. dw/server/ui/assets/twig-De2hgUGE.js +1 -0
  181. dw/server/ui/assets/typescript-BU6v-LMV.js +1 -0
  182. dw/server/ui/assets/typespec-B8J7ngcE.js +1 -0
  183. dw/server/ui/assets/vb-DV3o63ZY.js +1 -0
  184. dw/server/ui/assets/wgsl-DpFanUEy.js +298 -0
  185. dw/server/ui/assets/workers-Cn7cTUKr.js +1 -0
  186. dw/server/ui/assets/xml--0LP2Lwk.js +1 -0
  187. dw/server/ui/assets/yaml-mpBg9jnt.js +1 -0
  188. dw/server/ui/index.html +17 -0
  189. dw/server/updater.py +192 -0
  190. dw/settings.py +98 -0
  191. dw/shot_span_preflight.py +116 -0
  192. dw/shots.py +359 -0
  193. dw/slice_preflight.py +148 -0
  194. dw/step.py +187 -0
  195. dw/step_cache.py +442 -0
  196. dw/subfolders.py +107 -0
  197. dw/task_domains.py +307 -0
  198. dw/tasks/assess.py +826 -0
  199. dw/tasks/audio_transcription.py +88 -0
  200. dw/tasks/audio_utils.py +1862 -0
  201. dw/tasks/background_remover.py +43 -0
  202. dw/tasks/borders.py +113 -0
  203. dw/tasks/compose_text.py +74 -0
  204. dw/tasks/concat_videos.py +300 -0
  205. dw/tasks/depth_estimator.py +54 -0
  206. dw/tasks/diffusion_upscale.py +109 -0
  207. dw/tasks/dissolve_videos.py +342 -0
  208. dw/tasks/format_messages.py +24 -0
  209. dw/tasks/gather.py +173 -0
  210. dw/tasks/grade.py +97 -0
  211. dw/tasks/image_to_text.py +43 -0
  212. dw/tasks/image_utils.py +764 -0
  213. dw/tasks/interpolate_frames.py +252 -0
  214. dw/tasks/judge.py +68 -0
  215. dw/tasks/model_cache.py +55 -0
  216. dw/tasks/pair_audio.py +268 -0
  217. dw/tasks/qr_code.py +19 -0
  218. dw/tasks/restore_faces.py +175 -0
  219. dw/tasks/rife_model.py +192 -0
  220. dw/tasks/segment.py +121 -0
  221. dw/tasks/select.py +111 -0
  222. dw/tasks/speech_generation.py +228 -0
  223. dw/tasks/stabilize.py +129 -0
  224. dw/tasks/task.py +920 -0
  225. dw/tasks/tensor_image.py +57 -0
  226. dw/tasks/text_generation.py +169 -0
  227. dw/tasks/text_sections.py +80 -0
  228. dw/tasks/upscale.py +203 -0
  229. dw/tasks/video_utils.py +624 -0
  230. dw/tasks/zoe_depth.py +71 -0
  231. dw/teacache.py +381 -0
  232. dw/teacache_models.json +99 -0
  233. dw/test.py +29 -0
  234. dw/type_helpers.py +231 -0
  235. dw/validate.py +68 -0
  236. dw/variable_constraints.py +444 -0
  237. dw/variables.py +443 -0
  238. dw/video_extensions.py +141 -0
  239. dw/vram_estimate.py +116 -0
  240. dw/worker.py +764 -0
  241. dw/workflow.py +2007 -0
  242. dw/workflow_schema.json +1346 -0
  243. dw/workflow_sources.py +383 -0
  244. dw/workflows/h3_context_ir.json +57 -0
  245. dw/workflows/test.json +31 -0
  246. dw/workspace.py +730 -0
  247. dw_mcp/__init__.py +6 -0
  248. dw_mcp/__main__.py +133 -0
  249. dw_mcp/assets.py +336 -0
  250. dw_mcp/authoring.py +114 -0
  251. dw_mcp/catalog.py +360 -0
  252. dw_mcp/client.py +486 -0
  253. dw_mcp/diagnose.py +371 -0
  254. dw_mcp/exports.py +84 -0
  255. dw_mcp/guides.py +35 -0
  256. dw_mcp/media.py +638 -0
  257. dw_mcp/models.py +97 -0
  258. dw_mcp/prompts.py +104 -0
  259. dw_mcp/server.py +1343 -0
  260. dw_mcp/workspaces.py +212 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ dw
2
+ dw_mcp
dw/__init__.py ADDED
@@ -0,0 +1,440 @@
1
+ from .settings import resolve_path, load_settings
2
+ from .log_setup import setup_logging
3
+ import os
4
+ import re
5
+ import logging
6
+ import warnings
7
+ from dotenv import load_dotenv
8
+
9
+ load_dotenv() # Loads .env from current directory
10
+
11
+ # Allow MPS to use all available unified memory by default
12
+ # This prevents "MPS backend out of memory" errors with large models
13
+ # Users can override by setting these env vars before import
14
+ if "PYTORCH_MPS_HIGH_WATERMARK_RATIO" not in os.environ:
15
+ os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"
16
+
17
+ # Let the CUDA allocator grow segments instead of fragmenting fixed-size ones.
18
+ # Multi-step workflows churn differently-shaped allocations (generate, upscale,
19
+ # interpolate), and fragmentation is what OOMs a card that nominally has room
20
+ if "PYTORCH_CUDA_ALLOC_CONF" not in os.environ:
21
+ os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
22
+
23
+ # Load sharded checkpoints in parallel - a pure cold-start win
24
+ if "HF_ENABLE_PARALLEL_LOADING" not in os.environ:
25
+ os.environ["HF_ENABLE_PARALLEL_LOADING"] = "true"
26
+
27
+ # Suppress all common library warnings before any imports
28
+ warnings.filterwarnings("ignore", category=FutureWarning)
29
+ warnings.filterwarnings("ignore", category=UserWarning)
30
+ warnings.filterwarnings("ignore", category=DeprecationWarning)
31
+
32
+ # Eager (but guarded) import of torch. This module's own top-level code needs
33
+ # torch's exceptions/types unconditionally to detect its absence gracefully
34
+ # (see _TORCH_AVAILABLE below) rather than deferring the try/except to first
35
+ # use everywhere torch is touched. It would be nice for a torch-free path like
36
+ # `python -m dw.validate` (pure JSON schema validation) to skip this multi-
37
+ # second import, but that isn't achievable by changing dw/__init__.py alone:
38
+ # dw/validate.py imports dw/workflow.py, which does its own unconditional
39
+ # `import torch` at module scope (Workflow.run() uses torch.Generator() for
40
+ # seeding) - so torch loads regardless of what this module does. Making the
41
+ # import here lazy without also restructuring dw/workflow.py's random-seed
42
+ # handling would just move the cost around, not remove it, and touching
43
+ # dw/workflow.py's import structure is a larger, riskier change than this
44
+ # fix pass is meant to make. Left eager on purpose; see the audit notes for
45
+ # why a real fix needs to start in dw/workflow.py, not here.
46
+ try:
47
+ import torch
48
+ import diffusers
49
+ from packaging import version
50
+
51
+ _TORCH_AVAILABLE = True
52
+ except ImportError as e:
53
+ _TORCH_AVAILABLE = False
54
+ _TORCH_IMPORT_ERROR = e
55
+ # Create dummy objects to prevent AttributeError
56
+ torch = None
57
+ diffusers = None
58
+ version = None
59
+
60
+
61
+ def _read_version():
62
+ # Single-sourced from pyproject.toml. Read as text rather than TOML:
63
+ # tomllib is 3.11+ and this project supports 3.10. In a wheel install
64
+ # there is no pyproject on disk - the package metadata carries it.
65
+ try:
66
+ pyproject = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml")
67
+ with open(pyproject, encoding="utf-8") as f:
68
+ match = re.search(r'^version = "([^"]+)"$', f.read(), re.MULTILINE)
69
+ if match:
70
+ return match.group(1)
71
+ except OSError:
72
+ pass
73
+ try:
74
+ from importlib.metadata import version
75
+
76
+ return version("diffusers-workflow")
77
+ except Exception:
78
+ return "unknown"
79
+
80
+
81
+ __version__ = _read_version()
82
+
83
+ settings = load_settings()
84
+
85
+
86
+ def detect_device():
87
+ """
88
+ Detect the best device available on this machine.
89
+ Priority: CUDA > MPS > CPU
90
+
91
+ Returns:
92
+ str: Device identifier ('cuda', 'mps', or 'cpu')
93
+ """
94
+ if not _TORCH_AVAILABLE:
95
+ return "cpu"
96
+
97
+ if torch.cuda.is_available():
98
+ return "cuda"
99
+
100
+ if hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
101
+ return "mps"
102
+
103
+ return "cpu"
104
+
105
+
106
+ def get_device():
107
+ """
108
+ Get the device to run on.
109
+
110
+ An explicit choice wins over detection - the DW_DEVICE environment variable for a
111
+ single run, or the 'device' setting for a standing one. Either can name a specific
112
+ accelerator ('cuda:1'), force a CPU run to rule out a GPU-specific problem, or pin
113
+ a machine that has both to one backend.
114
+
115
+ Returns:
116
+ str: Device identifier ('cuda', 'cuda:1', 'mps', 'cpu', ...)
117
+ """
118
+ if not _TORCH_AVAILABLE:
119
+ return "cpu"
120
+
121
+ configured_device = os.environ.get("DW_DEVICE") or settings.device
122
+ if configured_device:
123
+ try:
124
+ # Only checks that torch understands the name - whether the machine has
125
+ # that device surfaces when a model is loaded onto it
126
+ torch.device(configured_device)
127
+ return configured_device
128
+ except (RuntimeError, TypeError, ValueError) as e:
129
+ logging.warning(f"Ignoring invalid configured device: {e}")
130
+
131
+ return detect_device()
132
+
133
+
134
+ def get_device_type(device=None):
135
+ """
136
+ Get the backend a device belongs to - 'cuda' for 'cuda:1', 'mps' for 'mps'.
137
+
138
+ A device identifier can carry an index, so comparisons against a backend name have
139
+ to be made on the type alone or a device like 'cuda:1' matches nothing.
140
+
141
+ Args:
142
+ device: Device identifier, or None to use the device dw is running on
143
+
144
+ Returns:
145
+ str: Backend name ('cuda', 'mps', 'xpu', 'cpu', ...)
146
+ """
147
+ if not _TORCH_AVAILABLE:
148
+ return "cpu"
149
+
150
+ return torch.device(device if device is not None else get_device()).type
151
+
152
+
153
+ def backend_available(device_type):
154
+ """
155
+ Whether this machine can actually run on a backend.
156
+
157
+ Only the backends dw knows how to probe get an answer. An unrecognized one is
158
+ reported available rather than guessed at, so a device torch understands and dw
159
+ does not is left alone instead of being rewritten.
160
+
161
+ Args:
162
+ device_type: Backend name ('cuda', 'mps', 'cpu', ...)
163
+
164
+ Returns:
165
+ bool: Whether the backend is usable here
166
+ """
167
+ if not _TORCH_AVAILABLE:
168
+ return device_type == "cpu"
169
+
170
+ if device_type == "cpu":
171
+ return True
172
+
173
+ if device_type == "cuda":
174
+ return torch.cuda.is_available()
175
+
176
+ if device_type == "mps":
177
+ return hasattr(torch.backends, "mps") and torch.backends.mps.is_available()
178
+
179
+ is_available = getattr(getattr(torch, device_type, None), "is_available", None)
180
+ return bool(is_available()) if callable(is_available) else True
181
+
182
+
183
+ def resolve_device(requested):
184
+ """
185
+ Translate a device a workflow asked for into one this machine has.
186
+
187
+ A device named in a workflow is nearly always the author saying 'the accelerator'
188
+ rather than 'specifically NVIDIA', so a workflow written on a CUDA box runs on a
189
+ Mac and back again. The backend is what gets translated - an index is left alone
190
+ when the backend matches, since 'cuda:1' on a single-GPU CUDA box is a genuine
191
+ mistake and not a portability problem. A CPU device is never rewritten: pinning a
192
+ step to the CPU is how a GPU-specific problem gets ruled out.
193
+
194
+ Args:
195
+ requested: Device identifier from a workflow, or None for no override
196
+
197
+ Returns:
198
+ The device to use, or None if None was passed
199
+ """
200
+ if requested is None or not _TORCH_AVAILABLE:
201
+ return requested
202
+
203
+ try:
204
+ device = torch.device(requested)
205
+ except (RuntimeError, TypeError, ValueError):
206
+ # Not a device torch understands - let the failure surface where it is used
207
+ return requested
208
+
209
+ if device.type == "cpu" or backend_available(device.type):
210
+ return requested
211
+
212
+ target = get_device()
213
+ if device.index is not None:
214
+ logging.warning(
215
+ f"Workflow asks for '{requested}', which this machine has no {device.type} "
216
+ f"backend for - running on {target}. The device index is dropped, so a "
217
+ "workflow that meant to spread work across accelerators will not."
218
+ )
219
+ else:
220
+ logging.warning(
221
+ f"Workflow asks for '{requested}', which this machine has no {device.type} "
222
+ f"backend for - running on {target}"
223
+ )
224
+
225
+ return target
226
+
227
+
228
+ def get_autocast_device_type():
229
+ """
230
+ Get the device type to use for torch.autocast.
231
+ MPS doesn't support autocast, so use 'cpu' for MPS devices.
232
+
233
+ Returns:
234
+ str: Device type for autocast ('cuda' or 'cpu')
235
+ """
236
+ if get_device_type() == "cuda":
237
+ return "cuda"
238
+
239
+ # MPS and CPU both use 'cpu' for autocast
240
+ return "cpu"
241
+
242
+
243
+ def preferred_task_dtype(device=None):
244
+ """
245
+ Get the preferred torch dtype for a lightweight inference task (captioning,
246
+ text generation, diffusion upscaling, depth estimation).
247
+
248
+ fp16 produces NaN values on MPS and is unsupported by many CPU operations,
249
+ so only CUDA gets it - everything else runs in fp32.
250
+
251
+ Args:
252
+ device: Device identifier, or None to use the device dw is running on
253
+
254
+ Returns:
255
+ torch.dtype: torch.float16 on CUDA, torch.float32 otherwise (or None
256
+ if torch isn't available)
257
+ """
258
+ if not _TORCH_AVAILABLE:
259
+ return None
260
+
261
+ return torch.float16 if get_device_type(device) == "cuda" else torch.float32
262
+
263
+
264
+ def empty_device_cache(synchronize=False):
265
+ """
266
+ Empty the allocator cache of the device dw is configured for, if its
267
+ backend has one. A no-op on CPU.
268
+
269
+ Dispatch honors the DW_DEVICE/settings override (via get_device_type())
270
+ but also checks the backend's own availability before calling into it,
271
+ matching the belt-and-suspenders checks the call sites used to do
272
+ individually.
273
+
274
+ Args:
275
+ synchronize: Also block until pending device work completes before
276
+ returning. Skipped by default - it's expensive and callers on a
277
+ hot path (e.g. between-run cleanup) don't need it.
278
+ """
279
+ if not _TORCH_AVAILABLE:
280
+ return
281
+
282
+ device_type = get_device_type()
283
+ if device_type == "cuda" and torch.cuda.is_available():
284
+ torch.cuda.empty_cache()
285
+ if synchronize:
286
+ torch.cuda.synchronize()
287
+ elif (
288
+ device_type == "mps"
289
+ and hasattr(torch.backends, "mps")
290
+ and torch.backends.mps.is_available()
291
+ ):
292
+ if hasattr(torch.mps, "empty_cache"):
293
+ torch.mps.empty_cache()
294
+ if synchronize and hasattr(torch.mps, "synchronize"):
295
+ torch.mps.synchronize()
296
+
297
+
298
+ def device_memory_stats():
299
+ """
300
+ Snapshot of allocator memory usage for the device dw is configured for.
301
+
302
+ Only CUDA exposes free/total figures (via torch.cuda.mem_get_info); MPS
303
+ has no equivalent API, so its snapshot reports zeroed, "known" values
304
+ instead. CPU, or a CUDA/MPS backend that isn't actually available despite
305
+ being the configured device type, results in an "unavailable" snapshot.
306
+
307
+ Returns:
308
+ dict with keys:
309
+ available (bool): whether the backend could be queried
310
+ device_name (str or None)
311
+ allocated_mb (float)
312
+ reserved_mb (float)
313
+ free_mb (float or None): None only when CUDA's mem_get_info call
314
+ itself fails
315
+ total_mb (float or None): None only when CUDA's mem_get_info call
316
+ itself fails
317
+ """
318
+ stats = {
319
+ "available": False,
320
+ "device_name": None,
321
+ "allocated_mb": 0.0,
322
+ "reserved_mb": 0.0,
323
+ "free_mb": None,
324
+ "total_mb": None,
325
+ }
326
+
327
+ if not _TORCH_AVAILABLE:
328
+ return stats
329
+
330
+ device_type = get_device_type()
331
+ if device_type == "cuda" and torch.cuda.is_available():
332
+ stats["available"] = True
333
+ stats["device_name"] = torch.cuda.get_device_name(0)
334
+ stats["allocated_mb"] = torch.cuda.memory_allocated() / 1024 / 1024
335
+ stats["reserved_mb"] = torch.cuda.memory_reserved() / 1024 / 1024
336
+ try:
337
+ free, total = torch.cuda.mem_get_info()
338
+ stats["free_mb"] = free / 1024 / 1024
339
+ stats["total_mb"] = total / 1024 / 1024
340
+ except (RuntimeError, AttributeError):
341
+ pass
342
+ elif (
343
+ device_type == "mps"
344
+ and hasattr(torch.backends, "mps")
345
+ and torch.backends.mps.is_available()
346
+ ):
347
+ # MPS doesn't provide detailed memory stats like CUDA
348
+ stats["available"] = True
349
+ stats["device_name"] = "Apple Silicon (MPS)"
350
+ stats["free_mb"] = 0.0
351
+ stats["total_mb"] = 0.0
352
+
353
+ return stats
354
+
355
+
356
+ def startup(log_level=None):
357
+ if not _TORCH_AVAILABLE:
358
+ raise ImportError(
359
+ f"PyTorch is not available. {_TORCH_IMPORT_ERROR}\n"
360
+ "Please ensure you're using the virtual environment where torch is installed.\n"
361
+ "Activate the venv: source venv/bin/activate"
362
+ )
363
+
364
+ # The default torch device is deliberately left alone. Diffusers loads weights into
365
+ # system memory and then places them - moving them to the device, or hooking them
366
+ # for offloading. A default device of 'cuda' pre-empts that by building every module
367
+ # directly in VRAM, which runs a large pipeline out of memory before its offload
368
+ # hooks are ever installed. Device placement is explicit throughout dw instead.
369
+ device = get_device()
370
+ device_type = get_device_type(device)
371
+
372
+ # MPS-specific configuration (Apple Silicon)
373
+ if device_type == "mps":
374
+ # Suppress autocast warnings (MPS doesn't support autocast,
375
+ # and libraries may try to use it with 'cuda' device_type)
376
+ warnings.filterwarnings(
377
+ "ignore",
378
+ message=".*User provided device_type of 'cuda'.*",
379
+ category=UserWarning,
380
+ module="torch.amp.autocast_mode",
381
+ )
382
+
383
+ logging.info(
384
+ f"MPS backend - watermark ratio: "
385
+ f"{os.environ.get('PYTORCH_MPS_HIGH_WATERMARK_RATIO', 'default')}"
386
+ )
387
+
388
+ # Check if we have a GPU backend (CUDA or MPS)
389
+ if device_type == "cpu":
390
+ logging.warning(
391
+ "No GPU backend available (CUDA or MPS). Running on CPU may be slow."
392
+ )
393
+
394
+ if version.parse(torch.__version__) < version.parse("2.0.0"):
395
+ raise Exception(
396
+ f"Pytorch must be 2.0 or greater (found {torch.__version__}). Run install script. Quitting."
397
+ )
398
+
399
+ if log_level is not None:
400
+ settings.log_level = log_level
401
+
402
+ setup_logging(
403
+ resolve_path(settings.log_filename),
404
+ settings.log_level,
405
+ log_to_console=settings.log_to_console,
406
+ )
407
+
408
+ logging.info(f"Version {__version__}")
409
+ logging.debug(f"Torch version {torch.__version__}")
410
+ logging.info(f"Using device: {device}")
411
+
412
+ diffusers.logging.set_verbosity_error()
413
+
414
+ # TF32 optimization (Ampere+ GPUs: RTX 30/40 series, A100, H100)
415
+ # Provides ~2x speedup for matmul operations with minimal precision loss
416
+ if settings.enable_tf32:
417
+ torch.set_float32_matmul_precision("high")
418
+ if device_type == "cuda":
419
+ torch.backends.cuda.matmul.allow_tf32 = True
420
+ logging.debug("TF32 precision enabled for faster matmul operations")
421
+ else:
422
+ logging.debug("TF32 precision disabled (full FP32 precision)")
423
+
424
+ # CUDA-specific optimizations
425
+ if device_type == "cuda":
426
+ # cuDNN autotuner - benchmarks algorithms and selects fastest
427
+ # Best for fixed input sizes, may slow down variable-size workflows
428
+ torch.backends.cudnn.benchmark = settings.cudnn_benchmark
429
+
430
+ # Always enable cuDNN (default anyway)
431
+ torch.backends.cudnn.enabled = True
432
+
433
+ # Deterministic mode - set True for reproducibility (same seed = same output)
434
+ # False prioritizes performance over strict reproducibility
435
+ torch.backends.cudnn.deterministic = settings.cudnn_deterministic
436
+
437
+ logging.debug(
438
+ f"CUDA optimizations - benchmark: {settings.cudnn_benchmark}, "
439
+ f"deterministic: {settings.cudnn_deterministic}"
440
+ )