dagloop5 commited on
Commit
62b9248
·
verified ·
1 Parent(s): 23f6945

Update pk_workflow.py

Browse files
Files changed (1) hide show
  1. pk_workflow.py +19 -14
pk_workflow.py CHANGED
@@ -179,29 +179,35 @@ SCHEDULE_SIGMA_FUNCS = {
179
  class use_schedule:
180
  """Set each scheduler's shift for one request, and — for anything but `native` — force its sigma grid onto
181
  one of `SCHEDULE_SIGMA_FUNCS`'s named schedules.
182
- Shift is applied unconditionally, including under `native`, so the shift sliders affect the pipeline's own
183
- default schedule too and not just the custom onesand it is always restored on exit, since
184
- `pipe.scheduler`/`pipe.audio_scheduler` are shared, request-spanning objects that must not carry one
185
- request's shift into the next.
 
 
186
  """
187
 
188
  def __init__(self, pipe, steps: int, schedule_name: str, video_shift: float, audio_shift: float, threshold_noise: float = 0.025):
189
- self.schedulers = [pipe.scheduler, pipe.audio_scheduler]
 
190
  self.shifts = [float(video_shift), float(audio_shift)]
191
  self.schedule_name = schedule_name
192
  self.steps = int(steps)
193
  self.threshold_noise = float(threshold_noise)
194
- self._originals = []
195
 
196
  def __enter__(self):
197
- self._originals = [(scheduler, scheduler.shift) for scheduler in self.schedulers]
198
- for scheduler, shift in zip(self.schedulers, self.shifts):
199
- scheduler.shift = shift
 
 
200
 
201
  if self.schedule_name != "native":
202
  sigma_func = SCHEDULE_SIGMA_FUNCS[self.schedule_name]
203
  base = sigma_func(self.steps, self.threshold_noise) if sigma_func is linear_quadratic_sigmas else sigma_func(self.steps)
204
- for scheduler in self.schedulers:
 
205
  sigmas = time_shift_sigma(base, 1.0, float(scheduler.shift))
206
  unbound = type(scheduler).set_timesteps
207
 
@@ -212,10 +218,9 @@ class use_schedule:
212
  return self
213
 
214
  def __exit__(self, *_):
215
- for scheduler in self.schedulers:
216
- scheduler.__dict__.pop("set_timesteps", None)
217
- for scheduler, original_shift in self._originals:
218
- scheduler.shift = original_shift
219
  return False
220
 
221
 
 
179
  class use_schedule:
180
  """Set each scheduler's shift for one request, and — for anything but `native` — force its sigma grid onto
181
  one of `SCHEDULE_SIGMA_FUNCS`'s named schedules.
182
+ `MiniMaxH3Scheduler.shift` is a read-only property, so a different shift means swapping in a freshly built
183
+ scheduler via `from_config(..., shift=...)` rather than mutating one in place the standard diffusers idiom
184
+ for changing a `ConfigMixin` parameter after construction, and correct regardless of exactly how `shift` is
185
+ stored internally. Applied unconditionally, including under `native`, so the shift sliders affect the
186
+ pipeline's own default schedule too — and always restored on exit, since `pipe.scheduler`/`pipe.audio_scheduler`
187
+ are shared, request-spanning objects that must not carry one request's shift into the next.
188
  """
189
 
190
  def __init__(self, pipe, steps: int, schedule_name: str, video_shift: float, audio_shift: float, threshold_noise: float = 0.025):
191
+ self.pipe = pipe
192
+ self.attr_names = ["scheduler", "audio_scheduler"]
193
  self.shifts = [float(video_shift), float(audio_shift)]
194
  self.schedule_name = schedule_name
195
  self.steps = int(steps)
196
  self.threshold_noise = float(threshold_noise)
197
+ self._originals: dict = {}
198
 
199
  def __enter__(self):
200
+ for attr_name, shift in zip(self.attr_names, self.shifts):
201
+ original = getattr(self.pipe, attr_name)
202
+ self._originals[attr_name] = original
203
+ if float(original.shift) != shift:
204
+ setattr(self.pipe, attr_name, type(original).from_config(original.config, shift=shift))
205
 
206
  if self.schedule_name != "native":
207
  sigma_func = SCHEDULE_SIGMA_FUNCS[self.schedule_name]
208
  base = sigma_func(self.steps, self.threshold_noise) if sigma_func is linear_quadratic_sigmas else sigma_func(self.steps)
209
+ for attr_name in self.attr_names:
210
+ scheduler = getattr(self.pipe, attr_name)
211
  sigmas = time_shift_sigma(base, 1.0, float(scheduler.shift))
212
  unbound = type(scheduler).set_timesteps
213
 
 
218
  return self
219
 
220
  def __exit__(self, *_):
221
+ for attr_name, original in self._originals.items():
222
+ getattr(self.pipe, attr_name).__dict__.pop("set_timesteps", None)
223
+ setattr(self.pipe, attr_name, original)
 
224
  return False
225
 
226