Skip to content

Commit 730a876

Browse files
committed
README update for FLUX
1 parent 4c2bde3 commit 730a876

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

README.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pip install -e .
2828

2929
### Hugging Face Hub Credentials
3030

31+
<details>
32+
<summary> Click to expand </summary>
33+
34+
3135
[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:
3236
> [!IMPORTANT]
3337
> 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 .
3640
huggingface-cli login --token YOUR_HF_HUB_TOKEN
3741
```
3842

43+
</details>
44+
45+
3946
## <a name="converting-models-to-coreml"></a> Converting Models from PyTorch to Core ML
4047

4148
<details>
@@ -67,56 +74,61 @@ Note:
6774
<summary> Click to expand </summary>
6875

6976
### CLI ###
70-
For simple text-to-image in float16 precision:
77+
78+
Most simple:
7179
```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>
7381
```
7482

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`).
8089

8190
Please refer to the help menu for all available arguments: `diffusionkit-cli -h`.
8291

8392
### Code ###
84-
After installing the package, import it using:
85-
```python
86-
from diffusionkit.mlx import DiffusionPipeline
87-
```
8893

89-
Then, initialize the pipeline object:
94+
For Stable Diffusion 3:
9095
```python
96+
from diffusionkit.mlx import DiffusionPipeline
9197
pipeline = DiffusionPipeline(
9298
model="argmaxinc/stable-diffusion",
93-
w16=True,
9499
shift=3.0,
95100
use_t5=False,
96-
model_version="2b",
97-
low_memory_mode=False,
101+
model_version="stable-diffusion-3-medium",
102+
low_memory_mode=True,
98103
a16=True,
104+
w16=True,
99105
)
100106
```
101107

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+
```
110120

111121
Finally, to generate the image, use the `generate_image()` function:
112122
```python
113123
HEIGHT = 512
114124
WIDTH = 512
125+
NUM_STEPS = 50 # 4 for FLUX.1-schnell
126+
CFG_WEIGHT = 5.0 # 0. for FLUX.1-schnell
115127

116128
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,
120132
latent_size=(HEIGHT // 8, WIDTH // 8),
121133
)
122134
```
@@ -125,7 +137,6 @@ Some notable optional arguments:
125137
- For seed, use `seed` input variable.
126138
- For negative prompt, use `negative_text` input variable.
127139

128-
129140
The generated `image` can be saved with:
130141
```python
131142
image.save("path/to/save.png")

python/src/diffusionkit/mlx/model_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ def load_flux(
686686

687687
flux_weights = _MMDIT[key][model_key]
688688
flux_weights_ckpt = LOCAl_SD3_CKPT or hf_hub_download(key, flux_weights)
689-
hf_hub_download(key, "config.json") # To count number of downloads
689+
hf_hub_download(key, "config.json")
690690
weights = mx.load(flux_weights_ckpt)
691691
weights = flux_state_dict_adjustments(
692692
weights, prefix="", hidden_size=config.hidden_size, mlp_ratio=config.mlp_ratio

0 commit comments

Comments
 (0)