File size: 4,446 Bytes
5b4396b
cd53da3
 
5b4396b
cd53da3
 
 
 
 
 
 
bec4729
 
b30344d
 
 
 
 
aef434e
5b4396b
 
aef434e
cd53da3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482a704
 
cd53da3
 
 
482a704
cd53da3
 
fb726e9
cd53da3
 
fb726e9
cd53da3
 
fb726e9
cd53da3
482a704
fb726e9
482a704
cd53da3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bec4729
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
---
language:
- en
library_name: diffusers
license: other
license_name: flux-1-dev-non-commercial-license
license_link: LICENSE.md
base_model:
- black-forest-labs/FLUX.1-dev
- black-forest-labs/FLUX.1-schnell
base_model_relation: merge
tags:
- flux
- fluxpipeline
- turbo
- lightning
- diffusers
pipeline_tag: text-to-image
new_version: LPX55/FLUX.1-merged_lightning_v2
---

# FLUX-merged_lightning-v1
This repository provides the merged params for [`black-forest-labs/FLUX.1-dev`](https://huggingface.co/black-forest-labs/FLUX.1-dev)
and [`black-forest-labs/FLUX.1-schnell`](https://huggingface.co/black-forest-labs/FLUX.1-schnell) originally provided by [@sayakpaul](https://huggingface.co/sayakpaul/FLUX.1-merged). 

The base model was then fused with a selection of LoRAs, *some of which are NSFW in nature*. Please use responsibily. Please be aware of the licenses of both the models before using the params commercially. 

This model was created as part of the ongoing [OpenSight project](https://huggingface.co/spaces/aiwithoutborders-xyz/OpenSight-Deepfake-Detection-Models-Playground), mostly for dataset generation and evaluation purposes. 


## The following context provided by sayakpaul, of the original merged model.

<table>
    <thead>
        <tr>
            <th>Dev (50 steps)</th>
            <th>Dev (4 steps)</th>
            <th>Dev + Schnell Merge (4 steps)</th>
            <th>This Model (6-8 steps recommended)</th>
        </tr>
    </thead>
    <tbody>
      <tr>Prompt: `An Instagram profile picture of an Asian model taken at a rooftop penthouse pool party.`</tr>
        <tr>
            <td>
              <img src="https://cdn-uploads.huggingface.co/production/uploads/639daf827270667011153fbc/pLdbs5kVH3jCKkKeAV8P_.jpeg" width="150px" height="150px">
            </td>
            <td>
              <img src="https://cdn-uploads.huggingface.co/production/uploads/639daf827270667011153fbc/5u4ME3kBSNGLmYyGIcyFW.jpeg" width="150px" height="150px">
            </td>
            <td>
              <img src="https://cdn-uploads.huggingface.co/production/uploads/639daf827270667011153fbc/b5JQCzbE2hzKZS-C1xra5.jpeg" width="150px" height="150px">
            </td>
          <td>
            <img src="https://cdn-uploads.huggingface.co/production/uploads/639daf827270667011153fbc/rnqvOgQH7IjReKjWmms00.jpeg" width="150px" height="150px">
          </td>
        </tr>
    </tbody>
</table>

## Sub-memory-efficient merging code

```python
from diffusers import FluxTransformer2DModel
from huggingface_hub import snapshot_download
from accelerate import init_empty_weights
from diffusers.models.model_loading_utils import load_model_dict_into_meta
import safetensors.torch
import glob
import torch


with init_empty_weights():
    config = FluxTransformer2DModel.load_config("black-forest-labs/FLUX.1-dev", subfolder="transformer")
    model = FluxTransformer2DModel.from_config(config)

dev_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-dev", allow_patterns="transformer/*")
schnell_ckpt = snapshot_download(repo_id="black-forest-labs/FLUX.1-schnell", allow_patterns="transformer/*")

dev_shards = sorted(glob.glob(f"{dev_ckpt}/transformer/*.safetensors"))
schnell_shards = sorted(glob.glob(f"{schnell_ckpt}/transformer/*.safetensors"))

merged_state_dict = {}
guidance_state_dict = {}

for i in range(len((dev_shards))):
    state_dict_dev_temp = safetensors.torch.load_file(dev_shards[i])
    state_dict_schnell_temp = safetensors.torch.load_file(schnell_shards[i])

    keys = list(state_dict_dev_temp.keys())
    for k in keys:
        if "guidance" not in k:
            merged_state_dict[k] = (state_dict_dev_temp.pop(k) + state_dict_schnell_temp.pop(k)) / 2
        else:
            guidance_state_dict[k] = state_dict_dev_temp.pop(k)

    if len(state_dict_dev_temp) > 0:
        raise ValueError(f"There should not be any residue but got: {list(state_dict_dev_temp.keys())}.")
    if len(state_dict_schnell_temp) > 0:
        raise ValueError(f"There should not be any residue but got: {list(state_dict_dev_temp.keys())}.")

merged_state_dict.update(guidance_state_dict)
load_model_dict_into_meta(model, merged_state_dict)

model.to(torch.bfloat16).save_pretrained("merged-flux")
```

---

Changelog:

* 7 April 2025 - Just noticed a potential mistake when loading some components (particularly the text_encoder2), feel free to load from the base dev folder, works the same as it is a merge.