Skip to content

Commit 1ac79fe

Browse files
committed
Style
1 parent a9ccade commit 1ac79fe

10 files changed

+35
-53
lines changed

src/diffusers/configuration_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ def extract_init_dict(cls, config_dict, **kwargs):
508508
hidden_config_dict = {k: v for k, v in original_dict.items() if k not in init_dict}
509509

510510
# 8. Take note of the parameters that were not present in the loaded config
511-
hidden_config_dict["_use_default_values"] = expected_keys - set(init_dict)
511+
hidden_config_dict["_use_default_values"] = expected_keys - set(init_dict)
512512

513513
return init_dict, unused_kwargs, hidden_config_dict
514514

src/diffusers/schedulers/scheduling_ddim.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,12 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
304304

305305
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
306306
if self.config.timestep_spacing == "linspace":
307-
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps).round()[
308-
::-1
309-
].copy().astype(np.int64)
307+
timesteps = (
308+
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
309+
.round()[::-1]
310+
.copy()
311+
.astype(np.int64)
312+
)
310313
elif self.config.timestep_spacing == "leading":
311314
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
312315
# creates integer timesteps by multiplying by ratio

src/diffusers/schedulers/scheduling_ddpm.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,12 @@ def set_timesteps(
241241

242242
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
243243
if self.config.timestep_spacing == "linspace":
244-
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps).round()[
245-
::-1
246-
].copy().astype(np.int64)
244+
timesteps = (
245+
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
246+
.round()[::-1]
247+
.copy()
248+
.astype(np.int64)
249+
)
247250
elif self.config.timestep_spacing == "leading":
248251
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
249252
# creates integer timesteps by multiplying by ratio
@@ -261,7 +264,6 @@ def set_timesteps(
261264
f"{self.config.timestep_spacing} is not supported. Please make sure to choose one of 'linspace', 'leading' or 'trailing'."
262265
)
263266

264-
265267
self.timesteps = torch.from_numpy(timesteps).to(device)
266268

267269
def _get_variance(self, t, predicted_variance=None, variance_type=None):

