Skip to content

Commit

Permalink
Response to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marksgraham committed Jan 4, 2024
1 parent c52c06a commit dfde26c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions monai/networks/schedulers/ddim.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,9 @@
from monai.utils import StrEnum

from .scheduler import Scheduler
from .ddpm import DDPMPredictionType


class DDIMPredictionType(StrEnum):
"""
Set of valid prediction type names for the DDIM scheduler's `prediction_type` argument.
epsilon: predicting the noise of the diffusion process
sample: directly predicting the noisy sample
v_prediction: velocity prediction, see section 2.4 https://imagen.research.google/video/paper.pdf
"""

EPSILON = "epsilon"
SAMPLE = "sample"
V_PREDICTION = "v_prediction"
DDIMPredictionType = DDPMPredictionType


class DDIMScheduler(Scheduler):
Expand Down Expand Up @@ -126,6 +115,13 @@ def set_timesteps(self, num_inference_steps: int, device: str | torch.device | N

self.num_inference_steps = num_inference_steps
step_ratio = self.num_train_timesteps // self.num_inference_steps
if self.steps_offset >= step_ratio:
raise ValueError(
f"`steps_offset`: {self.steps_offset} cannot be greater than or equal to "
f"`num_train_timesteps // num_inference_steps : {step_ratio}` as this will cause timesteps to exceed"
f" the max train timestep."
)

# creates integer timesteps by multiplying by ratio
# casting to int to avoid issues when num_inference_step is power of 3
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
Expand Down Expand Up @@ -159,7 +155,6 @@ def step(
timestep: current discrete timestep in the diffusion chain.
sample: current instance of sample being created by diffusion process.
eta: weight of noise for added noise in diffusion step.
predict_epsilon: flag to use when model predicts the samples directly instead of the noise, epsilon.
generator: random number generator.
Returns:
Expand Down

0 comments on commit dfde26c

Please sign in to comment.