radames commited on
Commit
a659304
1 Parent(s): 311d898
app.py CHANGED
@@ -12,6 +12,7 @@ print("TORCH_DTYPE:", torch_dtype)
12
  print("PIPELINE:", args.pipeline)
13
  print("SAFETY_CHECKER:", args.safety_checker)
14
  print("TORCH_COMPILE:", args.torch_compile)
 
15
  print("USE_TAESD:", args.taesd)
16
  print("COMPEL:", args.compel)
17
  print("DEBUG:", args.debug)
 
12
  print("PIPELINE:", args.pipeline)
13
  print("SAFETY_CHECKER:", args.safety_checker)
14
  print("TORCH_COMPILE:", args.torch_compile)
15
+ print("SFast:", args.sfast)
16
  print("USE_TAESD:", args.taesd)
17
  print("COMPEL:", args.compel)
18
  print("DEBUG:", args.debug)
app_init.py CHANGED
@@ -17,6 +17,8 @@ import asyncio
17
  import os
18
  import time
19
 
 
 
20
 
21
  def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
22
  app.add_middleware(
@@ -61,7 +63,7 @@ def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
61
  while True:
62
  data = await websocket.receive_json()
63
  if data["status"] != "next_frame":
64
- asyncio.sleep(1.0 / 24)
65
  continue
66
 
67
  params = await websocket.receive_json()
@@ -86,7 +88,7 @@ def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
86
  )
87
  await websocket.close()
88
  return
89
- await asyncio.sleep(1.0 / 24)
90
 
91
  except Exception as e:
92
  logging.error(f"Error: {e}")
 
17
  import os
18
  import time
19
 
20
+ THROTTLE = 1.0 / 120
21
+
22
 
23
  def init_app(app: FastAPI, user_data: UserData, args: Args, pipeline):
24
  app.add_middleware(
 
63
  while True:
64
  data = await websocket.receive_json()
65
  if data["status"] != "next_frame":
66
+ asyncio.sleep(THROTTLE)
67
  continue
68
 
69
  params = await websocket.receive_json()
 
88
  )
89
  await websocket.close()
90
  return
91
+ await asyncio.sleep(THROTTLE)
92
 
93
  except Exception as e:
94
  logging.error(f"Error: {e}")
frontend/src/lib/components/VideoInput.svelte CHANGED
@@ -20,7 +20,7 @@
20
  let videoFrameCallbackId: number;
21
 
22
  // ajust the throttle time to your needs
23
- const THROTTLE_TIME = 1000 / 15;
24
  let selectedDevice: string = '';
25
  let videoIsReady = false;
26
 
@@ -41,7 +41,7 @@
41
  }
42
  let lastMillis = 0;
43
  async function onFrameChange(now: DOMHighResTimeStamp, metadata: VideoFrameCallbackMetadata) {
44
- if (now - lastMillis < THROTTLE_TIME) {
45
  videoFrameCallbackId = videoEl.requestVideoFrameCallback(onFrameChange);
46
  return;
47
  }
 
20
  let videoFrameCallbackId: number;
21
 
22
  // ajust the throttle time to your needs
23
+ const THROTTLE = 1000 / 120;
24
  let selectedDevice: string = '';
25
  let videoIsReady = false;
26
 
 
41
  }
42
  let lastMillis = 0;
43
  async function onFrameChange(now: DOMHighResTimeStamp, metadata: VideoFrameCallbackMetadata) {
44
+ if (now - lastMillis < THROTTLE) {
45
  videoFrameCallbackId = videoEl.requestVideoFrameCallback(onFrameChange);
46
  return;
47
  }
pipelines/controlnet.py CHANGED
@@ -185,6 +185,7 @@ class Pipeline:
185
  config.enable_triton = True
186
  config.enable_cuda_graph = True
187
  self.pipe = compile(self.pipe, config=config)
 
188
  self.canny_torch = SobelOperator(device=device)
189
  self.pipe.set_progress_bar_config(disable=True)
190
  self.pipe.to(device=device, dtype=torch_dtype)
@@ -214,7 +215,6 @@ class Pipeline:
214
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
215
  generator = torch.manual_seed(params.seed)
216
  prompt_embeds = None
217
- control_image = None
218
  prompt = params.prompt
219
  if hasattr(self, "compel_proc"):
220
  prompt_embeds = self.compel_proc(params.prompt)
 
185
  config.enable_triton = True
186
  config.enable_cuda_graph = True
187
  self.pipe = compile(self.pipe, config=config)
188
+
189
  self.canny_torch = SobelOperator(device=device)
190
  self.pipe.set_progress_bar_config(disable=True)
191
  self.pipe.to(device=device, dtype=torch_dtype)
 
215
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
216
  generator = torch.manual_seed(params.seed)
217
  prompt_embeds = None
 
218
  prompt = params.prompt
219
  if hasattr(self, "compel_proc"):
220
  prompt_embeds = self.compel_proc(params.prompt)
pipelines/controlnetLoraSD15.py CHANGED
@@ -81,7 +81,7 @@ class Pipeline:
81
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
82
  )
