-
Notifications
You must be signed in to change notification settings - Fork 6.1k
[Type hint] PNDM schedulers #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
7d1f48f
58f6b95
71a373c
de51dcb
e9c24d5
50a6d74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -15,7 +15,7 @@ | |||||
# DISCLAIMER: This file is strongly influenced by https://github.com/ermongroup/ddim | ||||||
|
||||||
import math | ||||||
from typing import Union | ||||||
from typing import Optional, Union | ||||||
|
||||||
import numpy as np | ||||||
import torch | ||||||
|
@@ -51,12 +51,12 @@ class PNDMScheduler(SchedulerMixin, ConfigMixin): | |||||
@register_to_config | ||||||
def __init__( | ||||||
self, | ||||||
num_train_timesteps=1000, | ||||||
beta_start=0.0001, | ||||||
beta_end=0.02, | ||||||
beta_schedule="linear", | ||||||
tensor_format="pt", | ||||||
skip_prk_steps=False, | ||||||
num_train_timesteps: int = 1000, | ||||||
beta_start: float = 0.0001, | ||||||
beta_end: float = 0.02, | ||||||
beta_schedule: Optional[str] = "linear", | ||||||
tensor_format: Optional[str] = "pt", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think the |
||||||
skip_prk_steps: bool = False, | ||||||
): | ||||||
|
||||||
if beta_schedule == "linear": | ||||||
|
@@ -97,7 +97,7 @@ def __init__( | |||||
self.tensor_format = tensor_format | ||||||
self.set_format(tensor_format=tensor_format) | ||||||
|
||||||
def set_timesteps(self, num_inference_steps, offset=0): | ||||||
def set_timesteps(self, num_inference_steps: int, offset=0): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
self.num_inference_steps = num_inference_steps | ||||||
self._timesteps = list( | ||||||
range(0, self.config.num_train_timesteps, self.config.num_train_timesteps // num_inference_steps) | ||||||
|
@@ -264,7 +264,12 @@ def _get_prev_sample(self, sample, timestep, timestep_prev, model_output): | |||||
|
||||||
return prev_sample | ||||||
|
||||||
def add_noise(self, original_samples, noise, timesteps): | ||||||
def add_noise( | ||||||
self, | ||||||
original_samples: Union[torch.FloatTensor, np.ndarray], | ||||||
noise: Union[torch.FloatTensor, np.ndarray], | ||||||
timesteps: Union[torch.IntTensor, np.ndarray], | ||||||
): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sqrt_alpha_prod = self.alphas_cumprod[timesteps] ** 0.5 | ||||||
sqrt_alpha_prod = self.match_shape(sqrt_alpha_prod, original_samples) | ||||||
sqrt_one_minus_alpha_prod = (1 - self.alphas_cumprod[timesteps]) ** 0.5 | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beta_schedule
has to be string I think :-)