Text-to-Image
Diffusers
Safetensors
LibreFluxIPAdapterPipeline
neuralvfx commited on
Commit
d39424d
·
verified ·
1 Parent(s): 7feb367

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +132 -0
README.md ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license:
3
+ - apache-2.0
4
+ library_name: diffusers
5
+ pipeline_tag: text-to-image
6
+ datasets:
7
+ - SA1B
8
+ base_model:
9
+ - jimmycarter/LibreFLUX
10
+ - InstantX/FLUX.1-dev-IP-Adapter
11
+ ---
12
+ # LibreFLUX-IP-Adapter
13
+ ![Example: Control image vs result](examples/matrix_edge.png)
14
+
15
+ This model/pipeline is the product of my LibreFlux IP-Adapter training repo, which uses LibreFLUX as the underlying Transformer model. The Adapter design is roughly based on InstantX, and I was able to actualy fine-tune there weights to work with LibreFlux. For the dataset, I trained on laion2b-squareish-1024px for 20,000 iterations.
16
+
17
+ # How does this relate to LibreFLUX?
18
+ - Base model is [LibreFLUX](https://huggingface.co/jimmycarter/LibreFLUX)
19
+ - Trained in same non-distilled fashion
20
+ - Uses Attention Masking
21
+ - Uses CFG during Inference
22
+
23
+
24
+ # Fun Facts
25
+ - Trained on the [laion2b-squareish-1024px Dataset](https://huggingface.co/datasets/opendiffusionai/laion2b-squareish-1024px/)
26
+ - Trained using this repo: [https://github.com/NeuralVFX/LibreFLUX-IP-Adapter](https://github.com/NeuralVFX/LibreFLUX-IP-Adapter)
27
+ - Transformer model used: [https://huggingface.co/jimmycarter/LibreFlux](https://huggingface.co/jimmycarter/LibreFlux)
28
+ - Inference code roughly adapted from: [https://github.com/bghira/SimpleTuner](https://github.com/bghira/SimpleTuner)
29
+
30
+ # Compatibility
31
+ ```py
32
+ pip install -U diffusers==0.35.2
33
+ pip install -U transformers==4.57.1
34
+ # Compatibility
35
+ ```py
36
+ pip install -U diffusers==0.35.2
37
+ pip install -U transformers==4.57.1
38
+ ```
39
+ Low VRAM:
40
+ ```py
41
+ pip install optimum-quanto
42
+ ```
43
+ # Load Pipeline
44
+ ```py
45
+ import torch
46
+ from diffusers import DiffusionPipeline
47
+
48
+ model_id = "neuralvfx/LibreFlux-IP-Adapter"
49
+ device = "cuda" if torch.cuda.is_available() else "cpu"
50
+
51
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
52
+
53
+ pipe = DiffusionPipeline.from_pretrained(
54
+ model_id,
55
+ custom_pipeline=model_id,
56
+ trust_remote_code=True,
57
+ torch_dtype=dtype,
58
+ safety_checker=None
59
+ )
60
+
61
+ pipe.load_ip_adapter('ip_adapter.pt')
62
+
63
+ pipe.to(device)
64
+ ```
65
+
66
+ # Inference
67
+ ```py
68
+ from PIL import Image
69
+ from torchvision.transforms import ToTensor
70
+
71
+ # Load IP Adapter Image
72
+ ip_image = Image.open("examples/david.png").convert("RGB")
73
+ ip_image = cond.resize((512, 512))
74
+
75
+ prompt = "george washington"
76
+ negative_prompt = "blurry, low quality"
77
+
78
+ generator = torch.Generator(device="cuda").manual_seed(1995)
79
+
80
+ images = pipe(
81
+ prompt=prompt,
82
+ negative_prompt=negative_prompt,
83
+ return_dict=False,
84
+ ip_adapter_image=ip_image,
85
+ ip_adapter_scale=1.0,
86
+ height=512,
87
+ width=512,
88
+ num_inference_steps=75,
89
+ generator=generator
90
+ )
91
+ ```
92
+ # Load Pipeline ( Low VRAM )
93
+ ```py
94
+ import torch
95
+ from diffusers import DiffusionPipeline
96
+ from optimum.quanto import freeze, quantize, qint8
97
+
98
+ model_id = "neuralvfx/LibreFlux-IP-Adapter"
99
+ device = "cuda" if torch.cuda.is_available() else "cpu"
100
+ dtype = torch.bfloat16 if device == "cuda" else torch.float32
101
+
102
+ pipe = DiffusionPipeline.from_pretrained(
103
+ model_id,
104
+ custom_pipeline=model_id,
105
+ trust_remote_code=True,
106
+ torch_dtype=dtype,
107
+ safety_checker=None
108
+ )
109
+ pipe.load_ip_adapter('ip_adapter.pt')
110
+
111
+ quantize(
112
+ pipe.transformer,
113
+ weights=qint8,
114
+ exclude=[
115
+ "*.norm", "*.norm1", "*.norm2", "*.norm2_context",
116
+ "proj_out", "x_embedder", "norm_out", "context_embedder",
117
+ ],
118
+ )
119
+
120
+ quantize(
121
+ pipe.controlnet,
122
+ weights=qint8,
123
+ exclude=[
124
+ "*.norm", "*.norm1", "*.norm2", "*.norm2_context",
125
+ "proj_out", "x_embedder", "norm_out", "context_embedder",
126
+ ],
127
+ )
128
+ freeze(pipe.transformer)
129
+ freeze(pipe.controlnet)
130
+
131
+ pipe.enable_model_cpu_offload()
132
+ ```