Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions generative/networks/schedulers/ddim.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ def __init__(
# standard deviation of the initial noise distribution
self.init_noise_sigma = 1.0

# setable values
self.num_inference_steps = None

self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].astype(np.int64))

self.clip_sample = clip_sample
self.steps_offset = steps_offset

# default the number of inference timesteps to the number of train steps
self.set_timesteps(num_train_timesteps)

def set_timesteps(self, num_inference_steps: int, device: str | torch.device | None = None) -> None:
"""
Sets the discrete timesteps used for the diffusion chain. Supporting function to be run before inference.
Expand Down
8 changes: 3 additions & 5 deletions generative/networks/schedulers/pndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,11 @@ def __init__(
self.cur_sample = None
self.ets = []

# settable values
self.num_inference_steps = None

self._timesteps = np.arange(0, num_train_timesteps)[::-1].copy()
self.prk_timesteps = torch.Tensor([])
self.plms_timesteps = torch.Tensor([])
self.timesteps = torch.Tensor([])

# default the number of inference timesteps to the number of train steps
self.set_timesteps(num_train_timesteps)
def set_timesteps(self, num_inference_steps: int, device: str | torch.device | None = None) -> None:
"""
Sets the discrete timesteps used for the diffusion chain. Supporting function to be run before inference.
Expand Down
7 changes: 0 additions & 7 deletions tests/test_scheduler_pndm.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ def test_add_noise_2d_shape(self, input_param, input_shape, expected_shape):
noisy = scheduler.add_noise(original_samples=original_sample, noise=noise, timesteps=timesteps)
self.assertEqual(noisy.shape, expected_shape)

@parameterized.expand(TEST_CASES)
def test_error_if_timesteps_not_set(self, input_param, input_shape, expected_shape):
scheduler = PNDMScheduler(**input_param)
with self.assertRaises(ValueError):
model_output = torch.randn(input_shape)
sample = torch.randn(input_shape)
scheduler.step(model_output=model_output, timestep=500, sample=sample)

@parameterized.expand(TEST_CASES)
def test_step_shape(self, input_param, input_shape, expected_shape):
Expand Down