Skip to content

Commit 73f5cad

Browse files
authored
Update README for code python mlx inference (#8)
* update README * update README shell -> python * fix small typo
1 parent 3e398ad commit 73f5cad

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Note:
6767
<details>
6868
<summary> Click to expand </summary>
6969

70+
### CLI ###
7071
For simple text-to-image in float16 precision:
7172
```shell
7273
diffusionkit-cli --prompt "a photo of a cat" --output-path </path/to/output/image.png> --seed 0 --w16 --a16
@@ -80,6 +81,57 @@ Some notable optional arguments:
8081

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

84+
### Code ###
85+
After installing the package, import it using:
86+
```python
87+
from python.src.mlx import DiffusionPipeline
88+
```
89+
90+
Then, initialize the pipeline object:
91+
```python
92+
pipeline = DiffusionPipeline(
93+
model="argmaxinc/stable-diffusion",
94+
w16=True,
95+
shift=3.0,
96+
use_t5=False,
97+
model_size="2b",
98+
low_memory_mode=False,
99+
a16=True,
100+
)
101+
```
102+
103+
Some notable optional arguments:
104+
- For T5 text embeddings, set `use_t5=True`
105+
- For using a local checkpoint, set `local_ckpt=</path/to/ckpt.safetensors>` (e.g. `~/models/stable-diffusion-3-medium/sd3_medium.safetensors`).
106+
- If you want to use the `pipeline` object more than once, set `low_memory_mode=False`.
107+
- For loading weights in FP32, set `w16=False`
108+
- For FP32 activations, set `a16=False`
109+
110+
Note: Only `2b` model size is available for this pipeline.
111+
112+
Finally, to generate the image, use the `generate_image()` function:
113+
```python
114+
HEIGHT = 512
115+
WIDTH = 512
116+
117+
image, _ = pipeline.generate_image(
118+
"a photo of a cat holding a sign that says 'Hello!'",
119+
cfg_weight=5.0,
120+
num_steps=50,
121+
latent_size=(HEIGHT // 8, WIDTH // 8),
122+
)
123+
```
124+
Some notable optional arguments:
125+
- For image-to-image, use `image_path` (path to input image) and `denoise` (value between 0. and 1.) input variables.
126+
- For seed, use `seed` input variable.
127+
- For negative prompt, use `negative_text` input variable.
128+
129+
130+
The generated `image` can be saved with:
131+
```python
132+
image.save("path/to/save.png")
133+
```
134+
83135
</details>
84136

85137
## Image Generation with Swift

0 commit comments

Comments
 (0)