Upload folder using huggingface_hub
Browse files- README.md +174 -67
- pipeline.py +440 -0
README.md
CHANGED
@@ -53,7 +53,114 @@ For the model, follow the directions for flux for the vae and text encoder model
|
|
53 |
|
54 |
### Diffusers
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
## Limitations
|
59 |
|
@@ -109,83 +216,83 @@ If you enjoy my projects or use them commercially, please consider sponsoring me
|
|
109 |
|
110 |
All of these people / organizations are the ones who selflessly make this project possible. Thank you!!
|
111 |
|
112 |
-
_Last updated: 2025-04-22
|
113 |
|
114 |
<p align="center">
|
115 |
-
<a href="https://github.com/replicate" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/60410876?v=4" alt="Replicate" width="200" height="200" style="border-radius:8px;margin:5px;
|
116 |
-
<a href="https://github.com/josephrocca" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/1167575?u=92d92921b4cb5c8c7e225663fed53c4b41897736&v=4" alt="josephrocca" width="200" height="200" style="border-radius:8px;margin:5px;
|
117 |
</p>
|
118 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
119 |
<p align="center">
|
120 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/162524101/81a72689c3754ac5b9e38612ce5ce914/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=3XLSlLFCWAQ-0wd2_vZMikyotdQNSzKOjoyeoJiZEw0%3D" alt="Prasanth Veerina" width="150" height="150" style="border-radius:8px;margin:5px;
|
121 |
-
<a href="https://github.com/weights-ai" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/185568492?v=4" alt="Weights" width="150" height="150" style="border-radius:8px;margin:5px;
|
122 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/161471720/dd330b4036d44a5985ed5985c12a5def/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=qkRvrEc5gLPxaXxLvcvbYv1W1lcmOoTwhj4A9Cq5BxQ%3D" alt="Vladimir Sotnikov" width="150" height="150" style="border-radius:8px;margin:5px;
|
123 |
-
<img src="https://c8.patreon.com/3/200/33158543" alt="clement Delangue" width="150" height="150" style="border-radius:8px;margin:5px;
|
124 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/54890369/45cea21d82974c78bf43956de7fb0e12/eyJ3IjoyMDB9/2.jpeg?token-time=2145916800&token-hash=IK6OT6UpusHgdaC4y8IhK5XxXiP5TuLy3vjvgL77Fho%3D" alt="Eli Slugworth" width="150" height="150" style="border-radius:8px;margin:5px;
|
125 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/8654302/b0f5ebedc62a47c4b56222693e1254e9/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=lpeicIh1_S-3Ji3W27gyiRB7iXurp8Bx8HAzDHftOuo%3D" alt="Misch Strotz" width="150" height="150" style="border-radius:8px;margin:5px;
|
126 |
-
<img src="https://c8.patreon.com/3/200/93304" alt="Joseph Rocca" width="150" height="150" style="border-radius:8px;margin:5px;
|
127 |
</p>
|
128 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
129 |
<p align="center">
|
130 |
-
<a href="https://x.com/NuxZoe" target="_blank" rel="noopener noreferrer"><img src="https://pbs.twimg.com/profile_images/1714760743273574400/tdvQjNTl_400x400.jpg" alt="tungsten" width="100" height="100" style="border-radius:8px;margin:5px;
|
131 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/2298192/1228b69bd7d7481baf3103315183250d/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=1B7dbXy_gAcPT9WXBesLhs7z_9APiz2k1Wx4Vml_-8Q%3D" alt="Mohamed Oumoumad" width="100" height="100" style="border-radius:8px;margin:5px;
|
132 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/120239481/49b1ce70d3d24704b8ec34de24ec8f55/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=Dv1NPKwdv9QT8fhYYwbGnQIvfiyqTUlh52bjDW1vYxY%3D" alt="nitish PNR" width="100" height="100" style="border-radius:8px;margin:5px;
|
133 |
-
<img src="https://c8.patreon.com/3/200/548524" alt="Steve Hanff" width="100" height="100" style="border-radius:8px;margin:5px;
|
134 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/152118848/3b15a43d71714552b5ed1c9f84e66adf/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=IEKE18CBHVZ3k-08UD7Dkb7HbiFHb84W0FATdLMI0Dg%3D" alt="Kristjan Retter" width="100" height="100" style="border-radius:8px;margin:5px;
|
135 |
-
<img src="https://c8.patreon.com/3/200/83319230" alt="Miguel Lara" width="100" height="100" style="border-radius:8px;margin:5px;
|
136 |
</p>
|
137 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
138 |
<p align="center">
|
139 |
-
<img src="https://c8.patreon.com/3/200/8449560" alt="Patron" width="60" height="60" style="border-radius:8px;margin:5px;
|
140 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/27288932/6c35d2d961ee4e14a7a368c990791315/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=dpFFssZXZM_KZMKQhl3uDwwusdFw1c_v9x_ChJU7_zc%3D" alt="David Garrido" width="60" height="60" style="border-radius:8px;margin:5px;
|
141 |
-
<img src="https://c8.patreon.com/3/200/2410522" alt="George Gostyshev" width="60" height="60" style="border-radius:8px;margin:5px;
|
142 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/16287560/78130de30950410ca528d8a888997081/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=Ok-HSL2MthKXF09SmCOlPFCPfbMctFBZKCuTnPwxZ3A%3D" alt="Vitaly Golubenko" width="60" height="60" style="border-radius:8px;margin:5px;
|
143 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/570742/4ceb33453a5a4745b430a216aba9280f/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=wUzsI5cO5Evp2ukIGdSgBbvKeYgv5LSOQMa6Br33Rrs%3D" alt="Al H" width="60" height="60" style="border-radius:8px;margin:5px;
|
144 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/131773947/eda3405aa582437db4582fce908c8739/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=S4Bh0sMqTNmJlo3uRr7co5d_kxvBjITemDTfi_1KrCA%3D" alt="Jodh Singh" width="60" height="60" style="border-radius:8px;margin:5px;
|
145 |
-
<img src="https://c8.patreon.com/3/200/22809690" alt="Michael Levine" width="60" height="60" style="border-radius:8px;margin:5px;
|
146 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/99036356/7ae9c4d80e604e739b68cca12ee2ed01/eyJ3IjoyMDB9/3.png?token-time=2145916800&token-hash=zK0dHe6A937WtNlrGdefoXFTPPzHUCfn__23HP8-Ui0%3D" alt="Noctre" width="60" height="60" style="border-radius:8px;margin:5px;
|
147 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/141098579/1a9f0a1249d447a7a0df718a57343912/eyJ3IjoyMDB9/2.png?token-time=2145916800&token-hash=Rd_AjZGhMATVkZDf8E95ILc0n93gvvFWe1Ig0_dxwf4%3D" alt="The Local Lab" width="60" height="60" style="border-radius:8px;margin:5px;
|
148 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/98811435/3a3632d1795b4c2b9f8f0270f2f6a650/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=93w8RMxwXlcM4X74t03u6P5_SrKvlm1IpjnD2SzVpJk%3D" alt="EmmanuelMr18" width="60" height="60" style="border-radius:8px;margin:5px;
|
149 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/338551/e8f257d8d3dd46c38272b391a5785948/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=GLom1rGgOZjBeO7I1OnjiIgWmjl6PO9ZjBB8YTvc7AM%3D" alt="Plaidam" width="60" height="60" style="border-radius:8px;margin:5px;
|
150 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/82763/f99cc484361d4b9d94fe4f0814ada303/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=BpwC020pR3TRZ4r0RSCiSIOh-jmatkrpy1h2XU4sGa4%3D" alt="Doron Adler" width="60" height="60" style="border-radius:8px;margin:5px;
|
151 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/103077711/bb215761cc004e80bd9cec7d4bcd636d/eyJ3IjoyMDB9/2.jpeg?token-time=2145916800&token-hash=zvtBie29rRTKTXvAA2KhOI-l3mSMk9xxr-mg_CksLtc%3D" alt="John Dopamine" width="60" height="60" style="border-radius:8px;margin:5px;
|
152 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/93348210/5c650f32a0bc481d80900d2674528777/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=PpXK9B_iy288annlNdLOexhiQHbTftPEDeCh-sTQ2KA%3D" alt="Armin Behjati" width="60" height="60" style="border-radius:8px;margin:5px;
|
153 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/155963250/6f8fd7075c3b4247bfeb054ba49172d6/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=twmKs4mADF_h7bKh5jBuigYVScMeaeHv2pEPin9K0Dg%3D" alt="Un Defined" width="60" height="60" style="border-radius:8px;margin:5px;
|
154 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/45562978/0de33cf52ec642ae8a2f612cddec4ca6/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=hSAvaD4phiLcF0pvX7FP0juI5NQWCon-_TZSNpJzQJg%3D" alt="Jack English" width="60" height="60" style="border-radius:8px;margin:5px;
|
155 |
-
<img src="https://c8.patreon.com/3/200/27791680" alt="Jean-Tristan Marin" width="60" height="60" style="border-radius:8px;margin:5px;
|
156 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/60995694/92e0e8f336eb4a5bb8d99b940247d1d1/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=pj6Tm8XRdpGJcAEdnCakqYSNiSjoAYjvZescX7d0ic0%3D" alt="Abraham Irawan" width="60" height="60" style="border-radius:8px;margin:5px;
|
157 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/164958178/4eb7a37baa0541bab7a091f2b14615b7/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=_aaum7fBJAGaJhMBhlR8vqYavDhExdVxmO9mwd3_XMw%3D" alt="Austin Robinson" width="60" height="60" style="border-radius:8px;margin:5px;
|
158 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/134129880/680c7e14cd1a4d1a9face921fb010f88/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=vNKojv67krNqx7gdpKBX1R_stX2TkMRYvRc0xZrbY6s%3D" alt="Bharat Prabhakar" width="60" height="60" style="border-radius:8px;margin:5px;
|
159 |
-
<img src="https://c8.patreon.com/3/200/70218846" alt="Cosmosis" width="60" height="60" style="border-radius:8px;margin:5px;
|
160 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/83054970/13de6cb103ad41a5841edf549e66cd51/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=wU_Eke9VYcfI40FAQvdEV84Xspqlo5VSiafLqhg_FOE%3D" alt="Gili Ben Shahar" width="60" height="60" style="border-radius:8px;margin:5px;
|
161 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/30931983/54ab4e4ceab946e79a6418d205f9ed51/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=LBmsSsMQZhO6yRZ_YyRwTgE6a7BVWrGNsAVveLXHXR0%3D" alt="HestoySeghuro ." width="60" height="60" style="border-radius:8px;margin:5px;
|
162 |
-
<img src="https://c8.patreon.com/3/200/4105384" alt="Jack Blakely" width="60" height="60" style="border-radius:8px;margin:5px;
|
163 |
-
<img src="https://c8.patreon.com/3/200/494309" alt="Julian Tsependa" width="60" height="60" style="border-radius:8px;margin:5px;
|
164 |
-
<img src="https://c8.patreon.com/3/200/24653779" alt="RayHell" width="60" height="60" style="border-radius:8px;margin:5px;
|
165 |
-
<img src="https://c8.patreon.com/3/200/4541423" alt="Sören " width="60" height="60" style="border-radius:8px;margin:5px;
|
166 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/31950857/c567dc648f6144be9f6234946df05da2/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=3Vx4R1eOfD4X_ZPPd40MsZ-3lyknLM35XmaHRELnWjM%3D" alt="Trent Hunter" width="60" height="60" style="border-radius:8px;margin:5px;
|
167 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/110407414/30f9e9d88ef945ddb0f47fd23a8cbac2/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=QQRWOkMyOfDBERHn4O8N2wMB32zeiIEsydVTbSNUw-I%3D" alt="Wesley Reitzfeld" width="60" height="60" style="border-radius:8px;margin:5px;
|
168 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/162398691/89d78d89eecb4d6b981ce8c3c6a3d4b8/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=SWhI-0jGpY6Nc_bUQeXz4pa9DRURi9VnnnJ3Mxjg1po%3D" alt="Zoltán-Csaba Nyiró" width="60" height="60" style="border-radius:8px;margin:5px;
|
169 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/97985240/3d1d0e6905d045aba713e8132cab4a30/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=pG3X2m-py2lRYI2aoJiXI47_4ArD78ZHdSm6jCAHA_w%3D" alt="עומר מכלוף" width="60" height="60" style="border-radius:8px;margin:5px;
|
170 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/140599287/cff037fb93804af28bc3a4f1e91154f8/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=vkscmpmFoM5wq7GnsLmOEgNhvyXe-774kNGNqD0wurE%3D" alt="Lukas" width="60" height="60" style="border-radius:8px;margin:5px;
|
171 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/96561218/b0694642d13a49faa75aec9762ff2aeb/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=sLQXomYm1iMYpknvGwKQ49f30TKQ0B1R2W3EZfCJqr8%3D" alt="Ultimate Golf Archives" width="60" height="60" style="border-radius:8px;margin:5px;
|
172 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/81275465/1e4148fe9c47452b838949d02dd9a70f/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=uzJzkUq9rte3wx8wDLjGAgvSoxdtZcAnH7HctDhdYEo%3D" alt="Aaron Amortegui" width="60" height="60" style="border-radius:8px;margin:5px;
|
173 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/44568304/a9d83a0e786b41b4bdada150f7c9271c/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=SBphTD654nwr-OTrvIBIJBEQho7GE2PtRre8nyaG1Fk%3D" alt="Albert Bukoski" width="60" height="60" style="border-radius:8px;margin:5px;
|
174 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/49304261/d0a730de1c3349e585c49288b9f419c6/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=C2BMZ3ci-Ty2nhnSwKZqsR-5hOGsUNDYcvXps0Geq9w%3D" alt="Arvin Flores" width="60" height="60" style="border-radius:8px;margin:5px;
|
175 |
-
<img src="https://c8.patreon.com/3/200/5048649" alt="Ben Ward" width="60" height="60" style="border-radius:8px;margin:5px;
|
176 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/130338124/f904a3bb76cd4588ac8d8f595c6cb486/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=k-inISRUtYDu9q7fNAKc3S2S7qcaw26fr1pj7PqU28Q%3D" alt="Bnp" width="60" height="60" style="border-radius:8px;margin:5px;
|
177 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/111904990/08b1cf65be6a4de091c9b73b693b3468/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=OAJc9W5Ak0uJfQ2COlo1Upo38K3aj1fMQFCMC7ft5tM%3D" alt="Brian Smith" width="60" height="60" style="border-radius:8px;margin:5px;
|
178 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/113207022/d4a67cc113e84fb69032bef71d068720/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=mu-tIg88VwoQdgLEOmxuVkhVm9JT59DdnHXJstmkkLU%3D" alt="Fagem X" width="60" height="60" style="border-radius:8px;margin:5px;
|
179 |
-
<img src="https://c8.patreon.com/3/200/5602036" alt="Kelevra" width="60" height="60" style="border-radius:8px;margin:5px;
|
180 |
-
<img src="https://c8.patreon.com/3/200/358350" alt="L D" width="60" height="60" style="border-radius:8px;margin:5px;
|
181 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/159203973/36c817f941ac4fa18103a4b8c0cb9cae/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=9toslDfsO14QyaOiu6vIf--d4marBsWCZWN3gdPqbIU%3D" alt="Marko jak" width="60" height="60" style="border-radius:8px;margin:5px;
|
182 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/11198131/e696d9647feb4318bcf16243c2425805/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=o6Hrpzw9rf2Ucd4cZ-hdUkGejLNv44-pqF8smeOF3ts%3D" alt="Nicholas Agranoff" width="60" height="60" style="border-radius:8px;margin:5px;
|
183 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/785333/bdb9ede5765d42e5a2021a86eebf0d8f/eyJ3IjoyMDB9/2.jpg?token-time=2145916800&token-hash=dr5eaMg3Ua0wyCy40Qv3F-ZFajWZmuz2fWG55FskREc%3D" alt="Sapjes " width="60" height="60" style="border-radius:8px;margin:5px;
|
184 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/44738426/b01ff676da864d4ab9c21f226275b63e/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=54nIkcxFaGszJ3q0jNhtrVSBbV3WNK9e5WX9VzXltYk%3D" alt="Shakeel Saleemi" width="60" height="60" style="border-radius:8px;margin:5px;
|
185 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/76566911/6485eaf5ec6249a7b524ee0b979372f0/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=S1QK78ief5byQU7tB_reqnw4V2zhW_cpwTqHThk-tGc%3D" alt="the biitz" width="60" height="60" style="border-radius:8px;margin:5px;
|
186 |
-
<img src="https://c8.patreon.com/3/200/83034" alt="william tatum" width="60" height="60" style="border-radius:8px;margin:5px;
|
187 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/32633822/1ab5612efe80417cbebfe91e871fc052/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=RHYMcjr0UGIYw5FBrUfJdKMGuoYWhBQlLIykccEFJvo%3D" alt="Zack Abrams" width="60" height="60" style="border-radius:8px;margin:5px;
|
188 |
-
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/138787189/2b5662dcb638466282ac758e3ac651b4/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=IlUAs9JAlVRphfx81V-Jt-nMiSBS8mPewRr9u6pQjaQ%3D" alt="Антон Антонио" width="60" height="60" style="border-radius:8px;margin:5px;
|
189 |
</p>
|
190 |
|
191 |
---
|
|
|
53 |
|
54 |
### Diffusers
|
55 |
|
56 |
+
For diffusers, you can use `AutoPipelineForText2Image`. This will load the model with the pipeline located [here](https://huggingface.co/ostris/Flex.2-preview/blob/main/pipeline.py). We will run this example using the `diffusers` library.
|
57 |
+
|
58 |
+
|
59 |
+
<img src="https://ostris.com/wp-content/uploads/2025/04/diffusers_example.jpg" alt="Diffusers Flex.2" style="max-width: 100%; height: auto;"/>
|
60 |
+
|
61 |
+
First install the requirements.
|
62 |
+
|
63 |
+
```bash
|
64 |
+
pip install --upgrade torch accelerate transformers diffusers
|
65 |
+
```
|
66 |
+
|
67 |
+
Then you can load the model and use it like this:
|
68 |
+
|
69 |
+
```python
|
70 |
+
import torch
|
71 |
+
from diffusers import AutoPipelineForText2Image
|
72 |
+
from diffusers.utils import load_image
|
73 |
+
|
74 |
+
name_or_path = "ostris/Flex.2-preview"
|
75 |
+
|
76 |
+
inpaint_image = load_image("https://ostris.com/wp-content/uploads/2025/04/dog.jpg")
|
77 |
+
inpaint_mask = load_image("https://ostris.com/wp-content/uploads/2025/04/dog_mask.jpg")
|
78 |
+
control_image = load_image("https://ostris.com/wp-content/uploads/2025/04/dog_depth.jpg")
|
79 |
+
|
80 |
+
dtype = torch.bfloat16
|
81 |
+
|
82 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
83 |
+
name_or_path,
|
84 |
+
custom_pipeline=name_or_path,
|
85 |
+
torch_dtype=dtype
|
86 |
+
).to("cuda")
|
87 |
+
|
88 |
+
image = pipe(
|
89 |
+
prompt="A white friendly robotic dog sitting on a bench",
|
90 |
+
inpaint_image=inpaint_image,
|
91 |
+
inpaint_mask=inpaint_mask,
|
92 |
+
control_image=control_image,
|
93 |
+
control_strength=0.5,
|
94 |
+
control_stop=0.33,
|
95 |
+
height=1024,
|
96 |
+
width=1024,
|
97 |
+
guidance_scale=3.5,
|
98 |
+
num_inference_steps=50,
|
99 |
+
generator=torch.Generator("cpu").manual_seed(42)
|
100 |
+
).images[0]
|
101 |
+
image.save(f"robot_dog.png")
|
102 |
+
|
103 |
+
```
|
104 |
+
|
105 |
+
For consumer cards < 24GB, you can use torchao to
|
106 |
+
|
107 |
+
```bash
|
108 |
+
pip install --upgrade torchao
|
109 |
+
```
|
110 |
+
|
111 |
+
Then you can load the model and use it like this:
|
112 |
+
|
113 |
+
```python
|
114 |
+
import torch
|
115 |
+
from diffusers import AutoPipelineForText2Image
|
116 |
+
from diffusers.utils import load_image
|
117 |
+
from transformers import T5EncoderModel, TorchAoConfig
|
118 |
+
from diffusers import FluxTransformer2DModel
|
119 |
+
|
120 |
+
name_or_path = "ostris/Flex.2-preview"
|
121 |
+
|
122 |
+
inpaint_image = load_image("https://ostris.com/wp-content/uploads/2025/04/dog.jpg")
|
123 |
+
inpaint_mask = load_image("https://ostris.com/wp-content/uploads/2025/04/dog_mask.jpg")
|
124 |
+
control_image = load_image("https://ostris.com/wp-content/uploads/2025/04/dog_depth.jpg")
|
125 |
+
|
126 |
+
dtype = torch.bfloat16
|
127 |
+
|
128 |
+
quant_config = TorchAoConfig("int8_weight_only")
|
129 |
+
|
130 |
+
text_encoder_2 = T5EncoderModel.from_pretrained(
|
131 |
+
name_or_path, subfolder="text_encoder_2", torch_dtype=dtype, quantization_config=quant_config
|
132 |
+
).to("cuda")
|
133 |
+
|
134 |
+
transformer = FluxTransformer2DModel.from_pretrained(
|
135 |
+
name_or_path, subfolder="transformer", torch_dtype=dtype, quantization_config=quant_config
|
136 |
+
).to("cuda")
|
137 |
+
|
138 |
+
|
139 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
140 |
+
name_or_path,
|
141 |
+
transformer=transformer,
|
142 |
+
text_encoder_2=text_encoder_2,
|
143 |
+
custom_pipeline=name_or_path,
|
144 |
+
torch_dtype=dtype
|
145 |
+
).to("cuda")
|
146 |
+
|
147 |
+
image = pipe(
|
148 |
+
prompt="A white friendly robotic dog sitting on a bench",
|
149 |
+
inpaint_image=inpaint_image,
|
150 |
+
inpaint_mask=inpaint_mask,
|
151 |
+
control_image=control_image,
|
152 |
+
control_strength=0.5,
|
153 |
+
control_stop=0.33,
|
154 |
+
height=1024,
|
155 |
+
width=1024,
|
156 |
+
guidance_scale=3.5,
|
157 |
+
num_inference_steps=50,
|
158 |
+
generator=torch.Generator("cpu").manual_seed(42)
|
159 |
+
).images[0]
|
160 |
+
image.save(f"robot_dog.png")
|
161 |
+
```
|
162 |
+
|
163 |
+
|
164 |
|
165 |
## Limitations
|
166 |
|
|
|
216 |
|
217 |
All of these people / organizations are the ones who selflessly make this project possible. Thank you!!
|
218 |
|
219 |
+
_Last updated: 2025-04-22 16:45 UTC_
|
220 |
|
221 |
<p align="center">
|
222 |
+
<a href="https://github.com/replicate" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/60410876?v=4" alt="Replicate" width="200" height="200" style="border-radius:8px;margin:5px;"></a>
|
223 |
+
<a href="https://github.com/josephrocca" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/1167575?u=92d92921b4cb5c8c7e225663fed53c4b41897736&v=4" alt="josephrocca" width="200" height="200" style="border-radius:8px;margin:5px;"></a>
|
224 |
</p>
|
225 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
226 |
<p align="center">
|
227 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/162524101/81a72689c3754ac5b9e38612ce5ce914/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=3XLSlLFCWAQ-0wd2_vZMikyotdQNSzKOjoyeoJiZEw0%3D" alt="Prasanth Veerina" width="150" height="150" style="border-radius:8px;margin:5px;">
|
228 |
+
<a href="https://github.com/weights-ai" target="_blank" rel="noopener noreferrer"><img src="https://avatars.githubusercontent.com/u/185568492?v=4" alt="Weights" width="150" height="150" style="border-radius:8px;margin:5px;"></a>
|
229 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/161471720/dd330b4036d44a5985ed5985c12a5def/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=qkRvrEc5gLPxaXxLvcvbYv1W1lcmOoTwhj4A9Cq5BxQ%3D" alt="Vladimir Sotnikov" width="150" height="150" style="border-radius:8px;margin:5px;">
|
230 |
+
<img src="https://c8.patreon.com/3/200/33158543" alt="clement Delangue" width="150" height="150" style="border-radius:8px;margin:5px;">
|
231 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/54890369/45cea21d82974c78bf43956de7fb0e12/eyJ3IjoyMDB9/2.jpeg?token-time=2145916800&token-hash=IK6OT6UpusHgdaC4y8IhK5XxXiP5TuLy3vjvgL77Fho%3D" alt="Eli Slugworth" width="150" height="150" style="border-radius:8px;margin:5px;">
|
232 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/8654302/b0f5ebedc62a47c4b56222693e1254e9/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=lpeicIh1_S-3Ji3W27gyiRB7iXurp8Bx8HAzDHftOuo%3D" alt="Misch Strotz" width="150" height="150" style="border-radius:8px;margin:5px;">
|
233 |
+
<img src="https://c8.patreon.com/3/200/93304" alt="Joseph Rocca" width="150" height="150" style="border-radius:8px;margin:5px;">
|
234 |
</p>
|
235 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
236 |
<p align="center">
|
237 |
+
<a href="https://x.com/NuxZoe" target="_blank" rel="noopener noreferrer"><img src="https://pbs.twimg.com/profile_images/1714760743273574400/tdvQjNTl_400x400.jpg" alt="tungsten" width="100" height="100" style="border-radius:8px;margin:5px;"></a>
|
238 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/2298192/1228b69bd7d7481baf3103315183250d/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=1B7dbXy_gAcPT9WXBesLhs7z_9APiz2k1Wx4Vml_-8Q%3D" alt="Mohamed Oumoumad" width="100" height="100" style="border-radius:8px;margin:5px;">
|
239 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/120239481/49b1ce70d3d24704b8ec34de24ec8f55/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=Dv1NPKwdv9QT8fhYYwbGnQIvfiyqTUlh52bjDW1vYxY%3D" alt="nitish PNR" width="100" height="100" style="border-radius:8px;margin:5px;">
|
240 |
+
<img src="https://c8.patreon.com/3/200/548524" alt="Steve Hanff" width="100" height="100" style="border-radius:8px;margin:5px;">
|
241 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/152118848/3b15a43d71714552b5ed1c9f84e66adf/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=IEKE18CBHVZ3k-08UD7Dkb7HbiFHb84W0FATdLMI0Dg%3D" alt="Kristjan Retter" width="100" height="100" style="border-radius:8px;margin:5px;">
|
242 |
+
<img src="https://c8.patreon.com/3/200/83319230" alt="Miguel Lara" width="100" height="100" style="border-radius:8px;margin:5px;">
|
243 |
</p>
|
244 |
<hr style="width:100%;border:none;height:2px;background:#ddd;margin:30px 0;">
|
245 |
<p align="center">
|
246 |
+
<img src="https://c8.patreon.com/3/200/8449560" alt="Patron" width="60" height="60" style="border-radius:8px;margin:5px;">
|
247 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/27288932/6c35d2d961ee4e14a7a368c990791315/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=dpFFssZXZM_KZMKQhl3uDwwusdFw1c_v9x_ChJU7_zc%3D" alt="David Garrido" width="60" height="60" style="border-radius:8px;margin:5px;">
|
248 |
+
<img src="https://c8.patreon.com/3/200/2410522" alt="George Gostyshev" width="60" height="60" style="border-radius:8px;margin:5px;">
|
249 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/16287560/78130de30950410ca528d8a888997081/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=Ok-HSL2MthKXF09SmCOlPFCPfbMctFBZKCuTnPwxZ3A%3D" alt="Vitaly Golubenko" width="60" height="60" style="border-radius:8px;margin:5px;">
|
250 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/570742/4ceb33453a5a4745b430a216aba9280f/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=wUzsI5cO5Evp2ukIGdSgBbvKeYgv5LSOQMa6Br33Rrs%3D" alt="Al H" width="60" height="60" style="border-radius:8px;margin:5px;">
|
251 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/131773947/eda3405aa582437db4582fce908c8739/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=S4Bh0sMqTNmJlo3uRr7co5d_kxvBjITemDTfi_1KrCA%3D" alt="Jodh Singh" width="60" height="60" style="border-radius:8px;margin:5px;">
|
252 |
+
<img src="https://c8.patreon.com/3/200/22809690" alt="Michael Levine" width="60" height="60" style="border-radius:8px;margin:5px;">
|
253 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/99036356/7ae9c4d80e604e739b68cca12ee2ed01/eyJ3IjoyMDB9/3.png?token-time=2145916800&token-hash=zK0dHe6A937WtNlrGdefoXFTPPzHUCfn__23HP8-Ui0%3D" alt="Noctre" width="60" height="60" style="border-radius:8px;margin:5px;">
|
254 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/141098579/1a9f0a1249d447a7a0df718a57343912/eyJ3IjoyMDB9/2.png?token-time=2145916800&token-hash=Rd_AjZGhMATVkZDf8E95ILc0n93gvvFWe1Ig0_dxwf4%3D" alt="The Local Lab" width="60" height="60" style="border-radius:8px;margin:5px;">
|
255 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/98811435/3a3632d1795b4c2b9f8f0270f2f6a650/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=93w8RMxwXlcM4X74t03u6P5_SrKvlm1IpjnD2SzVpJk%3D" alt="EmmanuelMr18" width="60" height="60" style="border-radius:8px;margin:5px;">
|
256 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/338551/e8f257d8d3dd46c38272b391a5785948/eyJ3IjoyMDB9/1.jpg?token-time=2145916800&token-hash=GLom1rGgOZjBeO7I1OnjiIgWmjl6PO9ZjBB8YTvc7AM%3D" alt="Plaidam" width="60" height="60" style="border-radius:8px;margin:5px;">
|
257 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/82763/f99cc484361d4b9d94fe4f0814ada303/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=BpwC020pR3TRZ4r0RSCiSIOh-jmatkrpy1h2XU4sGa4%3D" alt="Doron Adler" width="60" height="60" style="border-radius:8px;margin:5px;">
|
258 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/103077711/bb215761cc004e80bd9cec7d4bcd636d/eyJ3IjoyMDB9/2.jpeg?token-time=2145916800&token-hash=zvtBie29rRTKTXvAA2KhOI-l3mSMk9xxr-mg_CksLtc%3D" alt="John Dopamine" width="60" height="60" style="border-radius:8px;margin:5px;">
|
259 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/93348210/5c650f32a0bc481d80900d2674528777/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=PpXK9B_iy288annlNdLOexhiQHbTftPEDeCh-sTQ2KA%3D" alt="Armin Behjati" width="60" height="60" style="border-radius:8px;margin:5px;">
|
260 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/155963250/6f8fd7075c3b4247bfeb054ba49172d6/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=twmKs4mADF_h7bKh5jBuigYVScMeaeHv2pEPin9K0Dg%3D" alt="Un Defined" width="60" height="60" style="border-radius:8px;margin:5px;">
|
261 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/45562978/0de33cf52ec642ae8a2f612cddec4ca6/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=hSAvaD4phiLcF0pvX7FP0juI5NQWCon-_TZSNpJzQJg%3D" alt="Jack English" width="60" height="60" style="border-radius:8px;margin:5px;">
|
262 |
+
<img src="https://c8.patreon.com/3/200/27791680" alt="Jean-Tristan Marin" width="60" height="60" style="border-radius:8px;margin:5px;">
|
263 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/60995694/92e0e8f336eb4a5bb8d99b940247d1d1/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=pj6Tm8XRdpGJcAEdnCakqYSNiSjoAYjvZescX7d0ic0%3D" alt="Abraham Irawan" width="60" height="60" style="border-radius:8px;margin:5px;">
|
264 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/164958178/4eb7a37baa0541bab7a091f2b14615b7/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=_aaum7fBJAGaJhMBhlR8vqYavDhExdVxmO9mwd3_XMw%3D" alt="Austin Robinson" width="60" height="60" style="border-radius:8px;margin:5px;">
|
265 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/134129880/680c7e14cd1a4d1a9face921fb010f88/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=vNKojv67krNqx7gdpKBX1R_stX2TkMRYvRc0xZrbY6s%3D" alt="Bharat Prabhakar" width="60" height="60" style="border-radius:8px;margin:5px;">
|
266 |
+
<img src="https://c8.patreon.com/3/200/70218846" alt="Cosmosis" width="60" height="60" style="border-radius:8px;margin:5px;">
|
267 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/83054970/13de6cb103ad41a5841edf549e66cd51/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=wU_Eke9VYcfI40FAQvdEV84Xspqlo5VSiafLqhg_FOE%3D" alt="Gili Ben Shahar" width="60" height="60" style="border-radius:8px;margin:5px;">
|
268 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/30931983/54ab4e4ceab946e79a6418d205f9ed51/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=LBmsSsMQZhO6yRZ_YyRwTgE6a7BVWrGNsAVveLXHXR0%3D" alt="HestoySeghuro ." width="60" height="60" style="border-radius:8px;margin:5px;">
|
269 |
+
<img src="https://c8.patreon.com/3/200/4105384" alt="Jack Blakely" width="60" height="60" style="border-radius:8px;margin:5px;">
|
270 |
+
<img src="https://c8.patreon.com/3/200/494309" alt="Julian Tsependa" width="60" height="60" style="border-radius:8px;margin:5px;">
|
271 |
+
<img src="https://c8.patreon.com/3/200/24653779" alt="RayHell" width="60" height="60" style="border-radius:8px;margin:5px;">
|
272 |
+
<img src="https://c8.patreon.com/3/200/4541423" alt="Sören " width="60" height="60" style="border-radius:8px;margin:5px;">
|
273 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/31950857/c567dc648f6144be9f6234946df05da2/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=3Vx4R1eOfD4X_ZPPd40MsZ-3lyknLM35XmaHRELnWjM%3D" alt="Trent Hunter" width="60" height="60" style="border-radius:8px;margin:5px;">
|
274 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/110407414/30f9e9d88ef945ddb0f47fd23a8cbac2/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=QQRWOkMyOfDBERHn4O8N2wMB32zeiIEsydVTbSNUw-I%3D" alt="Wesley Reitzfeld" width="60" height="60" style="border-radius:8px;margin:5px;">
|
275 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/162398691/89d78d89eecb4d6b981ce8c3c6a3d4b8/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=SWhI-0jGpY6Nc_bUQeXz4pa9DRURi9VnnnJ3Mxjg1po%3D" alt="Zoltán-Csaba Nyiró" width="60" height="60" style="border-radius:8px;margin:5px;">
|
276 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/97985240/3d1d0e6905d045aba713e8132cab4a30/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=pG3X2m-py2lRYI2aoJiXI47_4ArD78ZHdSm6jCAHA_w%3D" alt="עומר מכלוף" width="60" height="60" style="border-radius:8px;margin:5px;">
|
277 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/140599287/cff037fb93804af28bc3a4f1e91154f8/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=vkscmpmFoM5wq7GnsLmOEgNhvyXe-774kNGNqD0wurE%3D" alt="Lukas" width="60" height="60" style="border-radius:8px;margin:5px;">
|
278 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/96561218/b0694642d13a49faa75aec9762ff2aeb/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=sLQXomYm1iMYpknvGwKQ49f30TKQ0B1R2W3EZfCJqr8%3D" alt="Ultimate Golf Archives" width="60" height="60" style="border-radius:8px;margin:5px;">
|
279 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/81275465/1e4148fe9c47452b838949d02dd9a70f/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=uzJzkUq9rte3wx8wDLjGAgvSoxdtZcAnH7HctDhdYEo%3D" alt="Aaron Amortegui" width="60" height="60" style="border-radius:8px;margin:5px;">
|
280 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/44568304/a9d83a0e786b41b4bdada150f7c9271c/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=SBphTD654nwr-OTrvIBIJBEQho7GE2PtRre8nyaG1Fk%3D" alt="Albert Bukoski" width="60" height="60" style="border-radius:8px;margin:5px;">
|
281 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/49304261/d0a730de1c3349e585c49288b9f419c6/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=C2BMZ3ci-Ty2nhnSwKZqsR-5hOGsUNDYcvXps0Geq9w%3D" alt="Arvin Flores" width="60" height="60" style="border-radius:8px;margin:5px;">
|
282 |
+
<img src="https://c8.patreon.com/3/200/5048649" alt="Ben Ward" width="60" height="60" style="border-radius:8px;margin:5px;">
|
283 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/130338124/f904a3bb76cd4588ac8d8f595c6cb486/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=k-inISRUtYDu9q7fNAKc3S2S7qcaw26fr1pj7PqU28Q%3D" alt="Bnp" width="60" height="60" style="border-radius:8px;margin:5px;">
|
284 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/111904990/08b1cf65be6a4de091c9b73b693b3468/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=OAJc9W5Ak0uJfQ2COlo1Upo38K3aj1fMQFCMC7ft5tM%3D" alt="Brian Smith" width="60" height="60" style="border-radius:8px;margin:5px;">
|
285 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/113207022/d4a67cc113e84fb69032bef71d068720/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=mu-tIg88VwoQdgLEOmxuVkhVm9JT59DdnHXJstmkkLU%3D" alt="Fagem X" width="60" height="60" style="border-radius:8px;margin:5px;">
|
286 |
+
<img src="https://c8.patreon.com/3/200/5602036" alt="Kelevra" width="60" height="60" style="border-radius:8px;margin:5px;">
|
287 |
+
<img src="https://c8.patreon.com/3/200/358350" alt="L D" width="60" height="60" style="border-radius:8px;margin:5px;">
|
288 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/159203973/36c817f941ac4fa18103a4b8c0cb9cae/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=9toslDfsO14QyaOiu6vIf--d4marBsWCZWN3gdPqbIU%3D" alt="Marko jak" width="60" height="60" style="border-radius:8px;margin:5px;">
|
289 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/11198131/e696d9647feb4318bcf16243c2425805/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=o6Hrpzw9rf2Ucd4cZ-hdUkGejLNv44-pqF8smeOF3ts%3D" alt="Nicholas Agranoff" width="60" height="60" style="border-radius:8px;margin:5px;">
|
290 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/785333/bdb9ede5765d42e5a2021a86eebf0d8f/eyJ3IjoyMDB9/2.jpg?token-time=2145916800&token-hash=dr5eaMg3Ua0wyCy40Qv3F-ZFajWZmuz2fWG55FskREc%3D" alt="Sapjes " width="60" height="60" style="border-radius:8px;margin:5px;">
|
291 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/44738426/b01ff676da864d4ab9c21f226275b63e/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=54nIkcxFaGszJ3q0jNhtrVSBbV3WNK9e5WX9VzXltYk%3D" alt="Shakeel Saleemi" width="60" height="60" style="border-radius:8px;margin:5px;">
|
292 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/76566911/6485eaf5ec6249a7b524ee0b979372f0/eyJ3IjoyMDB9/1.jpeg?token-time=2145916800&token-hash=S1QK78ief5byQU7tB_reqnw4V2zhW_cpwTqHThk-tGc%3D" alt="the biitz" width="60" height="60" style="border-radius:8px;margin:5px;">
|
293 |
+
<img src="https://c8.patreon.com/3/200/83034" alt="william tatum" width="60" height="60" style="border-radius:8px;margin:5px;">
|
294 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/32633822/1ab5612efe80417cbebfe91e871fc052/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=RHYMcjr0UGIYw5FBrUfJdKMGuoYWhBQlLIykccEFJvo%3D" alt="Zack Abrams" width="60" height="60" style="border-radius:8px;margin:5px;">
|
295 |
+
<img src="https://c10.patreonusercontent.com/4/patreon-media/p/user/138787189/2b5662dcb638466282ac758e3ac651b4/eyJ3IjoyMDB9/1.png?token-time=2145916800&token-hash=IlUAs9JAlVRphfx81V-Jt-nMiSBS8mPewRr9u6pQjaQ%3D" alt="Антон Антонио" width="60" height="60" style="border-radius:8px;margin:5px;">
|
296 |
</p>
|
297 |
|
298 |
---
|
pipeline.py
ADDED
@@ -0,0 +1,440 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import FluxControlPipeline, FluxTransformer2DModel
|
2 |
+
from typing import Any, Callable, Dict, List, Optional, Union
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from diffusers.image_processor import PipelineImageInput
|
6 |
+
import numpy as np
|
7 |
+
import torch.nn.functional as F
|
8 |
+
from diffusers.pipelines.flux.pipeline_output import FluxPipelineOutput
|
9 |
+
from diffusers.pipelines.flux.pipeline_flux import calculate_shift, retrieve_timesteps, XLA_AVAILABLE
|
10 |
+
|
11 |
+
|
12 |
+
class Flex2Pipeline(FluxControlPipeline):
|
13 |
+
def __init__(
|
14 |
+
self,
|
15 |
+
scheduler,
|
16 |
+
vae,
|
17 |
+
text_encoder,
|
18 |
+
tokenizer,
|
19 |
+
text_encoder_2,
|
20 |
+
tokenizer_2,
|
21 |
+
transformer,
|
22 |
+
):
|
23 |
+
super().__init__(scheduler, vae, text_encoder, tokenizer, text_encoder_2, tokenizer_2, transformer)
|
24 |
+
|
25 |
+
def check_inputs(
|
26 |
+
self,
|
27 |
+
prompt,
|
28 |
+
prompt_2,
|
29 |
+
height,
|
30 |
+
width,
|
31 |
+
prompt_embeds=None,
|
32 |
+
pooled_prompt_embeds=None,
|
33 |
+
callback_on_step_end_tensor_inputs=None,
|
34 |
+
max_sequence_length=None,
|
35 |
+
inpaint_image=None,
|
36 |
+
inpaint_mask=None,
|
37 |
+
control_image=None,
|
38 |
+
):
|
39 |
+
super().check_inputs(
|
40 |
+
prompt,
|
41 |
+
prompt_2,
|
42 |
+
height,
|
43 |
+
width,
|
44 |
+
prompt_embeds=prompt_embeds,
|
45 |
+
pooled_prompt_embeds=pooled_prompt_embeds,
|
46 |
+
callback_on_step_end_tensor_inputs=callback_on_step_end_tensor_inputs,
|
47 |
+
max_sequence_length=max_sequence_length,
|
48 |
+
)
|
49 |
+
if inpaint_image is not None and inpaint_mask is None:
|
50 |
+
raise ValueError(
|
51 |
+
"If `inpaint_image` is passed, `inpaint_mask` must be passed as well. "
|
52 |
+
"Please make sure to pass both `inpaint_image` and `inpaint_mask`."
|
53 |
+
)
|
54 |
+
if inpaint_mask is not None and inpaint_image is None:
|
55 |
+
raise ValueError(
|
56 |
+
"If `inpaint_mask` is passed, `inpaint_image` must be passed as well. "
|
57 |
+
"Please make sure to pass both `inpaint_image` and `inpaint_mask`."
|
58 |
+
)
|
59 |
+
|
60 |
+
@torch.no_grad()
|
61 |
+
def __call__(
|
62 |
+
self,
|
63 |
+
prompt: Union[str, List[str]] = None,
|
64 |
+
prompt_2: Optional[Union[str, List[str]]] = None,
|
65 |
+
inpaint_image: Optional[PipelineImageInput] = None,
|
66 |
+
inpaint_mask: Optional[PipelineImageInput] = None,
|
67 |
+
control_image: Optional[PipelineImageInput] = None,
|
68 |
+
control_strength: Optional[float] = 1.0,
|
69 |
+
control_stop: Optional[float] = 1.0,
|
70 |
+
height: Optional[int] = None,
|
71 |
+
width: Optional[int] = None,
|
72 |
+
num_inference_steps: int = 28,
|
73 |
+
sigmas: Optional[List[float]] = None,
|
74 |
+
guidance_scale: float = 3.5,
|
75 |
+
num_images_per_prompt: Optional[int] = 1,
|
76 |
+
generator: Optional[Union[torch.Generator, List[torch.Generator]]] = None,
|
77 |
+
latents: Optional[torch.FloatTensor] = None,
|
78 |
+
prompt_embeds: Optional[torch.FloatTensor] = None,
|
79 |
+
pooled_prompt_embeds: Optional[torch.FloatTensor] = None,
|
80 |
+
output_type: Optional[str] = "pil",
|
81 |
+
return_dict: bool = True,
|
82 |
+
joint_attention_kwargs: Optional[Dict[str, Any]] = None,
|
83 |
+
callback_on_step_end: Optional[Callable[[int, int, Dict], None]] = None,
|
84 |
+
callback_on_step_end_tensor_inputs: List[str] = ["latents"],
|
85 |
+
max_sequence_length: int = 512,
|
86 |
+
**kwargs,
|
87 |
+
):
|
88 |
+
r"""
|
89 |
+
Function invoked when calling the pipeline for generation.
|
90 |
+
|
91 |
+
Args:
|
92 |
+
prompt (`str` or `List[str]`, *optional*):
|
93 |
+
The prompt or prompts to guide the image generation. If not defined, one has to pass `prompt_embeds`.
|
94 |
+
instead.
|
95 |
+
prompt_2 (`str` or `List[str]`, *optional*):
|
96 |
+
The prompt or prompts to be sent to `tokenizer_2` and `text_encoder_2`. If not defined, `prompt` is
|
97 |
+
will be used instead
|
98 |
+
inpaint_image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
|
99 |
+
`List[List[torch.Tensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
|
100 |
+
The image to be inpainted.
|
101 |
+
inpaint_mask (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
|
102 |
+
`List[List[torch.Tensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
|
103 |
+
A black and white mask to be used for inpainting. The white pixels are the areas to be inpainted, while the
|
104 |
+
black pixels are the areas to be kept.
|
105 |
+
control_image (`torch.Tensor`, `PIL.Image.Image`, `np.ndarray`, `List[torch.Tensor]`, `List[PIL.Image.Image]`, `List[np.ndarray]`,:
|
106 |
+
`List[List[torch.Tensor]]`, `List[List[np.ndarray]]` or `List[List[PIL.Image.Image]]`):
|
107 |
+
The control image (line, depth, pose, etc.) to be used for the generation. The control image
|
108 |
+
control_strength (`float`, *optional*, defaults to 1.0):
|
109 |
+
The strength of the control image. The higher the value, the more the control image will be used to
|
110 |
+
guide the generation. The lower the value, the less the control image will be used to guide the
|
111 |
+
generation.
|
112 |
+
control_stop (`float`, *optional*, defaults to 1.0):
|
113 |
+
The percentage of the generation to drop out the control. 0.0 to 1.0. 0.5 mean the control will be dropped
|
114 |
+
out at 50% of the generation.
|
115 |
+
height (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
|
116 |
+
The height in pixels of the generated image. This is set to 1024 by default for the best results.
|
117 |
+
width (`int`, *optional*, defaults to self.unet.config.sample_size * self.vae_scale_factor):
|
118 |
+
The width in pixels of the generated image. This is set to 1024 by default for the best results.
|
119 |
+
num_inference_steps (`int`, *optional*, defaults to 50):
|
120 |
+
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
121 |
+
expense of slower inference.
|
122 |
+
sigmas (`List[float]`, *optional*):
|
123 |
+
Custom sigmas to use for the denoising process with schedulers which support a `sigmas` argument in
|
124 |
+
their `set_timesteps` method. If not defined, the default behavior when `num_inference_steps` is passed
|
125 |
+
will be used.
|
126 |
+
guidance_scale (`float`, *optional*, defaults to 3.5):
|
127 |
+
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
|
128 |
+
`guidance_scale` is defined as `w` of equation 2. of [Imagen
|
129 |
+
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
|
130 |
+
1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
|
131 |
+
usually at the expense of lower image quality.
|
132 |
+
num_images_per_prompt (`int`, *optional*, defaults to 1):
|
133 |
+
The number of images to generate per prompt.
|
134 |
+
generator (`torch.Generator` or `List[torch.Generator]`, *optional*):
|
135 |
+
One or a list of [torch generator(s)](https://pytorch.org/docs/stable/generated/torch.Generator.html)
|
136 |
+
to make generation deterministic.
|
137 |
+
latents (`torch.FloatTensor`, *optional*):
|
138 |
+
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
|
139 |
+
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
|
140 |
+
tensor will ge generated by sampling using the supplied random `generator`.
|
141 |
+
prompt_embeds (`torch.FloatTensor`, *optional*):
|
142 |
+
Pre-generated text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting. If not
|
143 |
+
provided, text embeddings will be generated from `prompt` input argument.
|
144 |
+
pooled_prompt_embeds (`torch.FloatTensor`, *optional*):
|
145 |
+
Pre-generated pooled text embeddings. Can be used to easily tweak text inputs, *e.g.* prompt weighting.
|
146 |
+
If not provided, pooled text embeddings will be generated from `prompt` input argument.
|
147 |
+
output_type (`str`, *optional*, defaults to `"pil"`):
|
148 |
+
The output format of the generate image. Choose between
|
149 |
+
[PIL](https://pillow.readthedocs.io/en/stable/): `PIL.Image.Image` or `np.array`.
|
150 |
+
return_dict (`bool`, *optional*, defaults to `True`):
|
151 |
+
Whether or not to return a [`~pipelines.flux.FluxPipelineOutput`] instead of a plain tuple.
|
152 |
+
joint_attention_kwargs (`dict`, *optional*):
|
153 |
+
A kwargs dictionary that if specified is passed along to the `AttentionProcessor` as defined under
|
154 |
+
`self.processor` in
|
155 |
+
[diffusers.models.attention_processor](https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py).
|
156 |
+
callback_on_step_end (`Callable`, *optional*):
|
157 |
+
A function that calls at the end of each denoising steps during the inference. The function is called
|
158 |
+
with the following arguments: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int,
|
159 |
+
callback_kwargs: Dict)`. `callback_kwargs` will include a list of all tensors as specified by
|
160 |
+
`callback_on_step_end_tensor_inputs`.
|
161 |
+
callback_on_step_end_tensor_inputs (`List`, *optional*):
|
162 |
+
The list of tensor inputs for the `callback_on_step_end` function. The tensors specified in the list
|
163 |
+
will be passed as `callback_kwargs` argument. You will only be able to include variables listed in the
|
164 |
+
`._callback_tensor_inputs` attribute of your pipeline class.
|
165 |
+
max_sequence_length (`int` defaults to 512): Maximum sequence length to use with the `prompt`.
|
166 |
+
|
167 |
+
Examples:
|
168 |
+
|
169 |
+
Returns:
|
170 |
+
[`~pipelines.flux.FluxPipelineOutput`] or `tuple`: [`~pipelines.flux.FluxPipelineOutput`] if `return_dict`
|
171 |
+
is True, otherwise a `tuple`. When returning a tuple, the first element is a list with the generated
|
172 |
+
images.
|
173 |
+
"""
|
174 |
+
|
175 |
+
height = height or self.default_sample_size * self.vae_scale_factor
|
176 |
+
width = width or self.default_sample_size * self.vae_scale_factor
|
177 |
+
|
178 |
+
# 1. Check inputs. Raise error if not correct
|
179 |
+
self.check_inputs(
|
180 |
+
prompt,
|
181 |
+
prompt_2,
|
182 |
+
height,
|
183 |
+
width,
|
184 |
+
prompt_embeds=prompt_embeds,
|
185 |
+
pooled_prompt_embeds=pooled_prompt_embeds,
|
186 |
+
callback_on_step_end_tensor_inputs=callback_on_step_end_tensor_inputs,
|
187 |
+
max_sequence_length=max_sequence_length,
|
188 |
+
)
|
189 |
+
|
190 |
+
self._guidance_scale = guidance_scale
|
191 |
+
self._joint_attention_kwargs = joint_attention_kwargs
|
192 |
+
self._interrupt = False
|
193 |
+
|
194 |
+
# 2. Define call parameters
|
195 |
+
if prompt is not None and isinstance(prompt, str):
|
196 |
+
batch_size = 1
|
197 |
+
elif prompt is not None and isinstance(prompt, list):
|
198 |
+
batch_size = len(prompt)
|
199 |
+
else:
|
200 |
+
batch_size = prompt_embeds.shape[0]
|
201 |
+
|
202 |
+
device = self._execution_device
|
203 |
+
|
204 |
+
# 3. Prepare text embeddings
|
205 |
+
lora_scale = (
|
206 |
+
self.joint_attention_kwargs.get("scale", None) if self.joint_attention_kwargs is not None else None
|
207 |
+
)
|
208 |
+
(
|
209 |
+
prompt_embeds,
|
210 |
+
pooled_prompt_embeds,
|
211 |
+
text_ids,
|
212 |
+
) = self.encode_prompt(
|
213 |
+
prompt=prompt,
|
214 |
+
prompt_2=prompt_2,
|
215 |
+
prompt_embeds=prompt_embeds,
|
216 |
+
pooled_prompt_embeds=pooled_prompt_embeds,
|
217 |
+
device=device,
|
218 |
+
num_images_per_prompt=num_images_per_prompt,
|
219 |
+
max_sequence_length=max_sequence_length,
|
220 |
+
lora_scale=lora_scale,
|
221 |
+
)
|
222 |
+
|
223 |
+
# 4. Prepare latent variables
|
224 |
+
num_channels_latents = self.transformer.config.in_channels // 4
|
225 |
+
|
226 |
+
# only prepare latents for non controls
|
227 |
+
# (16 + 1 + 16 )
|
228 |
+
num_control_channels = 33
|
229 |
+
num_channels_latents = num_channels_latents - num_control_channels
|
230 |
+
|
231 |
+
control_latents = None
|
232 |
+
inpaint_latents = None
|
233 |
+
inpaint_latents_mask = None
|
234 |
+
|
235 |
+
latent_height = height // self.vae_scale_factor
|
236 |
+
latent_width = width // self.vae_scale_factor
|
237 |
+
|
238 |
+
# process the control and inpaint channels
|
239 |
+
|
240 |
+
if control_image is None:
|
241 |
+
control_latents = torch.zeros(
|
242 |
+
batch_size * num_images_per_prompt,
|
243 |
+
3,
|
244 |
+
latent_height,
|
245 |
+
latent_width,
|
246 |
+
device=device,
|
247 |
+
dtype=self.vae.dtype,
|
248 |
+
)
|
249 |
+
else:
|
250 |
+
control_image = self.prepare_image(
|
251 |
+
image=control_image,
|
252 |
+
width=width,
|
253 |
+
height=height,
|
254 |
+
batch_size=batch_size * num_images_per_prompt,
|
255 |
+
num_images_per_prompt=num_images_per_prompt,
|
256 |
+
device=device,
|
257 |
+
dtype=self.vae.dtype,
|
258 |
+
)
|
259 |
+
control_image = self.vae.encode(control_image).latent_dist.sample(generator=generator)
|
260 |
+
control_latents = (control_image - self.vae.config.shift_factor) * self.vae.config.scaling_factor
|
261 |
+
|
262 |
+
# apply control strength
|
263 |
+
control_latents = control_latents * control_strength
|
264 |
+
|
265 |
+
if inpaint_image is None and inpaint_mask is None:
|
266 |
+
inpaint_latents = torch.zeros(
|
267 |
+
batch_size * num_images_per_prompt,
|
268 |
+
3,
|
269 |
+
latent_height,
|
270 |
+
latent_width,
|
271 |
+
device=device,
|
272 |
+
dtype=self.vae.dtype,
|
273 |
+
)
|
274 |
+
inpaint_latents_mask = torch.ones(
|
275 |
+
batch_size * num_images_per_prompt,
|
276 |
+
1,
|
277 |
+
latent_height,
|
278 |
+
latent_width,
|
279 |
+
device=device,
|
280 |
+
dtype=self.vae.dtype,
|
281 |
+
)
|
282 |
+
else:
|
283 |
+
inpaint_image = self.prepare_image(
|
284 |
+
image=inpaint_image,
|
285 |
+
width=width,
|
286 |
+
height=height,
|
287 |
+
batch_size=batch_size * num_images_per_prompt,
|
288 |
+
num_images_per_prompt=num_images_per_prompt,
|
289 |
+
device=device,
|
290 |
+
dtype=self.vae.dtype,
|
291 |
+
)
|
292 |
+
inpaint_image = self.vae.encode(inpaint_image).latent_dist.sample(generator=generator)
|
293 |
+
inpaint_latents = (inpaint_image - self.vae.config.shift_factor) * self.vae.config.scaling_factor
|
294 |
+
height_inpaint_image, width_inpaint_image = control_image.shape[2:]
|
295 |
+
|
296 |
+
inpaint_mask = self.prepare_image(
|
297 |
+
image=inpaint_mask,
|
298 |
+
width=width,
|
299 |
+
height=height,
|
300 |
+
batch_size=batch_size * num_images_per_prompt,
|
301 |
+
num_images_per_prompt=num_images_per_prompt,
|
302 |
+
device=device,
|
303 |
+
dtype=self.vae.dtype,
|
304 |
+
)
|
305 |
+
# mask is 3 ch -1 to 1. make it 1ch, 0 to 1
|
306 |
+
inpaint_mask = inpaint_mask[:, 0:1, :, :] * 0.5 + 0.5
|
307 |
+
# resize to match height_inpaint_image and width_inpaint_image
|
308 |
+
inpaint_latents_mask = F.interpolate(inpaint_mask, size=(height_inpaint_image, width_inpaint_image), mode="bilinear", align_corners=False)
|
309 |
+
|
310 |
+
# apply inverted mask to inpaint latents
|
311 |
+
inpaint_latents = inpaint_latents * (1 - inpaint_latents_mask)
|
312 |
+
|
313 |
+
# concat the latent controls on the channel dimension every step
|
314 |
+
latent_controls = torch.cat([inpaint_latents, inpaint_latents_mask, control_latents], dim=1)
|
315 |
+
latent_no_controls = torch.cat([inpaint_latents, inpaint_latents_mask, torch.zeros_like(control_latents)], dim=1)
|
316 |
+
|
317 |
+
# pack the controls
|
318 |
+
height_latent_controls, width_latent_controls = latent_controls.shape[2:]
|
319 |
+
packed_latent_controls = self._pack_latents(
|
320 |
+
latent_controls,
|
321 |
+
batch_size * num_images_per_prompt,
|
322 |
+
num_control_channels,
|
323 |
+
height_latent_controls,
|
324 |
+
width_latent_controls,
|
325 |
+
)
|
326 |
+
packed_latent_no_controls = self._pack_latents(
|
327 |
+
latent_no_controls,
|
328 |
+
batch_size * num_images_per_prompt,
|
329 |
+
num_control_channels,
|
330 |
+
height_latent_controls,
|
331 |
+
width_latent_controls,
|
332 |
+
)
|
333 |
+
|
334 |
+
latents, latent_image_ids = self.prepare_latents(
|
335 |
+
batch_size * num_images_per_prompt,
|
336 |
+
num_channels_latents,
|
337 |
+
height,
|
338 |
+
width,
|
339 |
+
prompt_embeds.dtype,
|
340 |
+
device,
|
341 |
+
generator,
|
342 |
+
latents,
|
343 |
+
)
|
344 |
+
|
345 |
+
# 5. Prepare timesteps
|
346 |
+
sigmas = np.linspace(1.0, 1 / num_inference_steps, num_inference_steps) if sigmas is None else sigmas
|
347 |
+
image_seq_len = latents.shape[1]
|
348 |
+
mu = calculate_shift(
|
349 |
+
image_seq_len,
|
350 |
+
self.scheduler.config.get("base_image_seq_len", 256),
|
351 |
+
self.scheduler.config.get("max_image_seq_len", 4096),
|
352 |
+
self.scheduler.config.get("base_shift", 0.5),
|
353 |
+
self.scheduler.config.get("max_shift", 1.15),
|
354 |
+
)
|
355 |
+
timesteps, num_inference_steps = retrieve_timesteps(
|
356 |
+
self.scheduler,
|
357 |
+
num_inference_steps,
|
358 |
+
device,
|
359 |
+
sigmas=sigmas,
|
360 |
+
mu=mu,
|
361 |
+
)
|
362 |
+
num_warmup_steps = max(len(timesteps) - num_inference_steps * self.scheduler.order, 0)
|
363 |
+
self._num_timesteps = len(timesteps)
|
364 |
+
|
365 |
+
# handle guidance
|
366 |
+
if self.transformer.config.guidance_embeds:
|
367 |
+
guidance = torch.full([1], guidance_scale, device=device, dtype=torch.float32)
|
368 |
+
guidance = guidance.expand(latents.shape[0])
|
369 |
+
else:
|
370 |
+
guidance = None
|
371 |
+
|
372 |
+
control_cutoff = int(len(timesteps) * control_stop)
|
373 |
+
|
374 |
+
# 6. Denoising loop
|
375 |
+
with self.progress_bar(total=num_inference_steps) as progress_bar:
|
376 |
+
for i, t in enumerate(timesteps):
|
377 |
+
if self.interrupt:
|
378 |
+
continue
|
379 |
+
|
380 |
+
control_latents = packed_latent_controls if i < control_cutoff else packed_latent_no_controls
|
381 |
+
|
382 |
+
latent_model_input = torch.cat([latents, control_latents], dim=2)
|
383 |
+
|
384 |
+
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
|
385 |
+
timestep = t.expand(latents.shape[0]).to(latents.dtype)
|
386 |
+
|
387 |
+
noise_pred = self.transformer(
|
388 |
+
hidden_states=latent_model_input,
|
389 |
+
timestep=timestep / 1000,
|
390 |
+
guidance=guidance,
|
391 |
+
pooled_projections=pooled_prompt_embeds,
|
392 |
+
encoder_hidden_states=prompt_embeds,
|
393 |
+
txt_ids=text_ids,
|
394 |
+
img_ids=latent_image_ids,
|
395 |
+
joint_attention_kwargs=self.joint_attention_kwargs,
|
396 |
+
return_dict=False,
|
397 |
+
)[0]
|
398 |
+
|
399 |
+
# compute the previous noisy sample x_t -> x_t-1
|
400 |
+
latents_dtype = latents.dtype
|
401 |
+
latents = self.scheduler.step(noise_pred, t, latents, return_dict=False)[0]
|
402 |
+
|
403 |
+
if latents.dtype != latents_dtype:
|
404 |
+
if torch.backends.mps.is_available():
|
405 |
+
# some platforms (eg. apple mps) misbehave due to a pytorch bug: https://github.com/pytorch/pytorch/pull/99272
|
406 |
+
latents = latents.to(latents_dtype)
|
407 |
+
|
408 |
+
if callback_on_step_end is not None:
|
409 |
+
callback_kwargs = {}
|
410 |
+
for k in callback_on_step_end_tensor_inputs:
|
411 |
+
callback_kwargs[k] = locals()[k]
|
412 |
+
callback_outputs = callback_on_step_end(self, i, t, callback_kwargs)
|
413 |
+
|
414 |
+
latents = callback_outputs.pop("latents", latents)
|
415 |
+
prompt_embeds = callback_outputs.pop("prompt_embeds", prompt_embeds)
|
416 |
+
|
417 |
+
# call the callback, if provided
|
418 |
+
if i == len(timesteps) - 1 or ((i + 1) > num_warmup_steps and (i + 1) % self.scheduler.order == 0):
|
419 |
+
progress_bar.update()
|
420 |
+
|
421 |
+
if XLA_AVAILABLE:
|
422 |
+
xm.mark_step()
|
423 |
+
|
424 |
+
if output_type == "latent":
|
425 |
+
image = latents
|
426 |
+
else:
|
427 |
+
latents = self._unpack_latents(latents, height, width, self.vae_scale_factor)
|
428 |
+
latents = (latents / self.vae.config.scaling_factor) + self.vae.config.shift_factor
|
429 |
+
image = self.vae.decode(latents, return_dict=False)[0]
|
430 |
+
image = self.image_processor.postprocess(image, output_type=output_type)
|
431 |
+
|
432 |
+
# Offload all models
|
433 |
+
self.maybe_free_model_hooks()
|
434 |
+
|
435 |
+
if not return_dict:
|
436 |
+
return (image,)
|
437 |
+
|
438 |
+
return FluxPipelineOutput(images=image)
|
439 |
+
|
440 |
+
|