Skip to content

Commit 7b53e97

Browse files
committed
use np.int32 in scheduling
1 parent edb8c1b commit 7b53e97

18 files changed

+58
-58
lines changed

src/diffusers/schedulers/scheduling_consistency_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def set_timesteps(
207207
f" {self.config.num_train_timesteps}."
208208
)
209209

210-
timesteps = np.array(timesteps, dtype=np.int64)
210+
timesteps = np.array(timesteps, dtype=np.int32)
211211
self.custom_timesteps = True
212212
else:
213213
if num_inference_steps > self.config.num_train_timesteps:
@@ -220,7 +220,7 @@ def set_timesteps(
220220
self.num_inference_steps = num_inference_steps
221221

222222
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
223-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
223+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
224224
self.custom_timesteps = False
225225

226226
# Map timesteps to Karras sigmas directly for multistep sampling

src/diffusers/schedulers/scheduling_ddim.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def __init__(
231231

232232
# setable values
233233
self.num_inference_steps = None
234-
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int64))
234+
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int32))
235235

236236
def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor:
237237
"""
@@ -318,19 +318,19 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
318318
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
319319
.round()[::-1]
320320
.copy()
321-
.astype(np.int64)
321+
.astype(np.int32)
322322
)
323323
elif self.config.timestep_spacing == "leading":
324324
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
325325
# creates integer timesteps by multiplying by ratio
326326
# casting to int to avoid issues when num_inference_step is power of 3
327-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
327+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
328328
timesteps += self.config.steps_offset
329329
elif self.config.timestep_spacing == "trailing":
330330
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
331331
# creates integer timesteps by multiplying by ratio
332332
# casting to int to avoid issues when num_inference_step is power of 3
333-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
333+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
334334
timesteps -= 1
335335
else:
336336
raise ValueError(

src/diffusers/schedulers/scheduling_ddim_cogvideox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __init__(
228228

229229
# setable values
230230
self.num_inference_steps = None
231-
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int64))
231+
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int32))
232232

233233
def _get_variance(self, timestep, prev_timestep):
234234
alpha_prod_t = self.alphas_cumprod[timestep]
@@ -281,19 +281,19 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
281281
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
282282
.round()[::-1]
283283
.copy()
284-
.astype(np.int64)
284+
.astype(np.int32)
285285
)
286286
elif self.config.timestep_spacing == "leading":
287287
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
288288
# creates integer timesteps by multiplying by ratio
289289
# casting to int to avoid issues when num_inference_step is power of 3
290-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
290+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
291291
timesteps += self.config.steps_offset
292292
elif self.config.timestep_spacing == "trailing":
293293
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
294294
# creates integer timesteps by multiplying by ratio
295295
# casting to int to avoid issues when num_inference_step is power of 3
296-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
296+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
297297
timesteps -= 1
298298
else:
299299
raise ValueError(

src/diffusers/schedulers/scheduling_ddim_inverse.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __init__(
228228

229229
# setable values
230230
self.num_inference_steps = None
231-
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps).copy().astype(np.int64))
231+
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps).copy().astype(np.int32))
232232

233233
# Copied from diffusers.schedulers.scheduling_ddim.DDIMScheduler.scale_model_input
234234
def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor:
@@ -271,13 +271,13 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
271271
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
272272
# creates integer timesteps by multiplying by ratio
273273
# casting to int to avoid issues when num_inference_step is power of 3
274-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round().copy().astype(np.int64)
274+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round().copy().astype(np.int32)
275275
timesteps += self.config.steps_offset
276276
elif self.config.timestep_spacing == "trailing":
277277
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
278278
# creates integer timesteps by multiplying by ratio
279279
# casting to int to avoid issues when num_inference_step is power of 3
280-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)[::-1]).astype(np.int64)
280+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)[::-1]).astype(np.int32)
281281
timesteps -= 1
282282
else:
283283
raise ValueError(

src/diffusers/schedulers/scheduling_ddim_parallel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def __init__(
238238

239239
# setable values
240240
self.num_inference_steps = None
241-
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int64))
241+
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int32))
242242

243243
# Copied from diffusers.schedulers.scheduling_ddim.DDIMScheduler.scale_model_input
244244
def scale_model_input(self, sample: torch.Tensor, timestep: Optional[int] = None) -> torch.Tensor:
@@ -341,19 +341,19 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
341341
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
342342
.round()[::-1]
343343
.copy()
344-
.astype(np.int64)
344+
.astype(np.int32)
345345
)
346346
elif self.config.timestep_spacing == "leading":
347347
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
348348
# creates integer timesteps by multiplying by ratio
349349
# casting to int to avoid issues when num_inference_step is power of 3
350-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
350+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
351351
timesteps += self.config.steps_offset
352352
elif self.config.timestep_spacing == "trailing":
353353
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
354354
# creates integer timesteps by multiplying by ratio
355355
# casting to int to avoid issues when num_inference_step is power of 3
356-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
356+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
357357
timesteps -= 1
358358
else:
359359
raise ValueError(

src/diffusers/schedulers/scheduling_ddpm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def set_timesteps(
283283
f" {self.config.num_train_timesteps}."
284284
)
285285

286-
timesteps = np.array(timesteps, dtype=np.int64)
286+
timesteps = np.array(timesteps, dtype=np.int32)
287287
self.custom_timesteps = True
288288
else:
289289
if num_inference_steps > self.config.num_train_timesteps:
@@ -302,19 +302,19 @@ def set_timesteps(
302302
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
303303
.round()[::-1]
304304
.copy()
305-
.astype(np.int64)
305+
.astype(np.int32)
306306
)
307307
elif self.config.timestep_spacing == "leading":
308308
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
309309
# creates integer timesteps by multiplying by ratio
310310
# casting to int to avoid issues when num_inference_step is power of 3
311-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
311+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
312312
timesteps += self.config.steps_offset
313313
elif self.config.timestep_spacing == "trailing":
314314
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
315315
# creates integer timesteps by multiplying by ratio
316316
# casting to int to avoid issues when num_inference_step is power of 3
317-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
317+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
318318
timesteps -= 1
319319
else:
320320
raise ValueError(

src/diffusers/schedulers/scheduling_ddpm_parallel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def set_timesteps(
293293
f" {self.config.num_train_timesteps}."
294294
)
295295

296-
timesteps = np.array(timesteps, dtype=np.int64)
296+
timesteps = np.array(timesteps, dtype=np.int32)
297297
self.custom_timesteps = True
298298
else:
299299
if num_inference_steps > self.config.num_train_timesteps:
@@ -312,19 +312,19 @@ def set_timesteps(
312312
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
313313
.round()[::-1]
314314
.copy()
315-
.astype(np.int64)
315+
.astype(np.int32)
316316
)
317317
elif self.config.timestep_spacing == "leading":
318318
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
319319
# creates integer timesteps by multiplying by ratio
320320
# casting to int to avoid issues when num_inference_step is power of 3
321-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
321+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
322322
timesteps += self.config.steps_offset
323323
elif self.config.timestep_spacing == "trailing":
324324
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
325325
# creates integer timesteps by multiplying by ratio
326326
# casting to int to avoid issues when num_inference_step is power of 3
327-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
327+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
328328
timesteps -= 1
329329
else:
330330
raise ValueError(

src/diffusers/schedulers/scheduling_deis_multistep.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,19 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
248248
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps + 1)
249249
.round()[::-1][:-1]
250250
.copy()
251-
.astype(np.int64)
251+
.astype(np.int32)
252252
)
253253
elif self.config.timestep_spacing == "leading":
254254
step_ratio = self.config.num_train_timesteps // (num_inference_steps + 1)
255255
# creates integer timesteps by multiplying by ratio
256256
# casting to int to avoid issues when num_inference_step is power of 3
257-
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64)
257+
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int32)
258258
timesteps += self.config.steps_offset
259259
elif self.config.timestep_spacing == "trailing":
260260
step_ratio = self.config.num_train_timesteps / num_inference_steps
261261
# creates integer timesteps by multiplying by ratio
262262
# casting to int to avoid issues when num_inference_step is power of 3
263-
timesteps = np.arange(self.config.num_train_timesteps, 0, -step_ratio).round().copy().astype(np.int64)
263+
timesteps = np.arange(self.config.num_train_timesteps, 0, -step_ratio).round().copy().astype(np.int32)
264264
timesteps -= 1
265265
else:
266266
raise ValueError(

src/diffusers/schedulers/scheduling_dpm_cogvideox.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def __init__(
229229

230230
# setable values
231231
self.num_inference_steps = None
232-
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int64))
232+
self.timesteps = torch.from_numpy(np.arange(0, num_train_timesteps)[::-1].copy().astype(np.int32))
233233

234234
def _get_variance(self, timestep, prev_timestep):
235235
alpha_prod_t = self.alphas_cumprod[timestep]
@@ -282,19 +282,19 @@ def set_timesteps(self, num_inference_steps: int, device: Union[str, torch.devic
282282
np.linspace(0, self.config.num_train_timesteps - 1, num_inference_steps)
283283
.round()[::-1]
284284
.copy()
285-
.astype(np.int64)
285+
.astype(np.int32)
286286
)
287287
elif self.config.timestep_spacing == "leading":
288288
step_ratio = self.config.num_train_timesteps // self.num_inference_steps
289289
# creates integer timesteps by multiplying by ratio
290290
# casting to int to avoid issues when num_inference_step is power of 3
291-
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int64)
291+
timesteps = (np.arange(0, num_inference_steps) * step_ratio).round()[::-1].copy().astype(np.int32)
292292
timesteps += self.config.steps_offset
293293
elif self.config.timestep_spacing == "trailing":
294294
step_ratio = self.config.num_train_timesteps / self.num_inference_steps
295295
# creates integer timesteps by multiplying by ratio
296296
# casting to int to avoid issues when num_inference_step is power of 3
297-
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int64)
297+
timesteps = np.round(np.arange(self.config.num_train_timesteps, 0, -step_ratio)).astype(np.int32)
298298
timesteps -= 1
299299
else:
300300
raise ValueError(

src/diffusers/schedulers/scheduling_dpmsolver_multistep.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def set_timesteps(
359359
raise ValueError("Cannot set `timesteps` with `config.use_beta_sigmas = True`.")
360360

361361
if timesteps is not None:
362-
timesteps = np.array(timesteps).astype(np.int64)
362+
timesteps = np.array(timesteps).astype(np.int32)
363363
else:
364364
# Clipping the minimum of all lambda(t) for numerical stability.
365365
# This is critical for cosine (squaredcos_cap_v2) noise schedule.
@@ -372,21 +372,21 @@ def set_timesteps(
372372
np.linspace(0, last_timestep - 1, num_inference_steps + 1)
373373
.round()[::-1][:-1]
374374
.copy()
375-
.astype(np.int64)
375+
.astype(np.int32)
376376
)
377377
elif self.config.timestep_spacing == "leading":
378378
step_ratio = last_timestep // (num_inference_steps + 1)
379379
# creates integer timesteps by multiplying by ratio
380380
# casting to int to avoid issues when num_inference_step is power of 3
381381
timesteps = (
382-
(np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int64)
382+
(np.arange(0, num_inference_steps + 1) * step_ratio).round()[::-1][:-1].copy().astype(np.int32)
383383
)
384384
timesteps += self.config.steps_offset
385385
elif self.config.timestep_spacing == "trailing":
386386
step_ratio = self.config.num_train_timesteps / num_inference_steps
387387
# creates integer timesteps by multiplying by ratio
388388
# casting to int to avoid issues when num_inference_step is power of 3
389-
timesteps = np.arange(last_timestep, 0, -step_ratio).round().copy().astype(np.int64)
389+
timesteps = np.arange(last_timestep, 0, -step_ratio).round().copy().astype(np.int32)
390390
timesteps -= 1
391391
else:
392392
raise ValueError(

src/diffusers/schedulers/scheduling_dpmsolver_multistep_inverse.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,19 +260,19 @@ def set_timesteps(self, num_inference_steps: int = None, device: Union[str, torc
260260
# "linspace", "leading", "trailing" corresponds to annotation of Table 2. of https://arxiv.org/abs/2305.08891
261261
if self.config.timestep_spacing == "linspace":
262262
timesteps = (
263-
np.linspace(0, self.noisiest_timestep, num_inference_steps + 1).round()[:-1].copy().astype(np.int64)
263+
np.linspace(0, self.noisiest_timestep, num_inference_steps + 1).round()[:-1].copy().astype(np.int32)
264264
)
265265
elif self.config.timestep_spacing == "leading":
266266
step_ratio = (self.noisiest_timestep + 1) // (num_inference_steps + 1)
267267
# creates integer timesteps by multiplying by ratio
268268
# casting to int to avoid issues when num_inference_step is power of 3
269-
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[:-1].copy().astype(np.int64)
269+
timesteps = (np.arange(0, num_inference_steps + 1) * step_ratio).round()[:-1].copy().astype(np.int32)
270270
timesteps += self.config.steps_offset
271271
elif self.config.timestep_spacing == "trailing":
272272
step_ratio = self.config.num_train_timesteps / num_inference_steps
273273
# creates integer timesteps by multiplying by ratio
274274
# casting to int to avoid issues when num_inference_step is power of 3
275-
timesteps = np.arange(self.noisiest_timestep + 1, 0, -step_ratio).round()[::-1].copy().astype(np.int64)
275+
timesteps = np.arange(self.noisiest_timestep + 1, 0, -step_ratio).round()[::-1].copy().astype(np.int32)
276276
timesteps -= 1
277277
else:
278278
raise ValueError(
@@ -286,7 +286,7 @@ def set_timesteps(self, num_inference_steps: int = None, device: Union[str, torc
286286
if self.config.use_karras_sigmas:
287287
sigmas = self._convert_to_karras(in_sigmas=sigmas, num_inference_steps=num_inference_steps)
288288
timesteps = np.array([self._sigma_to_t(sigma, log_sigmas) for sigma in sigmas]).round()
289-
timesteps = timesteps.copy().astype(np.int64)
289+
timesteps = timesteps.copy().astype(np.int32)
290290
sigmas = np.concatenate([sigmas, sigmas[-1:]]).astype(np.float32)
291291
elif self.config.use_exponential_sigmas:
292292
sigmas = self._convert_to_exponential(in_sigmas=sigmas, num_inference_steps=num_inference_steps)

0 commit comments

Comments
 (0)