Closed asfiyab-nvidia closed 1 month ago
@sayakpaul @DN6 @yiyixuxu can you please help investigate?
Cc: @muellerzr
@muellerzr is this a known issue? Please link if there's another bug tracking it
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.
Please note that issues that do not follow the contributing guidelines are likely to be ignored.
Can you try updating to the nightly torch and try again?
Thanks! Works with the latest version of PyTorch. Closing
The accelerate package wasn't installed when I closed the issue. Can we please re-open? I'm noticing the same error with the following versions of relevant packages
torch 2.6.0.dev20240917+cu124
diffusers 0.30.3
accelerate 0.34.2
Was able to get rid of it with the simple patch:
diff --git a/src/diffusers/utils/accelerate_utils.py b/src/diffusers/utils/accelerate_utils.py
index 99a8b3a47..cc14070d2 100644
--- a/src/diffusers/utils/accelerate_utils.py
+++ b/src/diffusers/utils/accelerate_utils.py
@@ -17,12 +17,15 @@ Accelerate utilities: Utilities related to accelerate
from packaging import version
-from .import_utils import is_accelerate_available
+from .import_utils import is_accelerate_available, is_torch_available
if is_accelerate_available():
import accelerate
+if is_torch_available():
+ import torch
+
def apply_forward_hook(method):
"""
@@ -33,7 +36,8 @@ def apply_forward_hook(method):
This decorator looks inside the internal `_hf_hook` property to find a registered offload hook.
:param method: The method to decorate. This method should be a method of a PyTorch module.
- """
+ """
+
if not is_accelerate_available():
return method
accelerate_version = version.parse(accelerate.__version__).base_version
@yiyixuxu if okay with you, I can open a PR. The error can be reproduced:
import torch
from diffusers.models import AutoencoderKL
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
model = AutoencoderKL.from_pretrained(model_id, subfolder="vae", use_safetensors=True).to("cuda")
model.decode = torch.compile(model.decode, mode="reduce-overhead", dynamic=False, fullgraph=False)
latents = torch.randn(1, 4, 64, 64, device="cuda", dtype=torch.float32)
print(latents.shape)
image = model.decode(latents)
Only happens (or that is so we know) when a user compiles the decode()
function.
so this would work I had no idea and would be very interesting to know why the torch not found error, but unfortunately don't have time at the moment to investigate since it is not something broken
import torch
from diffusers.models import AutoencoderKL
model_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
model = AutoencoderKL.from_pretrained(model_id, subfolder="vae", use_safetensors=True).to("cuda")
model.decode = torch.compile(model.decode, mode="reduce-overhead", dynamic=False, fullgraph=False)
latents = torch.randn(1, 4, 64, 64, device="cuda", dtype=torch.float32)
print(latents.shape)
- image = model.decode(latents)
+ image = model.decode(latents, return_dict=False)[0]
print(image.shape)
Thanks @yiyixuxu . Applying the WAR you suggested is good for my use case!
Describe the bug
I'd like to run the runwayml/stable-diffusion-v1-5 pipeline using Torch Compile in the reduce-overhead mode. However, the optimized VAE decoder model complains that Torch is not found. I've attached a script to reproduce the error in the logs.
An initial debugging on my end revealed that the issue was caused by the
accelerate
package. The snippet runs error-free upon uninstallingaccelerate
.Reproduction
Logs