67
67
<details >
68
68
<summary > Click to expand </summary >
69
69
70
+ ### CLI ###
70
71
For simple text-to-image in float16 precision:
71
72
``` shell
72
73
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:
80
81
81
82
Please refer to the help menu for all available arguments: ` diffusionkit-cli -h ` .
82
83
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
+
83
135
</details >
84
136
85
137
## Image Generation with Swift
0 commit comments