OzzyGT HF Staff commited on
Commit
7bd7cb5
·
1 Parent(s): dc65fcc

add readme

Browse files
Files changed (1) hide show
  1. README.md +102 -0
README.md CHANGED
@@ -11,3 +11,105 @@ tags:
11
  - krea
12
  license: apache-2.0
13
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  - krea
12
  license: apache-2.0
13
  ---
14
+
15
+ # Krea 2 reference-image modular blocks
16
+
17
+ Custom [Modular Diffusers](https://huggingface.co/docs/diffusers/main/en/modular_diffusers/overview) blocks that
18
+ let Krea 2 take reference images. Its text encoder is the full Qwen3-VL, vision tower included, so a reference
19
+ can condition the generation through the encoder's vision path without any extra model. Two community edit
20
+ LoRAs go further and feed the reference into the transformer as clean VAE latents.
21
+
22
+ `reference_mode` picks the path:
23
+
24
+ ```
25
+ reference_mode="off" Qwen3-VL vision path only. No LoRA, works on the stock checkpoint
26
+ reference_mode="append" vision + clean reference tokens after the target. Ostris style-reference LoRA
27
+ reference_mode="prepend" vision + clean source before the target. Identity-Edit LoRA
28
+ ```
29
+
30
+ With `reference_mode="off"` and no images, the blocks are stock text-to-image. No mode patches the
31
+ transformer.
32
+
33
+ ## Loading & running
34
+
35
+ ```python
36
+ import sdnq # needed to load the quantized text encoder
37
+ import torch
38
+
39
+ from diffusers import ModularPipeline
40
+ from diffusers.utils import load_image
41
+
42
+
43
+ pipe = ModularPipeline.from_pretrained(
44
+ "OzzyGT/krea2_reference_blocks", trust_remote_code=True
45
+ )
46
+ pipe.load_components(dtype=torch.bfloat16)
47
+ pipe.to("cuda")
48
+
49
+ image = pipe(
50
+ prompt="the same cat, sitting on a stone wall at sunset",
51
+ reference_images=load_image("cat.png"),
52
+ height=1024,
53
+ width=1024,
54
+ output="images",
55
+ )[0]
56
+ image.save("reference.png")
57
+ ```
58
+
59
+ The LoRA modes need their adapter loaded first:
60
+
61
+ ```python
62
+ pipe.load_lora_weights("ostris/krea2_turbo_style_reference", weight_name="krea2_style_reference.safetensors")
63
+
64
+ image = pipe(
65
+ prompt="the same subject in a snowy forest",
66
+ reference_images=load_image("subject.png"),
67
+ reference_mode="append",
68
+ output="images",
69
+ )[0]
70
+ ```
71
+
72
+ For loading a different checkpoint or swapping components, see
73
+ [Modular pipeline](https://huggingface.co/docs/diffusers/main/en/modular_diffusers/modular_pipeline) in the
74
+ diffusers docs.
75
+
76
+ ## Reference inputs
77
+
78
+ ```
79
+ reference_images one image or a list
80
+ reference_subject_strength scales content and subject. 1.0 default, 0 drops it
81
+ reference_style_strength scales texture and style. 1.0 default, 0 drops it
82
+ grounding_px longest side of the view the VLM sees, 768 default
83
+ ```
84
+
85
+ Either strength takes one value for every reference, or a list matching them one to one, so a reference can
86
+ give its look without its content or the other way round. `grounding_px` is the identity-versus-adherence
87
+ dial: lower follows the prompt, higher holds the reference, `0` is native resolution.
88
+
89
+ ## Masks
90
+
91
+ `reference_masks` restricts a reference to part of the picture, painted being the part to use. One mask per
92
+ image, or `None` for a slot without one.
93
+
94
+ `reference_mask_mode` decides what happens to the rest:
95
+
96
+ ```
97
+ "exclude_blank" default. Mask the vision attention and blank the masked-out tokens
98
+ "exclude" mask the attention only, leaving the masked-out tokens in the sequence
99
+ "deemphasize" blank the tokens only, which attenuates the region instead of removing it
100
+ ```
101
+
102
+ Masks always apply to the vision path. In the LoRA modes the clean reference latents are unmasked by default,
103
+ so the edit still sees the whole image and a masked edit can show hints of the unpainted parts. Set
104
+ `mask_reference_latents=True` to drop those patches from the sequence too.
105
+
106
+ These blocks only work with Krea 2, Turbo or raw.
107
+
108
+ ## Credits
109
+
110
+ - [`ostris/krea2_turbo_style_reference`](https://huggingface.co/ostris/krea2_turbo_style_reference) -- the
111
+ style-reference LoRA behind `append`
112
+ - [`conradlocke/krea2-identity-edit`](https://huggingface.co/conradlocke/krea2-identity-edit) -- the
113
+ Identity-Edit LoRA behind `prepend`
114
+ - Both recipes come from [ai-toolkit](https://github.com/ostris/ai-toolkit); `append` follows its
115
+ reference/edit setup, `prepend` its `predict_velocity_edit`.