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brief summary of both models below. Image results are at the end of the post if you're not interested in - or are already familiar with - the idea behind Proteus & DPO.
|
4 |
+
|
5 |
+
## Preface
|
6 |
+
|
7 |
+
This model came about just as I started looking into the science behind merging models - starting with block-weighted merging, and how the different methods influence generation results. Because I'm still new to the concept, my process thus far was far from structured or scientific. I'm in no way a seasoned expert in the training and merging of models, knowing just enough to achieve stable merges, combined with a healthy amount and make some logical adjustments and judgements.
|
8 |
+
|
9 |
+
I say this, because - while I found a merge that I'm happy enough with to share - better variaations probably exist.
|
10 |
+
|
11 |
+
The models are licensed under [openrail++ (DPO)](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/LICENSE.md) and [GPL3 (Proteus)](https://choosealicense.com/licenses/gpl-3.0/), both allowing for free use and redistribution within the original model use-case. The merge is published under GPL3.
|
12 |
+
|
13 |
+
The two variants of this model, and the original base models (converted to transformers-base for use with stable diffusion, etc) can be found in the HuggingFace Repository.
|
14 |
+
|
15 |
+
## The Goal
|
16 |
+
|
17 |
+
When I started - artistic curiosity.
|
18 |
+
|
19 |
+
What it turned into - creating a model that has a good balance of artistic freedom while staying true to the original prompt.
|
20 |
+
|
21 |
+
The balance of accuracy and creativity when working with diffusion AI models is something we've all gotten used to - sacrficing some accuracy to add a bit more pop, and vice versa. This model aims to narrow that window - using Proteus to broaden
|
22 |
+
|
23 |
+
## The Models
|
24 |
+
|
25 |
+
### [mhdang/dpo-sdxl-text2image-v1](https://huggingface.co/mhdang/dpo-sd1.5-text2image-v1) | [mhdang/dpo-sd1.5-text2image-v1](https://huggingface.co/mhdang/dpo-sd1.5-text2image-v1)
|
26 |
+
|
27 |
+
Note: DPO's influence is way more apparent in SDXL models. This project had me focused on the SDXL version - there is probably room for exploration in merging some of the stronger 1.5 models with DPO.
|
28 |
+
|
29 |
+
Fine-tuned from [stable-diffusion-xl-base-1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and [stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) respectively, using offline human preference data [pickapic_v2](https://huggingface.co/datasets/yuvalkirstain/pickapic_v2).
|
30 |
+
|
31 |
+
#### What makes DPO interesting?
|
32 |
+
|
33 |
+
Direct Preference Optimization proposes fine-tuning models through directly optimizing on human comparison data, in stead of the widely used RLHF (Reinforcement Learning from Human Feedback) approach.
|
34 |
+
|
35 |
+
The claims to significantly improve visual appeal and prompt alignment, and - keeping in mind subjectivity - for the most part, general concensus agrees with this claim.
|
36 |
+
|
37 |
+
[*Research Paper on DPO*](https://arxiv.org/abs/2311.12908)
|
38 |
+
|
39 |
+
### [dataautogpt3/Proteus-RunDiffusion](https://huggingface.co/dataautogpt3/Proteus-RunDiffusion)
|
40 |
+
|
41 |
+
While investigating ways in which image generation can be improved within existing frameworks, the team at RunDiffusion stumbled upon a new approach in retraining CLIP - claiming to have unlocked and broadened their model's potential for character recognition, natural language processing and, most notably, its versatility in artistic expression.
|
42 |
+
|
43 |
+
#### What makes Proteus interesting?
|
44 |
+
|
45 |
+
**Extract from their model card:**
|
46 |
+
|
47 |
+
>When you start using Proteus-RunDiffusion, be ready for it to behave differently from other AI art models you've used. It's been designed in a unique way, which means it will respond to your prompts and commands in its own style. This difference is part of what makes it special, but it also means there's a learning curve. You'll need some time to get familiar with how it works and what it can do. So, as you begin, keep an open mind and be prepared to adjust your approach.
|
48 |
+
|
49 |
+
This paragraph told me that a merging would either be chaos, or it could at the very least output some interesting results -a welcome variance from the nuances we've gotten used to by now.
|
50 |
+
|
51 |
+
## The Merging
|
52 |
+
|
53 |
+
I happened across the two models only a few days apart - both piquing my interest in their own way - and as I was in the middle of my exploration in merging methods, I naturally wondered what a merging of these two ideas would look like - and I was pleasantly surprised by the results (comparison at the end of the post).
|
54 |
+
|
55 |
+
Unfortunately I didn't think to document the entire process, and only had all the information on my final contenders when I decided I want to share the model.
|
56 |
+
|
57 |
+
### The Challenge
|
58 |
+
|
59 |
+
The biggest challenge was finding a merge that could even be considered close to what I wanted to acihieve. Most merging attempts would result in a model outputting wildly different or inaccurate images, or there would be little to no change from the base model,
|
60 |
+
|
61 |
+
The fact that the two model's focus was so far seperated it could almost be considered oppopsites, actually worked in my favor - with my only real challenge was finding a alpha-base and block-weighting strategy that checks all the right boxes on each side.
|
62 |
+
|
63 |
+
### My Approach
|
64 |
+
|
65 |
+
I decided to use Proteus as a base, retaining its CLIP and VAE. I started with a 1-to-1 conversion from the original Proteus UNET model, uncluding their original clip models, tokenizers and VAE, to a transformers-based model - doing the same with the DPO models. I then brute-force tested my way through 16 block-weighted merging strategies (list at the end of this section), running prompts and comparing the results to the original model's output. I did a base_alpha 0.4, 0.5 and 0.6 merges of each, landing on 0.4 as my preferred base weighting.
|
66 |
+
|
67 |
+
Keeping in mind the subjective nature of art, I tried to keep the judgment of each resulting image as objective as possible by looking only at the below:
|
68 |
+
|
69 |
+
- Prompt Accuracy
|
70 |
+
- How much of the original prompt was adhered to?
|
71 |
+
- The amount of artistic liberties taken
|
72 |
+
- How much these liberties strayed from the prompt.
|
73 |
+
|
74 |
+
- Resemblence to the output of the base model (Proteus)
|
75 |
+
- Deciding to use Proteus as a base I, in theory, was attempting to add structure to a broad creative scope
|
76 |
+
- It was therefore important for me that a good balance was struck between the artistry and the accuracy of the final result
|
77 |
+
|
78 |
+
Most of the merging results either strayed way too far from the base image, disqualifying it based on my goal; or the resemblance was too far off from the original for my liking. It's worth noting that while I kept my metrics as objective as possible, subjective measurements/judgements are unavoidable - the acceptable travel distance from the base image being one of them.
|
79 |
+
|
80 |
+
I was left with two models that produced fairly similar results, but had slight, noticeable output variance on the creativity-accuracy scale - the ReverseSmoothstep and TrueReverseCubicHermite merging variants. I couldn't decide between the final two, because they both achieved my goal, either with a bit of artistic flair, or an impressive accuracy...like two sides to the same coin. The margin and variance is small enough that the final judgement would vary given your preference on a per-image basis.
|
81 |
+
|
82 |
+
So I decided to share both.
|
83 |
+
|
84 |
+
***Merging Strategies used:*** GradV ,GradA ,Flat_25 ,Wrap2 ,Mid2_50 ,Out07 ,Ring08Soft ,Ring08_5 ,Smoothstep ,ReverseSmoothstep ,Cosine ,ReverseCosine ,TrueCubicHermite ,TrueReverseCubicHermite ,FakeCubicHermite ,FakeReverseCubicHermite
|
85 |
+
|
86 |
+
## Testing Parameters and Result Interpretation
|
87 |
+
|
88 |
+
As previously mentioned, I mostly cowboy'd the process before I considered sharing the models. Below are the some comparison images between each variant. Both models show a healthy deviation from the base model, while staying within the contraints of the prompt.
|
89 |
+
|
90 |
+
The ReverseSmoothStep variant seems to add a bit more artistic flair while remaining close enough to what was asked, giving it the edge in artistic variance and possible outcomes while still checking the majority of boxes in the prompt..
|
91 |
+
|
92 |
+
The TrueReverseCubicHermite variant walks very closely to the ReverseSmoothStep model, but seems to add more detail that anchor it back to the prompt.
|
93 |
+
|
94 |
+
**My take on the variants:**
|
95 |
+
|
96 |
+
If you're a seasoned prompt engineer, and/or know exactly what you want in an image, give [Proteus-RunDiffusion-DPO_TrueReverseCubicHermite](https://huggingface.co/PikkieWyn/Proteus-RunDiffusion-DPO_Merge/blob/main/Proteus-RunDiffusion-DPO_TrueReverseCubicHermite.safetensors) a go. Throughout all my testing for the merge, and in subsequent tests, I've definitely noticed some unique interpretations, ranging from interesting to aweosme.
|
97 |
+
|
98 |
+
If you prefer being more loose with how the prompt will be interpreted, or you want the AI to do a bit more heavy lifting in detailing and style choice, [Proteus-RunDiffusion-DPO_ReverseSmoothstep](https://huggingface.co/PikkieWyn/Proteus-RunDiffusion-DPO_Merge/blob/main/Proteus-RunDiffusion-DPO_ReverseSmoothstep.safetensors) ticks many of the same boxes, While it's fairly stable and consistent, it does make more decisions that are purely artistic, which increases the risk of small errors or inconsistencies. In the same breathe, this did often result in the preferable output given my personal expectation for the prompt.
|
99 |
+
|
100 |
+
I tested multiple sampler/scheduler/CFG/Step combinations before deciding a foundation for the tests. This was another subjective choice, and I'm sure other parameters could have very different - and probably even better - outcomes. These were sufficient for testing my goal though:
|
101 |
+
|
102 |
+
>Tests were run in ComfyUI with the model's CLIP and VAE, no Loras and with no pre/post-processing. Worth noting is that DataPulse recommends a CLIP skip of -2. I did not make any modification to the CLIP skip layer during my merge variant testing. My only adjustment was setting the CLIP scaling to 4 to improve the final quality and clarity of the images. The workdlow was kept as simple as possible, running only base sampling in a single KSampler node. Any errors or small issues were left as is for consisency.
|
103 |
+
|
104 |
+
The workflow is available in the [Huggingface repository](https://huggingface.co/PikkieWyn/Proteus-RunDiffusion-DPO_Merge/tree/main/comparisons). The comparison images are also the original, unaltered output images, and have their workflows embedded. They're all the same, of course, the only variable being the model used and the prompt text for each test. If you plan on loading the workflow, Use Everywhere (UE Nodes) was used to neaten the flow (CLIP weight and seed distribution), and OneButtonPrompt's preset node was used to generate some random base prompts - so you'll either need to install these or make the necessary tweaks to bypass them.
|
105 |
+
|
106 |
+
**Universal Sampling Parameters:**
|
107 |
+
|
108 |
+
Resolution: 1344x768
|
109 |
+
|
110 |
+
Steps: 45
|
111 |
+
|
112 |
+
CFG: 4
|
113 |
+
|
114 |
+
Sampler: dpmpp_3m_sde_gpu
|
115 |
+
|
116 |
+
Scheduler: exponential
|
117 |
+
|
118 |
+
Denoise: 1
|
119 |
+
|
120 |
+
CLIP Scaling: 4
|
121 |
+
|
122 |
+
Negative Prompt: text, watermark, logo, blurry, out of focus
|
123 |
+
|
124 |
+
These parameters gave me the best results - according to my preference, but also for the sake of comparison. They do lean a bit more to the tame side of things to keep random variance down, so I'd recommend experimenting and pushing the boundaries of these parameters if you decide to play around with these models yoruself. I've gotten some good results with CFG set to 1.5, and making use of the Dynamic Thresholding extension (available for both Stable Diffusion and ComfyUI) to boost some of the CFG effects significantly.
|
125 |
+
|
126 |
+
If you're not familiar with the extension and would like to try it out, it can produce some amazing results on its own. Below is a relatively safe setup for fairly consistent results:
|
127 |
+
|
128 |
+
>- Set your CFG to a very low value, I usually stick with 1.5 as 1 tends turn to chaos very easily, especially at such high CFG levels
|
129 |
+
>- Set the "mimic scale" to 30 and "threshold percentile" to 0.9 (if you lower the CFG to a range of 18-26 0.95 works well)
|
130 |
+
>- Set both mimic modes to "Half Cosine Up", both scale minimum values to 4 and the scheduler value to 4
|
131 |
+
>
|
132 |
+
>The rest of your inputs and processing steps can be used as per usual. I've only hit walls with some Loras that can't handle the extremes, resulting in either a jumbled mess or pure black/blue/grey outputs. So if you experience this, look at removing loras before lowering your mimic level, etc.
|
133 |
+
|
134 |
+
I'll give two brief (subjective) comments the 1st and 4th comparisons as they tie in with earlier statemetns, the rest I'll leave to individual interpretation(as it should be).
|
135 |
+
|
136 |
+
**1. Robotic Chicken** is an example where I prefer the 'TrueReverseCubicHermite' variant. While both models moved away from the half real chicken the base model opted for, 'TrueReverseCubicHermite' added subtle details to the head that hinted more at it being a chicken. Both have too little chicken for my taste, and have more simple backgrounds, and I prefer the base model above both variants in this case. Outside of testing, I would tweak the parameters to find that balance more closely, but it does a good enough job at showing the nuance between the variants.
|
137 |
+
|
138 |
+
**4. Japanese Cherry Blossom** is a result where I prefer the 'ReverseSmoothStep' variant above 'TrueReverseCubicHermite'. The addition of the house with Japanese-inspired architecture is a welcomed addition for me - adding more depth to the story told and giving life to a prompt at risk of being lifeless, proven by the 'TrueReverseCubicHermite' variant's more accurate-to-the-prompt interpretation. A good example where a bit more artistic freedom can add to the image without moving outside of the prompt boundaries.
|
139 |
+
|
140 |
+
### 1. Robotic Chicken - Seed 40212733440049
|
141 |
+
|
142 |
+
**Prompt:**
|
143 |
+
|
144 |
+
sci-fi, art by Iris van Herpen, digital art, Rule of Thirds, robotic (Chicken:1.1) , the Chicken is wearing a Iron and Velvet Jacquard cybernetics that was designed by Apple computers, It is Hyperdetailed, Avant-garde, futuristic, 3D printing, science fiction, fashionable
|
145 |
+
|
146 |
+
**Cropped Comparison:**
|
147 |
+
|
148 |
+
![robotchicken_cropped](./comparisons/01-RoboticChicken-Cropped.png)
|
149 |
+
|
150 |
+
**Full images:**
|
151 |
+
|
152 |
+
ProteusBase
|
153 |
+
![robotchicken_cropped](./comparisons/01-RoboticChicken-ProteusBase.png)
|
154 |
+
ReverseSmoothStep
|
155 |
+
![robotchicken_smooth](./comparisons/01-RoboticChicken-RevSmoothStep.png)
|
156 |
+
TrueReverseCubicHermite
|
157 |
+
![robotchicken_cubichermite](./comparisons/01-RoboticChicken-TrueReverseCubicHermite.png)
|
158 |
+
|
159 |
+
### 2. Cyberpunk Cyborg Female - Seed 754467864831453
|
160 |
+
|
161 |
+
**Prompt:**
|
162 |
+
|
163 |
+
cyberpunk, concept art, cyborg Female Troll, background is night city, neon-lit, vogue pose, her hair is Silver, futuristic, womanly, D&D, neon hue, shadowrun
|
164 |
+
|
165 |
+
**Images:**
|
166 |
+
|
167 |
+
ProteusBase
|
168 |
+
![cyberfemale_base](./comparisons/02-Cyberpunk_CyborgFemale-ProteusBase.png)
|
169 |
+
ReverseSmoothStep
|
170 |
+
![cyberfemale_smooth](/comparisons/02-Cyberpunk_CyborgFemale-RevSmoothStep.png)
|
171 |
+
TrueReverseCubicHermite
|
172 |
+
![cyberfemale_cubichermite](./comparisons/02-Cyberpunk_CyborgFemale-TrueReverseCubicHermite.png)
|
173 |
+
|
174 |
+
### 3. Fashion Photgraph - Seed 321237786
|
175 |
+
|
176 |
+
**Prompt:**
|
177 |
+
|
178 |
+
Fashion photography of a supermodel, laughing, she is wearing a fashion outfit, her fashion outfit is Smart, It has Anthemion patterns on it, Tattoos, Fomapan 400, Depth of field 270mm, photorealism
|
179 |
+
|
180 |
+
**Images:**
|
181 |
+
|
182 |
+
ProteusBase
|
183 |
+
![fashionphoto_base](./comparisons/03-FashionPhoto-ProteusBase.png)
|
184 |
+
ReverseSmoothStep
|
185 |
+
![fashionphoto_smooth](./comparisons/03-FashionPhoto-RevSmoothStep.png)
|
186 |
+
TrueReverseCubicHermite
|
187 |
+
![fashionphoto_cubichermite](./comparisons/03-FashionPhoto-TrueReverseCubicHermite.png)
|
188 |
+
|
189 |
+
### 4. Japanese Cherry Blossom - Seed 123 *(not a typo)*
|
190 |
+
|
191 |
+
**Prompt:**
|
192 |
+
|
193 |
+
(nature art by Yuko Tatsushima:1.0) , wabi-sabi (Cherry blossom tree:1.1) , trees, deep focus, Japanese watercolor painting, traditional motives
|
194 |
+
|
195 |
+
**Images:**
|
196 |
+
|
197 |
+
ProteusBase
|
198 |
+
![cherryblossom_base](./comparisons/04-JapaneseCherryBlossom-ProteusBase.png)
|
199 |
+
ReverseSmoothStep
|
200 |
+
![cherryblossom_smooth](./comparisons/04-JapaneseCherryBlossom-RevSmoothStep.png)
|
201 |
+
TrueReverseCubicHermite
|
202 |
+
![cherryblossom_base](./comparisons/04-JapaneseCherryBlossom-TrueReverseCubicHermite.png)
|
203 |
+
|
204 |
+
## Final Word
|
205 |
+
|
206 |
+
Impatience and limitations in my knowledge on the mathematics and science behind the process almost certainly means I've done some things suboptimally, or incorrectly.
|
207 |
+
|
208 |
+
That said, I'm content with the merges I found, and have been pleasantly surprised by some of the results I've gotten thus far.
|
209 |
+
|
210 |
+
Ultimately, both the base models - and by extension the merged models - are about exploring what is possible, exploring the fringes of an already well established framework.
|
211 |
+
|
212 |
+
If this sounds like something you'd like to explore, I hope these models (and the individual base models) prove valurable to you.
|
213 |
+
|
214 |
+
If you read this post in its entirety - cudos! I probably woulnd't have. A big thanks to everyone in open-source land that makes these things possible for common folk like me.
|
215 |
+
|
216 |
+
## Credits
|
217 |
+
|
218 |
+
- [Alexander Izquierdo](https://huggingface.co/dataautogpt3) and the team at RunDiffusion for their time, effort and investment in developing Proteus.
|
219 |
+
|
220 |
+
- [Meihua Dang](https://rundiffusion.com/), and the folks that worked with him, for their efforts in unfusing DPO into the Stable Diffusion models - making a merge like this one a breeze
|
221 |
+
|
222 |
+
- All the wonderful folks in open-source land who invest so much time and effort into development, training and educating.
|
223 |
+
|
224 |
+
If you have dollars burning holes your pockets and any of these projects are of value to you, show these people some love by saying thanks with those spare bucks.
|
225 |
+
|
226 |
+
I don't drink coffe, so if these models or this post brought you some joy, sharing your creations is more than enough of a thank you.
|
227 |
+
|
228 |
+
*Peace.*
|