Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
2e2962b
1
Parent(s):
50e5c16
provide free-uni-p
Browse files- README.md +1 -1
- customed_unipc_scheduler.py +37 -29
README.md
CHANGED
|
@@ -8,7 +8,7 @@ sdk_version: 6.0.1
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description: A few-step UniPC solver with customed hyperparameters
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: A few-step UniPC solver with customed hyperparameters, github links https://github.com/TheLovesOfLadyPurple/Hyperparameters-are-all-you-need
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
customed_unipc_scheduler.py
CHANGED
|
@@ -213,10 +213,10 @@ class CustomedUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
|
|
| 213 |
steps_offset: int = 0,
|
| 214 |
final_sigmas_type: Optional[str] = "zero", # "zero", "sigma_min"
|
| 215 |
skip_type: str = "customed_time_karras",
|
| 216 |
-
denoise_to_zero: bool = False,
|
| 217 |
rescale_betas_zero_snr: bool = False,
|
| 218 |
use_afs: bool = False,
|
| 219 |
-
use_free_predictor = False
|
|
|
|
| 220 |
):
|
| 221 |
|
| 222 |
if self.config.use_beta_sigmas and not is_scipy_available():
|
|
@@ -241,7 +241,7 @@ class CustomedUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
|
|
| 241 |
self.skip_type = skip_type
|
| 242 |
self.use_free_predictor = use_free_predictor
|
| 243 |
self.use_afs = use_afs
|
| 244 |
-
self.
|
| 245 |
if rescale_betas_zero_snr:
|
| 246 |
self.betas = rescale_zero_terminal_snr(self.betas)
|
| 247 |
|
|
@@ -320,7 +320,7 @@ class CustomedUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
|
|
| 320 |
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
| 321 |
"""
|
| 322 |
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://huggingface.co/papers/2305.08891
|
| 323 |
-
|
| 324 |
sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5)
|
| 325 |
if self.skip_type == "customed_time_karras":
|
| 326 |
sigma_T = sigmas[-1]
|
|
@@ -331,51 +331,59 @@ class CustomedUniPCMultistepScheduler(SchedulerMixin, ConfigMixin):
|
|
| 331 |
sigmas = self.get_sigmas_karras(12, sigma_0, sigma_T, rho=7.0)
|
| 332 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 333 |
ct_end = self._sigma_to_t(sigmas[9], log_sigmas)
|
| 334 |
-
if self.
|
| 335 |
-
ct_real_end = self._sigma_to_t(sigmas[-1], log_sigmas)
|
| 336 |
-
timesteps = self.get_sigmas_karras(9 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2, customed_final_sigma= ct_real_end if self.denoise_to_zero else None)
|
| 337 |
elif N == 5:
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
elif N == 6:
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
elif N == 7:
|
| 354 |
log_sigmas = np.log(sigmas)
|
| 355 |
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 356 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 357 |
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 358 |
-
if self.
|
| 359 |
-
ct_real_end = self._sigma_to_t(sigmas[-1], log_sigmas)
|
| 360 |
-
timesteps = self.get_sigmas_karras(7 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2, customed_final_sigma= ct_real_end if self.denoise_to_zero else None)
|
| 361 |
elif N == 8:
|
| 362 |
log_sigmas = np.log(sigmas).copy()
|
| 363 |
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 364 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 365 |
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 366 |
-
if self.
|
| 367 |
-
ct_real_end = self._sigma_to_t(sigmas[-1], log_sigmas)
|
| 368 |
-
timesteps = self.get_sigmas_karras(8 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2, customed_final_sigma= ct_real_end if self.denoise_to_zero else None)
|
| 369 |
|
| 370 |
if self.use_afs and N > 6:
|
| 371 |
timesteps = np.insert(timesteps,1,(timesteps[0]+timesteps[1]) / 2)
|
| 372 |
|
| 373 |
|
| 374 |
timesteps_tmp = copy.deepcopy(timesteps)
|
| 375 |
-
|
|
|
|
| 376 |
sigmas = np.array([self._t_to_sigma(t, log_sigmas) for t in timesteps_tmp])
|
| 377 |
self.sigmas = torch.from_numpy(sigmas)
|
| 378 |
-
|
|
|
|
|
|
|
|
|
|
| 379 |
|
| 380 |
self.num_inference_steps = len(timesteps)
|
| 381 |
|
|
|
|
| 213 |
steps_offset: int = 0,
|
| 214 |
final_sigmas_type: Optional[str] = "zero", # "zero", "sigma_min"
|
| 215 |
skip_type: str = "customed_time_karras",
|
|
|
|
| 216 |
rescale_betas_zero_snr: bool = False,
|
| 217 |
use_afs: bool = False,
|
| 218 |
+
use_free_predictor = False,
|
| 219 |
+
ultilize_vae = False
|
| 220 |
):
|
| 221 |
|
| 222 |
if self.config.use_beta_sigmas and not is_scipy_available():
|
|
|
|
| 241 |
self.skip_type = skip_type
|
| 242 |
self.use_free_predictor = use_free_predictor
|
| 243 |
self.use_afs = use_afs
|
| 244 |
+
self.ultilize_vae = ultilize_vae
|
| 245 |
if rescale_betas_zero_snr:
|
| 246 |
self.betas = rescale_zero_terminal_snr(self.betas)
|
| 247 |
|
|
|
|
| 320 |
The device to which the timesteps should be moved to. If `None`, the timesteps are not moved.
|
| 321 |
"""
|
| 322 |
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://huggingface.co/papers/2305.08891
|
| 323 |
+
self.ultilize_vae = self.ultilize_vae and num_inference_steps >=5
|
| 324 |
sigmas = np.array(((1 - self.alphas_cumprod) / self.alphas_cumprod) ** 0.5)
|
| 325 |
if self.skip_type == "customed_time_karras":
|
| 326 |
sigma_T = sigmas[-1]
|
|
|
|
| 331 |
sigmas = self.get_sigmas_karras(12, sigma_0, sigma_T, rho=7.0)
|
| 332 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 333 |
ct_end = self._sigma_to_t(sigmas[9], log_sigmas)
|
| 334 |
+
timesteps = self.get_sigmas_karras(9 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
|
|
|
|
|
|
| 335 |
elif N == 5:
|
| 336 |
+
if not self.ultilize_vae:
|
| 337 |
+
log_sigmas = np.log(sigmas)
|
| 338 |
+
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 339 |
+
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 340 |
+
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 341 |
+
timesteps = self.get_sigmas_karras(5 + (1 if self.use_afs else 0) + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
| 342 |
+
else:
|
| 343 |
+
log_sigmas = np.log(sigmas)
|
| 344 |
+
sigmas = self.get_sigmas_karras(12, sigma_0, sigma_T,rho=12.0)
|
| 345 |
+
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 346 |
+
ct_end = self._sigma_to_t(sigmas[10], log_sigmas)
|
| 347 |
+
timesteps = self.get_sigmas_karras(6 + (1 if self.use_afs else 0) + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
| 348 |
elif N == 6:
|
| 349 |
+
if not self.ultilize_vae:
|
| 350 |
+
log_sigmas = np.log(sigmas)
|
| 351 |
+
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 352 |
+
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 353 |
+
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 354 |
+
timesteps = self.get_sigmas_karras(6 + (1 if self.use_afs else 0) + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
| 355 |
+
else:
|
| 356 |
+
log_sigmas = np.log(sigmas)
|
| 357 |
+
sigmas = self.get_sigmas_karras(12, sigma_0, sigma_T,rho=12.0)
|
| 358 |
+
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 359 |
+
ct_end = self._sigma_to_t(sigmas[10], log_sigmas)
|
| 360 |
+
timesteps = self.get_sigmas_karras(7 + (1 if self.use_afs else 0) + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
| 361 |
elif N == 7:
|
| 362 |
log_sigmas = np.log(sigmas)
|
| 363 |
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 364 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 365 |
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 366 |
+
timesteps = self.get_sigmas_karras(7 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
|
|
|
|
|
|
| 367 |
elif N == 8:
|
| 368 |
log_sigmas = np.log(sigmas).copy()
|
| 369 |
sigmas = self.get_sigmas_karras(8, sigma_0, sigma_T, rho=5.0)
|
| 370 |
ct_start = self._sigma_to_t(sigmas[0], log_sigmas)
|
| 371 |
ct_end = self._sigma_to_t(sigmas[6], log_sigmas)
|
| 372 |
+
timesteps = self.get_sigmas_karras(8 + (1 if self.use_free_predictor else 0), ct_end, ct_start,rho=1.2)
|
|
|
|
|
|
|
| 373 |
|
| 374 |
if self.use_afs and N > 6:
|
| 375 |
timesteps = np.insert(timesteps,1,(timesteps[0]+timesteps[1]) / 2)
|
| 376 |
|
| 377 |
|
| 378 |
timesteps_tmp = copy.deepcopy(timesteps)
|
| 379 |
+
if not self.ultilize_vae:
|
| 380 |
+
timesteps_tmp = np.append(timesteps_tmp, self._sigma_to_t(sigmas[-1], log_sigmas))
|
| 381 |
sigmas = np.array([self._t_to_sigma(t, log_sigmas) for t in timesteps_tmp])
|
| 382 |
self.sigmas = torch.from_numpy(sigmas)
|
| 383 |
+
if not self.ultilize_vae:
|
| 384 |
+
self.timesteps = torch.from_numpy(timesteps).to(device=device)
|
| 385 |
+
else:
|
| 386 |
+
self.timesteps = torch.from_numpy(timesteps[:-1]).to(device=device)
|
| 387 |
|
| 388 |
self.num_inference_steps = len(timesteps)
|
| 389 |
|