83
  steps: int = Field(
84
- 4, min=1, max=15, title="Steps", field="range", hide=True, id="steps"
85
  )
86
  width: int = Field(
87
  768, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
@@ -90,7 +90,7 @@ class Pipeline:
90
  768, min=2, max=15, title="Height", disabled=True, hide=True, id="height"
91
  )
92
  guidance_scale: float = Field(
93
- 0.2,
94
  min=0,
95
  max=2,
96
  step=0.001,
@@ -195,13 +195,9 @@ class Pipeline:
195
  for pipe in self.pipes.values():
196
  pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
197
  pipe.set_progress_bar_config(disable=True)
198
- pipe.to(device=device, dtype=torch_dtype).to(device)
199
  if device.type != "mps":
200
  pipe.unet.to(memory_format=torch.channels_last)
201
 
202
- if psutil.virtual_memory().total < 64 * 1024**3:
203
- pipe.enable_attention_slicing()
204
-
205
  if args.taesd:
206
  pipe.vae = AutoencoderTiny.from_pretrained(
207
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
@@ -209,11 +205,13 @@ class Pipeline:
209
 
210
  # Load LCM LoRA
211
  pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
212
- pipe.compel_proc = Compel(
213
- tokenizer=pipe.tokenizer,
214
- text_encoder=pipe.text_encoder,
215
- truncate_long_prompts=False,
216
- )
 
 
217
  if args.torch_compile:
218
  pipe.unet = torch.compile(
219
  pipe.unet, mode="reduce-overhead", fullgraph=True
@@ -233,7 +231,12 @@ class Pipeline:
233
 
234
  activation_token = base_models[params.base_model_id]
235
  prompt = f"{activation_token} {params.prompt}"
236
- prompt_embeds = pipe.compel_proc(prompt)
 
 
 
 
 
237
  control_image = self.canny_torch(
238
  params.image, params.canny_low_threshold, params.canny_high_threshold
239
  )
@@ -245,6 +248,7 @@ class Pipeline:
245
  results = pipe(
246
  image=params.image,
247
  control_image=control_image,
 
248
  prompt_embeds=prompt_embeds,
249
  generator=generator,
250
  strength=strength,
 
81
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
82
  )
83
  steps: int = Field(
84
+ 1, min=1, max=15, title="Steps", field="range", hide=True, id="steps"
85
  )
86
  width: int = Field(
87
  768, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
 
90
  768, min=2, max=15, title="Height", disabled=True, hide=True, id="height"
91
  )
92
  guidance_scale: float = Field(
93
+ 1.0,
94
  min=0,
95
  max=2,
96
  step=0.001,
 
195
  for pipe in self.pipes.values():
196
  pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
197
  pipe.set_progress_bar_config(disable=True)
 
198
  if device.type != "mps":
199
  pipe.unet.to(memory_format=torch.channels_last)
200
 
 
 
 
201
  if args.taesd:
202
  pipe.vae = AutoencoderTiny.from_pretrained(
203
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
 
205
 
206
  # Load LCM LoRA
207
  pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
208
+ pipe.to(device=device, dtype=torch_dtype).to(device)
209
+ if args.compel:
210
+ self.compel_proc = Compel(
211
+ tokenizer=pipe.tokenizer,
212
+ text_encoder=pipe.text_encoder,
213
+ truncate_long_prompts=False,
214
+ )
215
  if args.torch_compile:
216
  pipe.unet = torch.compile(
217
  pipe.unet, mode="reduce-overhead", fullgraph=True
 
231
 
232
  activation_token = base_models[params.base_model_id]
233
  prompt = f"{activation_token} {params.prompt}"
234
+ prompt_embeds = None
235
+ prompt = params.prompt
236
+ if hasattr(self, "compel_proc"):
237
+ prompt_embeds = self.compel_proc(prompt)
238
+ prompt = None
239
+
240
  control_image = self.canny_torch(
241
  params.image, params.canny_low_threshold, params.canny_high_threshold
242
  )
 
248
  results = pipe(
249
  image=params.image,
250
  control_image=control_image,
251
+ prompt=prompt,
252
  prompt_embeds=prompt_embeds,
253
  generator=generator,
254
  strength=strength,
pipelines/controlnetLoraSDXL.py CHANGED
@@ -80,7 +80,7 @@ class Pipeline:
80
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
81
  )
82
  steps: int = Field(
83
- 2, min=1, max=15, title="Steps", field="range", hide=True, id="steps"
84
  )
85
  width: int = Field(
86
  1024, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
@@ -91,7 +91,7 @@ class Pipeline:
91
  guidance_scale: float = Field(
92
  1.0,
93
  min=0,
94
- max=20,
95
  step=0.001,
96
  title="Guidance Scale",
97
  field="range",
@@ -199,18 +199,30 @@ class Pipeline:
199
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
200
  self.pipe.set_progress_bar_config(disable=True)
201
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  if device.type != "mps":
203
  self.pipe.unet.to(memory_format=torch.channels_last)
204
 
205
- if psutil.virtual_memory().total < 64 * 1024**3:
206
- self.pipe.enable_attention_slicing()
 
 
 
 
 
207
 
208
- self.pipe.compel_proc = Compel(
209
- tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
210
- text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
211
- returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
212
- requires_pooled=[False, True],
213
- )
214
  if args.taesd:
215
  self.pipe.vae = AutoencoderTiny.from_pretrained(
216
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
@@ -232,9 +244,23 @@ class Pipeline:
232
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
233
  generator = torch.manual_seed(params.seed)
234
 
235
- prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
236
- [params.prompt, params.negative_prompt]
237
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  control_image = self.canny_torch(
239
  params.image, params.canny_low_threshold, params.canny_high_threshold
240
  )
@@ -246,10 +272,12 @@ class Pipeline:
246
  results = self.pipe(
247
  image=params.image,
248
  control_image=control_image,
249
- prompt_embeds=prompt_embeds[0:1],
250
- pooled_prompt_embeds=pooled_prompt_embeds[0:1],
251
- negative_prompt_embeds=prompt_embeds[1:2],
252
- negative_pooled_prompt_embeds=pooled_prompt_embeds[1:2],
 
 
253
  generator=generator,
254
  strength=strength,
255
  num_inference_steps=steps,
 
80
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
81
  )
82
  steps: int = Field(
83
+ 1, min=1, max=10, title="Steps", field="range", hide=True, id="steps"
84
  )
85
  width: int = Field(
86
  1024, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
 
91
  guidance_scale: float = Field(
92
  1.0,
93
  min=0,
94
+ max=2.0,
95
  step=0.001,
96
  title="Guidance Scale",
97
  field="range",
 
199
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
200
  self.pipe.set_progress_bar_config(disable=True)
201
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
202
+
203
+ if args.sfast:
204
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
205
+ compile,
206
+ CompilationConfig,
207
+ )
208
+
209
+ config = CompilationConfig.Default()
210
+ config.enable_xformers = True
211
+ config.enable_triton = True
212
+ config.enable_cuda_graph = True
213
+ self.pipe = compile(self.pipe, config=config)
214
+
215
  if device.type != "mps":
216
  self.pipe.unet.to(memory_format=torch.channels_last)
217
 
218
+ if args.compel:
219
+ self.pipe.compel_proc = Compel(
220
+ tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
221
+ text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
222
+ returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
223
+ requires_pooled=[False, True],
224
+ )
225
 
 
 
 
 
 
 
226
  if args.taesd:
227
  self.pipe.vae = AutoencoderTiny.from_pretrained(
228
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
 
244
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
245
  generator = torch.manual_seed(params.seed)
246
 
247
+ prompt = params.prompt
248
+ negative_prompt = params.negative_prompt
249
+ prompt_embeds = None
250
+ pooled_prompt_embeds = None
251
+ negative_prompt_embeds = None
252
+ negative_pooled_prompt_embeds = None
253
+ if hasattr(self.pipe, "compel_proc"):
254
+ _prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
255
+ [params.prompt, params.negative_prompt]
256
+ )
257
+ prompt = None
258
+ negative_prompt = None
259
+ prompt_embeds = _prompt_embeds[0:1]
260
+ pooled_prompt_embeds = pooled_prompt_embeds[0:1]
261
+ negative_prompt_embeds = _prompt_embeds[1:2]
262
+ negative_pooled_prompt_embeds = pooled_prompt_embeds[1:2]
263
+
264
  control_image = self.canny_torch(
265
  params.image, params.canny_low_threshold, params.canny_high_threshold
266
  )
 
272
  results = self.pipe(
273
  image=params.image,
274
  control_image=control_image,
275
+ prompt=prompt,
276
+ negative_prompt=negative_prompt,
277
+ prompt_embeds=prompt_embeds,
278
+ pooled_prompt_embeds=pooled_prompt_embeds,
279
+ negative_prompt_embeds=negative_prompt_embeds,
280
+ negative_pooled_prompt_embeds=negative_pooled_prompt_embeds,
281
  generator=generator,
282
  strength=strength,
283
  num_inference_steps=steps,
pipelines/{controlnelSD21Turbo.py → controlnetSDTurbo.py} RENAMED
File without changes
pipelines/controlnetSegmindVegaRT.py CHANGED
@@ -193,14 +193,24 @@ class Pipeline:
193
  self.pipe.scheduler = LCMScheduler.from_pretrained(
194
  base_model, subfolder="scheduler"
195
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  self.pipe.set_progress_bar_config(disable=True)
197
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
198
  if device.type != "mps":
199
  self.pipe.unet.to(memory_format=torch.channels_last)
200
 
201
- if psutil.virtual_memory().total < 64 * 1024**3:
202
- self.pipe.enable_attention_slicing()
203
-
204
  if args.compel:
205
  self.pipe.compel_proc = Compel(
206
  tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
 
193
  self.pipe.scheduler = LCMScheduler.from_pretrained(
194
  base_model, subfolder="scheduler"
195
  )
196
+
197
+ if args.sfast:
198
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
199
+ compile,
200
+ CompilationConfig,
201
+ )
202
+
203
+ config = CompilationConfig.Default()
204
+ config.enable_xformers = True
205
+ config.enable_triton = True
206
+ config.enable_cuda_graph = True
207
+ self.pipe = compile(self.pipe, config=config)
208
+
209
  self.pipe.set_progress_bar_config(disable=True)
210
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
211
  if device.type != "mps":
212
  self.pipe.unet.to(memory_format=torch.channels_last)
213
 
 
 
 
214
  if args.compel:
215
  self.pipe.compel_proc = Compel(
216
  tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
pipelines/img2img.py CHANGED
@@ -107,15 +107,23 @@ class Pipeline:
107
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
108
  ).to(device)
109
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  self.pipe.set_progress_bar_config(disable=True)
111
  self.pipe.to(device=device, dtype=torch_dtype)
112
  if device.type != "mps":
113
  self.pipe.unet.to(memory_format=torch.channels_last)
114
 
115
- # check if computer has less than 64GB of RAM using sys or os
116
- if psutil.virtual_memory().total < 64 * 1024**3:
117
- self.pipe.enable_attention_slicing()
118
-
119
  if args.torch_compile:
120
  print("Running torch compile")
121
  self.pipe.unet = torch.compile(
@@ -130,15 +138,20 @@ class Pipeline:
130
  image=[Image.new("RGB", (768, 768))],
131
  )
132
 
133
- self.compel_proc = Compel(
134
- tokenizer=self.pipe.tokenizer,
135
- text_encoder=self.pipe.text_encoder,
136
- truncate_long_prompts=False,
137
- )
 
138
 
139
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
140
  generator = torch.manual_seed(params.seed)
141
- prompt_embeds = self.compel_proc(params.prompt)
 
 
 
 
142
 
143
  steps = params.steps
144
  strength = params.strength
@@ -147,6 +160,7 @@ class Pipeline:
147
 
148
  results = self.pipe(
149
  image=params.image,
 
150
  prompt_embeds=prompt_embeds,
151
  generator=generator,
152
  strength=strength,
 
107
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
108
  ).to(device)
109
 
110
+ if args.sfast:
111
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
112
+ compile,
113
+ CompilationConfig,
114
+ )
115
+
116
+ config = CompilationConfig.Default()
117
+ config.enable_xformers = True
118
+ config.enable_triton = True
119
+ config.enable_cuda_graph = True
120
+ self.pipe = compile(self.pipe, config=config)
121
+
122
  self.pipe.set_progress_bar_config(disable=True)
123
  self.pipe.to(device=device, dtype=torch_dtype)
124
  if device.type != "mps":
125
  self.pipe.unet.to(memory_format=torch.channels_last)
126
 
 
 
 
 
127
  if args.torch_compile:
128
  print("Running torch compile")
129
  self.pipe.unet = torch.compile(
 
138
  image=[Image.new("RGB", (768, 768))],
139
  )
140
 
141
+ if args.compel:
142
+ self.compel_proc = Compel(
143
+ tokenizer=self.pipe.tokenizer,
144
+ text_encoder=self.pipe.text_encoder,
145
+ truncate_long_prompts=False,
146
+ )
147
 
148
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
149
  generator = torch.manual_seed(params.seed)
150
+ prompt_embeds = None
151
+ prompt = params.prompt
152
+ if hasattr(self, "compel_proc"):
153
+ prompt_embeds = self.compel_proc(params.prompt)
154
+ prompt = None
155
 
156
  steps = params.steps
157
  strength = params.strength
 
160
 
161
  results = self.pipe(
162
  image=params.image,
163
+ prompt=prompt,
164
  prompt_embeds=prompt_embeds,
165
  generator=generator,
166
  strength=strength,
pipelines/{img2imgSD21Turbo.py → img2imgSDTurbo.py} RENAMED
File without changes
pipelines/img2imgSDXLTurbo.py CHANGED
@@ -73,18 +73,18 @@ class Pipeline:
73
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
74
  )
75
  steps: int = Field(
76
- 4, min=1, max=15, title="Steps", field="range", hide=True, id="steps"
77
  )
78
  width: int = Field(
79
- 512, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
80
  )
81
  height: int = Field(
82
- 512, min=2, max=15, title="Height", disabled=True, hide=True, id="height"
83
  )
84
  guidance_scale: float = Field(
85
- 0.2,
86
  min=0,
87
- max=20,
88
  step=0.001,
89
  title="Guidance Scale",
90
  field="range",
@@ -115,15 +115,23 @@ class Pipeline:
115
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
116
  ).to(device)
117
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  self.pipe.set_progress_bar_config(disable=True)
119
  self.pipe.to(device=device, dtype=torch_dtype)
120
  if device.type != "mps":
121
  self.pipe.unet.to(memory_format=torch.channels_last)
122
 
123
- # check if computer has less than 64GB of RAM using sys or os
124
- if psutil.virtual_memory().total < 64 * 1024**3:
125
- self.pipe.enable_attention_slicing()
126
-
127
  if args.torch_compile:
128
  print("Running torch compile")
129
  self.pipe.unet = torch.compile(
@@ -132,24 +140,38 @@ class Pipeline:
132
  self.pipe.vae = torch.compile(
133
  self.pipe.vae, mode="reduce-overhead", fullgraph=True
134
  )
135
-
136
  self.pipe(
137
  prompt="warmup",
138
  image=[Image.new("RGB", (768, 768))],
139
  )
140
 
141
- self.pipe.compel_proc = Compel(
142
- tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
143
- text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
144
- returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
145
- requires_pooled=[False, True],
146
- )
 
147
 
148
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
149
  generator = torch.manual_seed(params.seed)
150
- prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
151
- [params.prompt, params.negative_prompt]
152
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  steps = params.steps
154
  strength = params.strength
155
  if int(steps * strength) < 1:
@@ -157,10 +179,12 @@ class Pipeline:
157
 
158
  results = self.pipe(
159
  image=params.image,
160
- prompt_embeds=prompt_embeds[0:1],
161
- pooled_prompt_embeds=pooled_prompt_embeds[0:1],
162
- negative_prompt_embeds=prompt_embeds[1:2],
163
- negative_pooled_prompt_embeds=pooled_prompt_embeds[1:2],
 
 
164
  generator=generator,
165
  strength=strength,
166
  num_inference_steps=steps,
 
73
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
74
  )
75
  steps: int = Field(
76
+ 1, min=1, max=10, title="Steps", field="range", hide=True, id="steps"
77
  )
78
  width: int = Field(
79
+ 768, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
80
  )
81
  height: int = Field(
82
+ 768, min=2, max=15, title="Height", disabled=True, hide=True, id="height"
83
  )
84
  guidance_scale: float = Field(
85
+ 1.0,
86
  min=0,
87
+ max=1,
88
  step=0.001,
89
  title="Guidance Scale",
90
  field="range",
 
115
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
116
  ).to(device)
117
 
118
+ if args.sfast:
119
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
120
+ compile,
121
+ CompilationConfig,
122
+ )
123
+
124
+ config = CompilationConfig.Default()
125
+ config.enable_xformers = True
126
+ config.enable_triton = True
127
+ config.enable_cuda_graph = True
128
+ self.pipe = compile(self.pipe, config=config)
129
+
130
  self.pipe.set_progress_bar_config(disable=True)
131
  self.pipe.to(device=device, dtype=torch_dtype)
132
  if device.type != "mps":
133
  self.pipe.unet.to(memory_format=torch.channels_last)
134
 
 
 
 
 
135
  if args.torch_compile:
136
  print("Running torch compile")
137
  self.pipe.unet = torch.compile(
 
140
  self.pipe.vae = torch.compile(
141
  self.pipe.vae, mode="reduce-overhead", fullgraph=True
142
  )
 
143
  self.pipe(
144
  prompt="warmup",
145
  image=[Image.new("RGB", (768, 768))],
146
  )
147
 
148
+ if args.compel:
149
+ self.pipe.compel_proc = Compel(
150
+ tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
151
+ text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
152
+ returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
153
+ requires_pooled=[False, True],
154
+ )
155
 
156
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
157
  generator = torch.manual_seed(params.seed)
158
+ prompt = params.prompt
159
+ negative_prompt = params.negative_prompt
160
+ prompt_embeds = None
161
+ pooled_prompt_embeds = None
162
+ negative_prompt_embeds = None
163
+ negative_pooled_prompt_embeds = None
164
+ if hasattr(self.pipe, "compel_proc"):
165
+ _prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
166
+ [params.prompt, params.negative_prompt]
167
+ )
168
+ prompt = None
169
+ negative_prompt = None
170
+ prompt_embeds = _prompt_embeds[0:1]
171
+ pooled_prompt_embeds = pooled_prompt_embeds[0:1]
172
+ negative_prompt_embeds = _prompt_embeds[1:2]
173
+ negative_pooled_prompt_embeds = pooled_prompt_embeds[1:2]
174
+
175
  steps = params.steps
176
  strength = params.strength
177
  if int(steps * strength) < 1:
 
179
 
180
  results = self.pipe(
181
  image=params.image,
182
+ prompt=prompt,
183
+ negative_prompt=negative_prompt,
184
+ prompt_embeds=prompt_embeds,
185
+ pooled_prompt_embeds=pooled_prompt_embeds,
186
+ negative_prompt_embeds=negative_prompt_embeds,
187
+ negative_pooled_prompt_embeds=negative_pooled_prompt_embeds,
188
  generator=generator,
189
  strength=strength,
190
  num_inference_steps=steps,
pipelines/img2imgSegmindVegaRT.py CHANGED
@@ -75,7 +75,7 @@ class Pipeline:
75
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
76
  )
77
  steps: int = Field(
78
- 4, min=1, max=15, title="Steps", field="range", hide=True, id="steps"
79
  )
80
  width: int = Field(
81
  1024, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
@@ -126,15 +126,23 @@ class Pipeline:
126
  self.pipe.scheduler = LCMScheduler.from_pretrained(
127
  base_model, subfolder="scheduler"
128
  )
 
 
 
 
 
 
 
 
 
 
 
 
129
  self.pipe.set_progress_bar_config(disable=True)
130
  self.pipe.to(device=device, dtype=torch_dtype)
131
  if device.type != "mps":
132
  self.pipe.unet.to(memory_format=torch.channels_last)
133
 
134
- # check if computer has less than 64GB of RAM using sys or os
135
- if psutil.virtual_memory().total < 64 * 1024**3:
136
- self.pipe.enable_attention_slicing()
137
-
138
  if args.torch_compile:
139
  print("Running torch compile")
140
  self.pipe.unet = torch.compile(
 
75
  2159232, min=0, title="Seed", field="seed", hide=True, id="seed"
76
  )
77
  steps: int = Field(
78
+ 1, min=1, max=10, title="Steps", field="range", hide=True, id="steps"
79
  )
80
  width: int = Field(
81
  1024, min=2, max=15, title="Width", disabled=True, hide=True, id="width"
 
126
  self.pipe.scheduler = LCMScheduler.from_pretrained(
127
  base_model, subfolder="scheduler"
128
  )
129
+ if args.sfast:
130
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
131
+ compile,
132
+ CompilationConfig,
133
+ )
134
+
135
+ config = CompilationConfig.Default()
136
+ config.enable_xformers = True
137
+ config.enable_triton = True
138
+ config.enable_cuda_graph = True
139
+ self.pipe = compile(self.pipe, config=config)
140
+
141
  self.pipe.set_progress_bar_config(disable=True)
142
  self.pipe.to(device=device, dtype=torch_dtype)
143
  if device.type != "mps":
144
  self.pipe.unet.to(memory_format=torch.channels_last)
145
 
 
 
 
 
146
  if args.torch_compile:
147
  print("Running torch compile")
148
  self.pipe.unet = torch.compile(
pipelines/txt2img.py CHANGED
@@ -90,15 +90,23 @@ class Pipeline:
90
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
91
  ).to(device)
92
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  self.pipe.set_progress_bar_config(disable=True)
94
  self.pipe.to(device=device, dtype=torch_dtype)
95
  if device.type != "mps":
96
  self.pipe.unet.to(memory_format=torch.channels_last)
97
 
98
- # check if computer has less than 64GB of RAM using sys or os
99
- if psutil.virtual_memory().total < 64 * 1024**3:
100
- self.pipe.enable_attention_slicing()
101
-
102
  if args.torch_compile:
103
  self.pipe.unet = torch.compile(
104
  self.pipe.unet, mode="reduce-overhead", fullgraph=True
@@ -109,17 +117,24 @@ class Pipeline:
109
 
110
  self.pipe(prompt="warmup", num_inference_steps=1, guidance_scale=8.0)
111
 
112
- self.compel_proc = Compel(
113
- tokenizer=self.pipe.tokenizer,
114
- text_encoder=self.pipe.text_encoder,
115
- truncate_long_prompts=False,
116
- )
 
117
 
118
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
119
  generator = torch.manual_seed(params.seed)
120
- prompt_embeds = self.compel_proc(params.prompt)
 
 
 
 
 
121
  results = self.pipe(
122
  prompt_embeds=prompt_embeds,
 
123
  generator=generator,
124
  num_inference_steps=params.steps,
125
  guidance_scale=params.guidance_scale,
 
90
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
91
  ).to(device)
92
 
93
+ if args.sfast:
94
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
95
+ compile,
96
+ CompilationConfig,
97
+ )
98
+
99
+ config = CompilationConfig.Default()
100
+ config.enable_xformers = True
101
+ config.enable_triton = True
102
+ config.enable_cuda_graph = True
103
+ self.pipe = compile(self.pipe, config=config)
104
+
105
  self.pipe.set_progress_bar_config(disable=True)
106
  self.pipe.to(device=device, dtype=torch_dtype)
107
  if device.type != "mps":
108
  self.pipe.unet.to(memory_format=torch.channels_last)
109
 
 
 
 
 
110
  if args.torch_compile:
111
  self.pipe.unet = torch.compile(
112
  self.pipe.unet, mode="reduce-overhead", fullgraph=True
 
117
 
118
  self.pipe(prompt="warmup", num_inference_steps=1, guidance_scale=8.0)
119
 
120
+ if args.compel:
121
+ self.compel_proc = Compel(
122
+ tokenizer=self.pipe.tokenizer,
123
+ text_encoder=self.pipe.text_encoder,
124
+ truncate_long_prompts=False,
125
+ )
126
 
127
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
128
  generator = torch.manual_seed(params.seed)
129
+ prompt_embeds = None
130
+ prompt = params.prompt
131
+ if hasattr(self, "compel_proc"):
132
+ prompt_embeds = self.compel_proc(params.prompt)
133
+ prompt = None
134
+
135
  results = self.pipe(
136
  prompt_embeds=prompt_embeds,
137
+ prompt=prompt,
138
  generator=generator,
139
  num_inference_steps=params.steps,
140
  guidance_scale=params.guidance_scale,
pipelines/txt2imgLora.py CHANGED
@@ -96,16 +96,15 @@ class Pipeline:
96
  self.pipe.vae = AutoencoderTiny.from_pretrained(
97
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
98
  ).to(device)
 
99
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
100
  self.pipe.set_progress_bar_config(disable=True)
 
101
  self.pipe.to(device=device, dtype=torch_dtype)
 
102
  if device.type != "mps":
103
  self.pipe.unet.to(memory_format=torch.channels_last)
104
 
105
- # check if computer has less than 64GB of RAM using sys or os
106
- if psutil.virtual_memory().total < 64 * 1024**3:
107
- self.pipe.enable_attention_slicing()
108
-
109
  if args.torch_compile:
110
  self.pipe.unet = torch.compile(
111
  self.pipe.unet, mode="reduce-overhead", fullgraph=True
@@ -116,18 +115,35 @@ class Pipeline:
116
 
117
  self.pipe(prompt="warmup", num_inference_steps=1, guidance_scale=8.0)
118
 
119
- self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
 
 
 
 
120
 
121
- self.compel_proc = Compel(
122
- tokenizer=self.pipe.tokenizer,
123
- text_encoder=self.pipe.text_encoder,
124
- truncate_long_prompts=False,
125
- )
 
 
 
 
 
 
 
126
 
127
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
128
  generator = torch.manual_seed(params.seed)
129
- prompt_embeds = self.compel_proc(params.prompt)
 
 
 
 
 
130
  results = self.pipe(
 
131
  prompt_embeds=prompt_embeds,
132
  generator=generator,
133
  num_inference_steps=params.steps,
 
96
  self.pipe.vae = AutoencoderTiny.from_pretrained(
97
  taesd_model, torch_dtype=torch_dtype, use_safetensors=True
98
  ).to(device)
99
+
100
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
101
  self.pipe.set_progress_bar_config(disable=True)
102
+ self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
103
  self.pipe.to(device=device, dtype=torch_dtype)
104
+
105
  if device.type != "mps":
106
  self.pipe.unet.to(memory_format=torch.channels_last)
107
 
 
 
 
 
108
  if args.torch_compile:
109
  self.pipe.unet = torch.compile(
110
  self.pipe.unet, mode="reduce-overhead", fullgraph=True
 
115
 
116
  self.pipe(prompt="warmup", num_inference_steps=1, guidance_scale=8.0)
117
 
118
+ if args.sfast:
119
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
120
+ compile,
121
+ CompilationConfig,
122
+ )
123
 
124
+ config = CompilationConfig.Default()
125
+ config.enable_xformers = True
126
+ config.enable_triton = True
127
+ config.enable_cuda_graph = True
128
+ self.pipe = compile(self.pipe, config=config)
129
+
130
+ if args.compel:
131
+ self.compel_proc = Compel(
132
+ tokenizer=self.pipe.tokenizer,
133
+ text_encoder=self.pipe.text_encoder,
134
+ truncate_long_prompts=False,
135
+ )
136
 
137
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
138
  generator = torch.manual_seed(params.seed)
139
+ prompt_embeds = None
140
+ prompt = params.prompt
141
+ if hasattr(self, "compel_proc"):
142
+ prompt_embeds = self.compel_proc(params.prompt)
143
+ prompt = None
144
+
145
  results = self.pipe(
146
+ prompt=prompt,
147
  prompt_embeds=prompt_embeds,
148
  generator=generator,
149
  num_inference_steps=params.steps,
pipelines/txt2imgLoraSDXL.py CHANGED
@@ -111,12 +111,22 @@ class Pipeline:
111
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
112
  self.pipe.set_progress_bar_config(disable=True)
113
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  if device.type != "mps":
115
  self.pipe.unet.to(memory_format=torch.channels_last)
116
 
117
- if psutil.virtual_memory().total < 64 * 1024**3:
118
- self.pipe.enable_attention_slicing()
119
-
120
  self.pipe.compel_proc = Compel(
121
  tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
122
  text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
@@ -142,14 +152,30 @@ class Pipeline:
142
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
143
  generator = torch.manual_seed(params.seed)
144
 
145
- prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
146
- [params.prompt, params.negative_prompt]
147
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  results = self.pipe(
149
- prompt_embeds=prompt_embeds[0:1],
150
- pooled_prompt_embeds=pooled_prompt_embeds[0:1],
151
- negative_prompt_embeds=prompt_embeds[1:2],
152
- negative_pooled_prompt_embeds=pooled_prompt_embeds[1:2],
 
 
153
  generator=generator,
154
  num_inference_steps=params.steps,
155
  guidance_scale=params.guidance_scale,
 
111
  self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
112
  self.pipe.set_progress_bar_config(disable=True)
113
  self.pipe.to(device=device, dtype=torch_dtype).to(device)
114
+
115
+ if args.sfast:
116
+ from sfast.compilers.stable_diffusion_pipeline_compiler import (
117
+ compile,
118
+ CompilationConfig,
119
+ )
120
+
121
+ config = CompilationConfig.Default()
122
+ config.enable_xformers = True
123
+ config.enable_triton = True
124
+ config.enable_cuda_graph = True
125
+ self.pipe = compile(self.pipe, config=config)
126
+
127
  if device.type != "mps":
128
  self.pipe.unet.to(memory_format=torch.channels_last)
129
 
 
 
 
130
  self.pipe.compel_proc = Compel(
131
  tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
132
  text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
 
152
  def predict(self, params: "Pipeline.InputParams") -> Image.Image:
153
  generator = torch.manual_seed(params.seed)
154
 
155
+ prompt = params.prompt
156
+ negative_prompt = params.negative_prompt
157
+ prompt_embeds = None
158
+ pooled_prompt_embeds = None
159
+ negative_prompt_embeds = None
160
+ negative_pooled_prompt_embeds = None
161
+ if hasattr(self.pipe, "compel_proc"):
162
+ _prompt_embeds, pooled_prompt_embeds = self.pipe.compel_proc(
163
+ [params.prompt, params.negative_prompt]
164
+ )
165
+ prompt = None
166
+ negative_prompt = None
167
+ prompt_embeds = _prompt_embeds[0:1]
168
+ pooled_prompt_embeds = pooled_prompt_embeds[0:1]
169
+ negative_prompt_embeds = _prompt_embeds[1:2]
170
+ negative_pooled_prompt_embeds = pooled_prompt_embeds[1:2]
171
+
172
  results = self.pipe(
173
+ prompt=prompt,
174
+ negative_prompt=negative_prompt,
175
+ prompt_embeds=prompt_embeds,
176
+ pooled_prompt_embeds=pooled_prompt_embeds,
177
+ negative_prompt_embeds=negative_prompt_embeds,
178
+ negative_pooled_prompt_embeds=negative_pooled_prompt_embeds,
179
  generator=generator,
180
  num_inference_steps=params.steps,
181
  guidance_scale=params.guidance_scale,