nynxz commited on
Commit
ebf1c59
·
unverified ·
1 Parent(s): 8643971

Add ComfyUI-ready LoRA, examples, converter, README, LICENSE

Browse files
.gitattributes CHANGED
@@ -1,38 +1,7 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
  *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
  *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
  *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
36
  *.jpg filter=lfs diff=lfs merge=lfs -text
37
  *.jpeg filter=lfs diff=lfs merge=lfs -text
38
  *.png filter=lfs diff=lfs merge=lfs -text
 
1
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
 
2
  *.bin filter=lfs diff=lfs merge=lfs -text
 
3
  *.ckpt filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  *.pt filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  *.jpg filter=lfs diff=lfs merge=lfs -text
6
  *.jpeg filter=lfs diff=lfs merge=lfs -text
7
  *.png filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 tracking or 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 describing the origin of the Work and
141
+ 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 Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 RealGen-V2 contributors.
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
189
+ implied. See the License for the specific language governing
190
+ permissions and limitations under the License.
README.md ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model:
4
+ - Tongyi-MAI/Z-Image
5
+ - Tongyi-MAI/Z-Image-Turbo
6
+ base_model_relation: adapter
7
+ pipeline_tag: text-to-image
8
+ library_name: diffusers
9
+ tags:
10
+ - lora
11
+ - text-to-image
12
+ - z-image
13
+ - comfyui
14
+ - realism
15
+ ---
16
+
17
+ # RealGen-V2 — ComfyUI-ready LoRA for Z-Image
18
+
19
+ A drop-in [ComfyUI](https://github.com/comfyanonymous/ComfyUI) build of
20
+ [Yunncheng/RealGen-V2](https://huggingface.co/Yunncheng/RealGen-V2). Same
21
+ weights as upstream, repackaged so ComfyUI's stock `LoraLoader` can load it
22
+ without a custom node. Works on both Z-Image base and Z-Image-Turbo.
23
+
24
+ ## Examples
25
+
26
+ Each row is the **same prompt and seed**, rendered with and without the LoRA
27
+ at strength `1.0`.
28
+
29
+ ### [Z-Image (base)](https://huggingface.co/Tongyi-MAI/Z-Image)
30
+
31
+ | Without LoRA | With RealGen-V2 |
32
+ | --- | --- |
33
+ | ![Z-Image base, prompt 1, no LoRA](examples/base/z-image-regular_00001_.jpg) | ![Z-Image base, prompt 1, with RealGen-V2](examples/base/z-image-realgen_00001_.jpg) |
34
+ | ![Z-Image base, prompt 2, no LoRA](examples/base/z-image-regular_00002_.jpg) | ![Z-Image base, prompt 2, with RealGen-V2](examples/base/z-image-realgen_00002_.jpg) |
35
+ | ![Z-Image base, prompt 3, no LoRA](examples/base/z-image-regular_00003_.jpg) | ![Z-Image base, prompt 3, with RealGen-V2](examples/base/z-image-realgen_00003_.jpg) |
36
+ | ![Z-Image base, prompt 4, no LoRA](examples/base/z-image-regular_00004_.jpg) | ![Z-Image base, prompt 4, with RealGen-V2](examples/base/z-image-realgen_00004_.jpg) |
37
+ | ![Z-Image base, prompt 5, no LoRA](examples/base/z-image-regular_00005_.jpg) | ![Z-Image base, prompt 5, with RealGen-V2](examples/base/z-image-realgen_00005_.jpg) |
38
+
39
+ ### [Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo)
40
+
41
+ | Without LoRA | With RealGen-V2 |
42
+ | --- | --- |
43
+ | ![Z-Image-Turbo, prompt 1, no LoRA](examples/turbo/z-image-turbo-regular_00001_.jpg) | ![Z-Image-Turbo, prompt 1, with RealGen-V2](examples/turbo/z-image-turbo-realgen_00001_.jpg) |
44
+ | ![Z-Image-Turbo, prompt 2, no LoRA](examples/turbo/z-image-turbo-regular_00002_.jpg) | ![Z-Image-Turbo, prompt 2, with RealGen-V2](examples/turbo/z-image-turbo-realgen_00002_.jpg) |
45
+ | ![Z-Image-Turbo, prompt 3, no LoRA](examples/turbo/z-image-turbo-regular_00003_.jpg) | ![Z-Image-Turbo, prompt 3, with RealGen-V2](examples/turbo/z-image-turbo-realgen_00003_.jpg) |
46
+ | ![Z-Image-Turbo, prompt 4, no LoRA](examples/turbo/z-image-turbo-regular_00004_.jpg) | ![Z-Image-Turbo, prompt 4, with RealGen-V2](examples/turbo/z-image-turbo-realgen_00004_.jpg) |
47
+ | ![Z-Image-Turbo, prompt 5, no LoRA](examples/turbo/z-image-turbo-regular_00005_.jpg) | ![Z-Image-Turbo, prompt 5, with RealGen-V2](examples/turbo/z-image-turbo-realgen_00005_.jpg) |
48
+
49
+ Note: on Turbo the LoRA still affects the image even though negative prompts
50
+ don't — CFG=1 disables the negative branch, not the LoRA patch.
51
+
52
+ ## Why this repo exists
53
+
54
+ The upstream release ships the adapter in [PEFT](https://github.com/huggingface/peft)
55
+ format (`base_model.model.<path>.lora_A.<adapter>.weight` keys, with
56
+ `lora_alpha` living separately in `adapter_config.json`). ComfyUI's stock
57
+ `LoraLoader` doesn't understand that layout, so this repo provides:
58
+
59
+ - the **same weights, repackaged** with diffusers-style keys
60
+ (`<path>.lora_down.weight`, `<path>.lora_up.weight`) and
61
+ - per-module `alpha` tensors baked into the file so the `alpha/rank` scaling
62
+ ComfyUI applies matches what PEFT would have applied at runtime.
63
+
64
+ No retraining, no quantisation, no surgery beyond key renaming and alpha
65
+ injection — the math is identical to running the original adapter through PEFT.
66
+
67
+ ## Files
68
+
69
+ | File | Purpose |
70
+ | --- | --- |
71
+ | `realgen_v2.safetensors` | The repackaged LoRA. Drop into `ComfyUI/models/loras/`. |
72
+ | `scripts/convert_realgen_v2.py` | The script used to produce it from the upstream PEFT adapter. Re-runnable for transparency. |
73
+ | `examples/` | Side-by-side renders, with and without the LoRA, on both Z-Image base and Z-Image-Turbo. |
74
+ | `LICENSE` | Apache 2.0 (matches both RealGen-V2 and Z-Image upstream). |
75
+
76
+ ## Usage in ComfyUI
77
+
78
+ 1. Download `realgen_v2.safetensors` and place it in `ComfyUI/models/loras/`.
79
+ 2. Build a graph: `Load Diffusion Model` (Z-Image) → `LoraLoader` → sampler.
80
+ - Select `realgen_v2.safetensors` in the loader.
81
+ - **Strength `1.0`** reproduces the upstream training intent
82
+ (`alpha=128, rank=64 → scale=2.0`).
83
+ - Lower (e.g. `0.5–0.8`) for a softer effect; the LoRA scales linearly.
84
+
85
+ That's it — there is no custom node to install.
86
+
87
+ ## Reproducing the conversion
88
+
89
+ If you'd rather convert the upstream weights yourself:
90
+
91
+ ```bash
92
+ # from a Python env with torch + safetensors + packaging:
93
+ python scripts/convert_realgen_v2.py adapter_model.safetensors realgen_v2.safetensors
94
+ ```
95
+
96
+ The script reads `lora_alpha` from `adapter_config.json` (sitting next to the
97
+ adapter), strips the `base_model.model.` prefix, rewrites
98
+ `lora_A`/`lora_B` → `lora_down`/`lora_up`, and writes one `<module>.alpha`
99
+ tensor per LoRA module. See the source for the full mapping.
100
+
101
+ ## Credits
102
+
103
+ - Original RealGen-V2 weights: [Yunncheng/RealGen-V2](https://huggingface.co/Yunncheng/RealGen-V2)
104
+ - RealGen training code: [yejy53/RealGen](https://github.com/yejy53/RealGen) (`RealGen_v2/`)
105
+ - Base models: [Tongyi-MAI/Z-Image](https://huggingface.co/Tongyi-MAI/Z-Image) and [Tongyi-MAI/Z-Image-Turbo](https://huggingface.co/Tongyi-MAI/Z-Image-Turbo)
106
+
107
+ This repo redistributes the weights under their original Apache 2.0 license;
108
+ all credit for the LoRA itself belongs to the upstream authors.
examples/base/z-image-realgen_00001_.jpg ADDED

Git LFS Details

  • SHA256: 9b03e7e1a648fbc1e858cb9b7382caf6f64b16ef204f223c4c63bc156edd99da
  • Pointer size: 131 Bytes
  • Size of remote file: 154 kB
examples/base/z-image-realgen_00002_.jpg ADDED

Git LFS Details

  • SHA256: e99fd7ebf9c6e1fd8e286870714eef591bb3ace1e59409e8a7d836e89137c63e
  • Pointer size: 131 Bytes
  • Size of remote file: 222 kB
examples/base/z-image-realgen_00003_.jpg ADDED

Git LFS Details

  • SHA256: 17e7ece7dba9cd5ab592268d48eba6b721ceafcb1899d8b5f5984db4d8caf403
  • Pointer size: 131 Bytes
  • Size of remote file: 330 kB
examples/base/z-image-realgen_00004_.jpg ADDED

Git LFS Details

  • SHA256: 064cc43ec89d8ba828a02e0a62e1bbd5737095fb028a547330ed5f8f42af4d27
  • Pointer size: 131 Bytes
  • Size of remote file: 345 kB
examples/base/z-image-realgen_00005_.jpg ADDED

Git LFS Details

  • SHA256: 8784b230e826c27d6164c3764f88f6bf6b5feb7e34c92b9d6455f909a200dc36
  • Pointer size: 131 Bytes
  • Size of remote file: 263 kB
examples/base/z-image-regular_00001_.jpg ADDED

Git LFS Details

  • SHA256: b2a9ebe5707a5daef7d1c143043e48435106d926915a26a896b927a65b93d942
  • Pointer size: 131 Bytes
  • Size of remote file: 143 kB
examples/base/z-image-regular_00002_.jpg ADDED

Git LFS Details

  • SHA256: 80c0e598e070da43036340214001556380542731c128e9dc66a7b439d11693ed
  • Pointer size: 131 Bytes
  • Size of remote file: 284 kB
examples/base/z-image-regular_00003_.jpg ADDED

Git LFS Details

  • SHA256: 18a4a36745b3baffa16dda41a6aa788fde74cbbfd29a9c3e3f572a73bd1a3f3b
  • Pointer size: 131 Bytes
  • Size of remote file: 214 kB
examples/base/z-image-regular_00004_.jpg ADDED

Git LFS Details

  • SHA256: caf36e42f51ffa4fd03e48f868a6fa97d43878db8d7d4ae5ea8c923674e78ef8
  • Pointer size: 131 Bytes
  • Size of remote file: 254 kB
examples/base/z-image-regular_00005_.jpg ADDED

Git LFS Details

  • SHA256: 70d74b12f20e8eb8cb14006be23c82427244163ed48b21dc2c42ab57961b9a1d
  • Pointer size: 131 Bytes
  • Size of remote file: 167 kB
examples/turbo/z-image-turbo-realgen_00001_.jpg ADDED

Git LFS Details

  • SHA256: d85198841aa097509b4af1e2ce35acc2265302576d33b7997734651844d38edf
  • Pointer size: 131 Bytes
  • Size of remote file: 169 kB
examples/turbo/z-image-turbo-realgen_00002_.jpg ADDED

Git LFS Details

  • SHA256: c53ee8a48676b1eadacf796a111e5a2c0f79364be45e6fe6c31ede817f77f217
  • Pointer size: 131 Bytes
  • Size of remote file: 232 kB
examples/turbo/z-image-turbo-realgen_00003_.jpg ADDED

Git LFS Details

  • SHA256: 0b1c83c60d9f2c83aab5c709a01ceceeb36a1fccd885e5ffe5d2eac8494f1b86
  • Pointer size: 131 Bytes
  • Size of remote file: 259 kB
examples/turbo/z-image-turbo-realgen_00004_.jpg ADDED

Git LFS Details

  • SHA256: 99d02ec2a9f043642b965d7f2e24b3a9a7219dd0fe4e5a2546df75fc03c3d416
  • Pointer size: 131 Bytes
  • Size of remote file: 184 kB
examples/turbo/z-image-turbo-realgen_00005_.jpg ADDED

Git LFS Details

  • SHA256: 1c0e42c3e7f03b7989e69faeca0714c6f0bb38b33f3f849ed0a71a65ff698b93
  • Pointer size: 131 Bytes
  • Size of remote file: 150 kB
examples/turbo/z-image-turbo-regular_00001_.jpg ADDED

Git LFS Details

  • SHA256: 75b30898529cc954c61363819eb44d44694aa38af555122b0a44218d59b7b6ee
  • Pointer size: 131 Bytes
  • Size of remote file: 154 kB
examples/turbo/z-image-turbo-regular_00002_.jpg ADDED

Git LFS Details

  • SHA256: c0759e9f0ef3e90430eef953173c3c133293f18c08d134e3c9c48003da0c83ea
  • Pointer size: 131 Bytes
  • Size of remote file: 197 kB
examples/turbo/z-image-turbo-regular_00003_.jpg ADDED

Git LFS Details

  • SHA256: c857fed0b48b7d236a830cfcf4120e874dd742f3cb289e92f0b1f1650e655547
  • Pointer size: 131 Bytes
  • Size of remote file: 234 kB
examples/turbo/z-image-turbo-regular_00004_.jpg ADDED

Git LFS Details

  • SHA256: a5c738b342b6c8e72a95a484290b979cdd6981159dcd77726feb4bc93895bacb
  • Pointer size: 131 Bytes
  • Size of remote file: 156 kB
examples/turbo/z-image-turbo-regular_00005_.jpg ADDED

Git LFS Details

  • SHA256: 5c5953c022c92c5e3019b7e1576681cfa04477e8a9181896e2cfc759c541ab17
  • Pointer size: 131 Bytes
  • Size of remote file: 125 kB
realgen_v2.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c50a3437f85592512f92a2f956d699c6fc524e2b05cc77a05dc47a3057133973
3
+ size 317598656
scripts/convert_realgen_v2.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Convert the RealGen-V2 PEFT LoRA adapter into a ComfyUI-compatible LoRA.
3
+
4
+ Input: adapter_model.safetensors (+ adapter_config.json in the same folder,
5
+ used to read `lora_alpha` so ComfyUI scales the LoRA correctly)
6
+ Output: a single safetensors file with diffusers-style keys
7
+ (`<path>.lora_down.weight`, `<path>.lora_up.weight`, `<path>.alpha`).
8
+
9
+ Drop the output file into `ComfyUI/models/loras/` and load it with the stock
10
+ `LoraLoader` against a Z-Image model.
11
+
12
+ Usage:
13
+ python convert_realgen_v2.py adapter_model.safetensors realgen_v2.safetensors
14
+ python convert_realgen_v2.py adapter_model.safetensors # auto-names
15
+ python convert_realgen_v2.py # cwd defaults
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import argparse
21
+ import json
22
+ import sys
23
+ from pathlib import Path
24
+
25
+ import torch
26
+ import safetensors.torch as st
27
+
28
+
29
+ PEFT_PREFIX = "base_model.model."
30
+ SUFFIX_MAP = (("lora_A", "lora_down"), ("lora_B", "lora_up"))
31
+
32
+
33
+ def convert(src: Path, dst: Path, alpha_override: float | None = None) -> None:
34
+ if not src.is_file():
35
+ sys.exit(f"error: source not found: {src}")
36
+
37
+ # Pull lora_alpha from adapter_config.json if present, else fall back.
38
+ lora_alpha: float
39
+ if alpha_override is not None:
40
+ lora_alpha = float(alpha_override)
41
+ print(f"using alpha override: {lora_alpha}")
42
+ else:
43
+ cfg_path = src.parent / "adapter_config.json"
44
+ if cfg_path.is_file():
45
+ with cfg_path.open() as f:
46
+ cfg = json.load(f)
47
+ lora_alpha = float(cfg.get("lora_alpha", 1.0))
48
+ print(f"read lora_alpha={lora_alpha} from {cfg_path.name}")
49
+ else:
50
+ lora_alpha = 128.0 # documented default for RealGen-V2
51
+ print(
52
+ f"warning: no adapter_config.json next to {src.name}; "
53
+ f"falling back to lora_alpha={lora_alpha}"
54
+ )
55
+
56
+ sd = st.load_file(str(src))
57
+ out: dict[str, torch.Tensor] = {}
58
+ modules: set[str] = set()
59
+ skipped: list[str] = []
60
+
61
+ for k, v in sd.items():
62
+ nk = k
63
+ if nk.startswith(PEFT_PREFIX):
64
+ nk = nk[len(PEFT_PREFIX):]
65
+
66
+ rewritten = False
67
+ for peft_part, comfy_part in SUFFIX_MAP:
68
+ tag = f".{peft_part}."
69
+ if tag in nk and nk.endswith(".weight"):
70
+ head, _ = nk.split(tag, 1)
71
+ nk = f"{head}.{comfy_part}.weight"
72
+ modules.add(head)
73
+ rewritten = True
74
+ break
75
+
76
+ if not rewritten and not nk.endswith(".alpha"):
77
+ skipped.append(k)
78
+ continue
79
+
80
+ out[nk] = v.contiguous()
81
+
82
+ if not modules:
83
+ sys.exit(
84
+ "error: no LoRA tensors detected. "
85
+ "Is this actually a PEFT adapter_model.safetensors?"
86
+ )
87
+
88
+ # Inject per-module alpha tensors if the source didn't ship them.
89
+ alpha_tensor = torch.tensor(lora_alpha, dtype=torch.float32)
90
+ for m in modules:
91
+ out.setdefault(f"{m}.alpha", alpha_tensor.clone())
92
+
93
+ dst.parent.mkdir(parents=True, exist_ok=True)
94
+ st.save_file(out, str(dst))
95
+
96
+ print(f"wrote {dst}")
97
+ print(f" tensors: {len(out)} (modules: {len(modules)})")
98
+ if skipped:
99
+ print(f" skipped {len(skipped)} unrecognized keys, e.g. {skipped[:3]}")
100
+
101
+
102
+ def main() -> None:
103
+ ap = argparse.ArgumentParser(description=__doc__.splitlines()[1])
104
+ ap.add_argument(
105
+ "src",
106
+ nargs="?",
107
+ default="adapter_model.safetensors",
108
+ type=Path,
109
+ help="Input PEFT adapter (default: ./adapter_model.safetensors)",
110
+ )
111
+ ap.add_argument(
112
+ "dst",
113
+ nargs="?",
114
+ default=None,
115
+ type=Path,
116
+ help="Output filename (default: <src stem>_comfy.safetensors)",
117
+ )
118
+ ap.add_argument(
119
+ "--alpha",
120
+ type=float,
121
+ default=None,
122
+ help="Override lora_alpha instead of reading adapter_config.json.",
123
+ )
124
+ args = ap.parse_args()
125
+
126
+ src: Path = args.src
127
+ dst: Path = args.dst or src.with_name(f"{src.stem}_comfy.safetensors")
128
+ convert(src, dst, alpha_override=args.alpha)
129
+
130
+
131
+ if __name__ == "__main__":
132
+ main()