src/diffusers/schedulers/scheduling_deis_multistep.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,13 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
201201
step_ratio = self.config.num_train_timesteps // (num_inference_steps + 1)
202202
# creates integer timesteps by multiplying by ratio
203203
# casting to int to avoid issues when num_inference_step is power of 3
204-
timesteps = (
205-
(np.arange(0, num_inference_steps + 1) * step_ratio)
206-
.round()[::-1][:-1]
207-
.copy()
208-
.astype(np.int64)
209-
)
204+
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64)
210205
timesteps += self.config.steps_offset
211206
elif self.config.timestep_spacing == "trailing":
212207
step_ratio = self.config.num_train_timesteps / num_inference_steps
213208
# creates integer timesteps by multiplying by ratio
214209
# casting to int to avoid issues when num_inference_step is power of 3
215-
timesteps = (
216-
np.arange(self.config.num_train_timesteps, 0, -step_ratio)
217-
.round()
218-
.copy()
219-
.astype(np.int64)
220-
)
210+
timesteps = np.arange(self.config.num_train_timesteps, 0, -step_ratio).round().copy().astype(np.int64)
221211
timesteps -= 1
222212
else:
223213
raise ValueError(

src/diffusers/schedulers/scheduling_dpmsolver_multistep.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,32 +232,19 @@ def set_timesteps(self, num_inference_steps: int = None, device: Union[str, torc
232232
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
233233
if self.config.timestep_spacing == "linspace":
234234
timesteps = (
235-
np.linspace(0, last_timestep - 1, num_inference_steps + 1)
236-
.round()[::-1][:-1]
237-
.copy()
238-
.astype(np.int64)
235+
np.linspace(0, last_timestep - 1, num_inference_steps + 1).round()[::-1][:-1].copy().astype(np.int64)
239236
)
240237
elif self.config.timestep_spacing == "leading":
241238
step_ratio = last_timestep // (num_inference_steps + 1)
242239
# creates integer timesteps by multiplying by ratio
243240
# casting to int to avoid issues when num_inference_step is power of 3
244-
timesteps = (
245-
(np.arange(0, num_inference_steps + 1) * step_ratio)
246-
.round()[::-1][:-1]
247-
.copy()
248-
.astype(np.int64)
249-
)
241+
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64)
250242
timesteps += self.config.steps_offset
251243
elif self.config.timestep_spacing == "trailing":
252244
step_ratio = self.config.num_train_timesteps / num_inference_steps
253245
# creates integer timesteps by multiplying by ratio
254246
# casting to int to avoid issues when num_inference_step is power of 3
255-
timesteps = (
256-
np.arange(last_timestep, 0, -step_ratio)
257-
.round()
258-
.copy()
259-
.astype(np.int64)
260-
)
247+
timesteps = np.arange(last_timestep, 0, -step_ratio).round().copy().astype(np.int64)
261248
timesteps -= 1
262249
else:
263250
raise ValueError(

src/diffusers/schedulers/scheduling_euler_ancestral_discrete.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
194194

195195
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
196196
if self.config.timestep_spacing == "linspace":
197-
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[::-1].copy()
197+
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[
198+
::-1
199+
].copy()
198200
elif self.config.timestep_spacing == "leading":
199201
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
200202
# creates integer timesteps by multiplying by ratio

src/diffusers/schedulers/scheduling_euler_discrete.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
207207

208208
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
209209
if self.config.timestep_spacing == "linspace":
210-
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[::-1].copy()
210+
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[
211+
::-1
212+
].copy()
211213
elif self.config.timestep_spacing == "leading":
212214
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
213215
# creates integer timesteps by multiplying by ratio

src/diffusers/schedulers/scheduling_lms_discrete.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
221221

222222
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
223223
if self.config.timestep_spacing == "linspace":
224-
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[::-1].copy()
224+
timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps, dtype=float)[
225+
::-1
226+
].copy()
225227
elif self.config.timestep_spacing == "leading":
226228
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
227229
# creates integer timesteps by multiplying by ratio

src/diffusers/schedulers/scheduling_pndm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
164164
self.num_inference_steps = num_inference_steps
165165
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
166166
if self.config.timestep_spacing == "linspace":
167-
self._timesteps = np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps).round().astype(np.int64)
167+
self._timesteps = (
168+
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps).round().astype(np.int64)
169+
)
168170
elif self.config.timestep_spacing == "leading":
169171
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
170172
# creates integer timesteps by multiplying by ratio
@@ -175,7 +177,9 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
175177
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
176178
# creates integer timesteps by multiplying by ratio
177179
# casting to int to avoid issues when num_inference_step is power of 3
178-
self._timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio))[::-1].astype(np.int64)
180+
self._timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio))[::-1].astype(
181+
np.int64
182+
)
179183
self._timesteps -= 1
180184
else:
181185
raise ValueError(

src/diffusers/schedulers/scheduling_unipc_multistep.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,13 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
222222
step_ratio = self.config.num_train_timesteps // (num_inference_steps + 1)
223223
# creates integer timesteps by multiplying by ratio
224224
# casting to int to avoid issues when num_inference_step is power of 3
225-
timesteps = (
226-
(np.arange(0, num_inference_steps + 1) * step_ratio)
227-
.round()[::-1][:-1]
228-
.copy()
229-
.astype(np.int64)
230-
)
225+
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64)
231226
timesteps += self.config.steps_offset
232227
elif self.config.timestep_spacing == "trailing":
233228
step_ratio = self.config.num_train_timesteps / num_inference_steps
234229
# creates integer timesteps by multiplying by ratio
235230
# casting to int to avoid issues when num_inference_step is power of 3
236-
timesteps = (
237-
np.arange(self.config.num_train_timesteps, 0, -step_ratio)
238-
.round()
239-
.copy()
240-
.astype(np.int64)
241-
)
231+
timesteps = np.arange(self.config.num_train_timesteps, 0, -step_ratio).round().copy().astype(np.int64)
242232
timesteps -= 1
243233
else:
244234
raise ValueError(

0 commit comments

Comments
 (0)