Spaces:
Running on Zero
Running on Zero
Update pk_workflow.py
Browse files- pk_workflow.py +17 -3
pk_workflow.py
CHANGED
|
@@ -514,7 +514,7 @@ class use_schedule:
|
|
| 514 |
are shared, request-spanning objects that must not carry one request's shift into the next.
|
| 515 |
"""
|
| 516 |
|
| 517 |
-
def __init__(self, pipe, steps: int, schedule_name: str, video_shift: float, audio_shift: float, sampler_name: str = "euler", seed: int = 0, threshold_noise: float = 0.025):
|
| 518 |
self.pipe = pipe
|
| 519 |
self.attr_names = ["scheduler", "audio_scheduler"]
|
| 520 |
self.shifts = [float(video_shift), float(audio_shift)]
|
|
@@ -523,6 +523,15 @@ class use_schedule:
|
|
| 523 |
self.seed = int(seed)
|
| 524 |
self.steps = int(steps)
|
| 525 |
self.threshold_noise = float(threshold_noise)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
self._originals: dict = {}
|
| 527 |
|
| 528 |
def __enter__(self):
|
|
@@ -534,10 +543,15 @@ class use_schedule:
|
|
| 534 |
|
| 535 |
if self.schedule_name != "native":
|
| 536 |
sigma_func = SCHEDULE_SIGMA_FUNCS[self.schedule_name]
|
| 537 |
-
base =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
for attr_name in self.attr_names:
|
| 539 |
scheduler = getattr(self.pipe, attr_name)
|
| 540 |
-
|
|
|
|
| 541 |
unbound = type(scheduler).set_timesteps
|
| 542 |
|
| 543 |
def forced(num_inference_steps=None, device=None, sigmas=None, _s=scheduler, _grid=sigmas, _f=unbound):
|
|
|
|
| 514 |
are shared, request-spanning objects that must not carry one request's shift into the next.
|
| 515 |
"""
|
| 516 |
|
| 517 |
+
def __init__(self, pipe, steps: int, schedule_name: str, video_shift: float, audio_shift: float, sampler_name: str = "euler", seed: int = 0, threshold_noise: float = 0.025, total_steps: int | None = None, stage_from: int = 0):
|
| 518 |
self.pipe = pipe
|
| 519 |
self.attr_names = ["scheduler", "audio_scheduler"]
|
| 520 |
self.shifts = [float(video_shift), float(audio_shift)]
|
|
|
|
| 523 |
self.seed = int(seed)
|
| 524 |
self.steps = int(steps)
|
| 525 |
self.threshold_noise = float(threshold_noise)
|
| 526 |
+
# Staged Denoising: `total_steps` builds the schedule at the eventual target length rather than `steps`,
|
| 527 |
+
# and `stage_from` slices this stage's own `steps`-length span out of it
|
| 528 |
+
# (`sigmas_full[stage_from : stage_from + steps + 1]`) rather than the schedule's own start. Every
|
| 529 |
+
# schedule and every custom-step sampler is a pure function of its sigma array, so a slice of a longer
|
| 530 |
+
# schedule is mathematically indistinguishable, from the sampler's perspective, from a complete schedule
|
| 531 |
+
# of that length — nothing below this class needs to know a stage boundary exists. Defaults reproduce
|
| 532 |
+
# the unstaged behavior exactly (`total_steps=None` falls back to `steps`, `stage_from=0`).
|
| 533 |
+
self.total_steps = int(total_steps) if total_steps is not None else int(steps)
|
| 534 |
+
self.stage_from = int(stage_from)
|
| 535 |
self._originals: dict = {}
|
| 536 |
|
| 537 |
def __enter__(self):
|
|
|
|
| 543 |
|
| 544 |
if self.schedule_name != "native":
|
| 545 |
sigma_func = SCHEDULE_SIGMA_FUNCS[self.schedule_name]
|
| 546 |
+
base = (
|
| 547 |
+
sigma_func(self.total_steps, self.threshold_noise)
|
| 548 |
+
if sigma_func is linear_quadratic_sigmas
|
| 549 |
+
else sigma_func(self.total_steps)
|
| 550 |
+
)
|
| 551 |
for attr_name in self.attr_names:
|
| 552 |
scheduler = getattr(self.pipe, attr_name)
|
| 553 |
+
sigmas_full = time_shift_sigma(base, 1.0, float(scheduler.shift))
|
| 554 |
+
sigmas = sigmas_full[self.stage_from : self.stage_from + self.steps + 1]
|
| 555 |
unbound = type(scheduler).set_timesteps
|
| 556 |
|
| 557 |
def forced(num_inference_steps=None, device=None, sigmas=None, _s=scheduler, _grid=sigmas, _f=unbound):
|