You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-27Lines changed: 38 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,10 @@ pip install -e .
28
28
29
29
### Hugging Face Hub Credentials
30
30
31
+
<details>
32
+
<summary> Click to expand </summary>
33
+
34
+
31
35
[Stable Diffusion 3](https://huggingface.co/stabilityai/stable-diffusion-3-medium) requires users to accept the terms before downloading the checkpoint. Once you accept the terms, sign in with your Hugging Face hub READ token as below:
32
36
> [!IMPORTANT]
33
37
> If using a fine-grained token, it is also necessary to [edit permissions](https://huggingface.co/settings/tokens) to allow `Read access to contents of all public gated repos you can access`
@@ -36,6 +40,9 @@ pip install -e .
36
40
huggingface-cli login --token YOUR_HF_HUB_TOKEN
37
41
```
38
42
43
+
</details>
44
+
45
+
39
46
## <aname="converting-models-to-coreml"></a> Converting Models from PyTorch to Core ML
40
47
41
48
<details>
@@ -67,56 +74,61 @@ Note:
67
74
<summary> Click to expand </summary>
68
75
69
76
### CLI ###
70
-
For simple text-to-image in float16 precision:
77
+
78
+
Most simple:
71
79
```shell
72
-
diffusionkit-cli --prompt "a photo of a cat" --output-path </path/to/output/image.png> --seed 0 --w16 --a16
80
+
diffusionkit-cli --prompt "a photo of a cat" --output-path </path/to/output/image.png>
73
81
```
74
82
75
-
Some notable optional arguments:
76
-
- For image-to-image, use `--image-path` (path to input image) and `--denoise` (value between 0. and 1.)
77
-
- T5 text embeddings, use `--t5`
78
-
- For different resolutions, use `--height` and `--width`
79
-
- For using a local checkpoint, use `--local-ckpt </path/to/ckpt.safetensors>` (e.g. `~/models/stable-diffusion-3-medium/sd3_medium.safetensors`).
83
+
Some notable optional arguments for:
84
+
- Reproduciblity of results, use `--seed`
85
+
- image-to-image, use `--image-path` (path to input image) and `--denoise` (value between 0. and 1.)
86
+
- Enabling T5 encoder in SD3, use `--t5` (FLUX must use T5 regardless of this argument)
87
+
- Different resolutions, use `--height` and `--width`
88
+
- Using a local checkpoint, use `--local-ckpt </path/to/ckpt.safetensors>` (e.g. `~/models/stable-diffusion-3-medium/sd3_medium.safetensors`).
80
89
81
90
Please refer to the help menu for all available arguments: `diffusionkit-cli -h`.
82
91
83
92
### Code ###
84
-
After installing the package, import it using:
85
-
```python
86
-
from diffusionkit.mlx import DiffusionPipeline
87
-
```
88
93
89
-
Then, initialize the pipeline object:
94
+
For Stable Diffusion 3:
90
95
```python
96
+
from diffusionkit.mlx import DiffusionPipeline
91
97
pipeline = DiffusionPipeline(
92
98
model="argmaxinc/stable-diffusion",
93
-
w16=True,
94
99
shift=3.0,
95
100
use_t5=False,
96
-
model_version="2b",
97
-
low_memory_mode=False,
101
+
model_version="stable-diffusion-3-medium",
102
+
low_memory_mode=True,
98
103
a16=True,
104
+
w16=True,
99
105
)
100
106
```
101
107
102
-
Some notable optional arguments:
103
-
- For T5 text embeddings, set `use_t5=True`
104
-
- For using a local checkpoint, set `local_ckpt=</path/to/ckpt.safetensors>` (e.g. `~/models/stable-diffusion-3-medium/sd3_medium.safetensors`).
105
-
- If you want to use the `pipeline` object more than once, set `low_memory_mode=False`.
106
-
- For loading weights in FP32, set `w16=False`
107
-
- For FP32 activations, set `a16=False`
108
-
109
-
Note: Only `2b` model size is available for this pipeline.
108
+
For FLUX:
109
+
```python
110
+
from diffusionkit.mlx import FLUXPipeline
111
+
pipeline = DiffusionPipeline(
112
+
model="argmaxinc/stable-diffusion",
113
+
shift=1.0,
114
+
model_version="FLUX.1-schnell",
115
+
low_memory_mode=True,
116
+
a16=True,
117
+
w16=True,
118
+
)
119
+
```
110
120
111
121
Finally, to generate the image, use the `generate_image()` function:
112
122
```python
113
123
HEIGHT=512
114
124
WIDTH=512
125
+
NUM_STEPS=50# 4 for FLUX.1-schnell
126
+
CFG_WEIGHT=5.0# 0. for FLUX.1-schnell
115
127
116
128
image, _ = pipeline.generate_image(
117
-
"a photo of a cat holding a sign that says 'Hello!'",
118
-
cfg_weight=5.0,
119
-
num_steps=50,
129
+
"a photo of a cat",
130
+
cfg_weight=CFG_WEIGHT,
131
+
num_steps=NUM_STEPS,
120
132
latent_size=(HEIGHT//8, WIDTH//8),
121
133
)
122
134
```
@@ -125,7 +137,6 @@ Some notable optional arguments:
125
137
- For seed, use `seed` input variable.
126
138
- For negative prompt, use `negative_text` input variable.
0 commit comments