From 675c2a529d4583f2ad7acfe14f00a810261eef5c Mon Sep 17 00:00:00 2001 From: lostdisc <194321775+lostdisc@users.noreply.github.com> Date: Thu, 13 Mar 2025 12:53:23 -0400 Subject: [PATCH 1/4] 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. --- .../stable_diffusion/pipeline_onnx_stable_diffusion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py index 9917276e0a1f..b61c61deb0ac 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py @@ -383,7 +383,7 @@ def __call__( # set timesteps self.scheduler.set_timesteps(num_inference_steps) - latents = latents * np.float64(self.scheduler.init_noise_sigma) + latents = latents * self.scheduler.init_noise_sigma # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature # eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers. From 16dba238e583bcd488554e8989a07d11e8a2bf8f Mon Sep 17 00:00:00 2001 From: lostdisc <194321775+lostdisc@users.noreply.github.com> Date: Thu, 13 Mar 2025 12:56:48 -0400 Subject: [PATCH 2/4] 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. --- .../stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py index ddd2e27dedaf..d8d1f49182ae 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_inpaint.py @@ -483,7 +483,7 @@ def __call__( self.scheduler.set_timesteps(num_inference_steps) # scale the initial noise by the standard deviation required by the scheduler - latents = latents * np.float64(self.scheduler.init_noise_sigma) + latents = latents * self.scheduler.init_noise_sigma # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature # eta (η) is only used with the DDIMScheduler, it will be ignored for other schedulers. From c8b9e2532a108400411035da745bd3ce7ee0dbdc Mon Sep 17 00:00:00 2001 From: lostdisc <194321775+lostdisc@users.noreply.github.com> Date: Thu, 13 Mar 2025 12:57:34 -0400 Subject: [PATCH 3/4] 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. --- .../stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py index ef84cdd38b6d..406489810dbd 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion_upscale.py @@ -481,7 +481,7 @@ def __call__( timesteps = self.scheduler.timesteps # Scale the initial noise by the standard deviation required by the scheduler - latents = latents * np.float64(self.scheduler.init_noise_sigma) + latents = latents * self.scheduler.init_noise_sigma # 5. Add noise to image noise_level = np.array([noise_level]).astype(np.int64) From 6689572a1e65fd682c1389551b65e7e3d289194a Mon Sep 17 00:00:00 2001 From: lostdisc <194321775+lostdisc@users.noreply.github.com> Date: Thu, 13 Mar 2025 13:18:33 -0400 Subject: [PATCH 4/4] 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. --- .../pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py index b61c61deb0ac..78f5490eaf24 100644 --- a/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py +++ b/src/diffusers/pipelines/stable_diffusion/pipeline_onnx_stable_diffusion.py @@ -383,6 +383,7 @@ def __call__( # set timesteps self.scheduler.set_timesteps(num_inference_steps) + # scale the initial noise by the standard deviation required by the scheduler latents = latents * self.scheduler.init_noise_sigma # prepare extra kwargs for the scheduler step, since not all schedulers have the same signature