Skip to content

Commit fe4d2ad

Browse files
lostdiscyiyixuxu
authored andcommitted
Remove forced float64 from onnx stable diffusion pipelines (huggingface#11054)
* Update pipeline_onnx_stable_diffusion.py to remove float64 init_noise_sigma was being set as float64 before multiplying with latents, which changed latents into float64 too, which caused errors with onnxruntime since the latter wanted float16. * Update pipeline_onnx_stable_diffusion_inpaint.py to remove float64 init_noise_sigma was being set as float64 before multiplying with latents, which changed latents into float64 too, which caused errors with onnxruntime since the latter wanted float16. * Update pipeline_onnx_stable_diffusion_upscale.py to remove float64 init_noise_sigma was being set as float64 before multiplying with latents, which changed latents into float64 too, which caused errors with onnxruntime since the latter wanted float16. * Update pipeline_onnx_stable_diffusion.py with comment for previous commit Added comment on purpose of init_noise_sigma. This comment exists in related scripts that use the same line of code, but it was missing here. --------- Co-authored-by: YiYi Xu <[email protected]>
1 parent 015c64d commit fe4d2ad

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ def __call__(
383383
# set timesteps
384384
self.scheduler.set_timesteps(num_inference_steps)
385385

386-
latents = latents * np.float64(self.scheduler.init_noise_sigma)
386+
# scale the initial noise by the standard deviation required by the scheduler
387+
latents = latents * self.scheduler.init_noise_sigma
387388

388389
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
389390
# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def __call__(
483483
self.scheduler.set_timesteps(num_inference_steps)
484484

485485
# scale the initial noise by the standard deviation required by the scheduler
486-
latents = latents * np.float64(self.scheduler.init_noise_sigma)
486+
latents = latents * self.scheduler.init_noise_sigma
487487

488488
# prepare extra kwargs for the scheduler step, since not all schedulers have the same signature
489489
# eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers.

src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def __call__(
481481
timesteps = self.scheduler.timesteps
482482

483483
# Scale the initial noise by the standard deviation required by the scheduler
484-
latents = latents * np.float64(self.scheduler.init_noise_sigma)
484+
latents = latents * self.scheduler.init_noise_sigma
485485

486486
# 5. Add noise to image
487487
noise_level = np.array([noise_level]).astype(np.int64)

0 commit comments

Comments
 (0)