Repository: huggingface/diffusers

Issue:
Graph compile breaks due to logging.info
### Describe the bug

When building a unet via `torch.compile(pipeline.unet)`, I receive an error.

### Reproduction

1. Load SD 2.1 `ptx0/pseudo-flex-base`
2. Compile the unet
3. See that the error prevents continuance
4. Remove the logging.info line from the module
5. Compile works.

### Logs

```shell
in skipfiles: Logger.info  | info /usr/lib/python3.9/logging/__init__.py

from user code:
   File "/notebooks/container/discord-tron-client/.venv/lib/python3.9/site-packages/diffusers/models/unet_2d_condition.py", line 730, in forward
    logger.info("Forward upsample size to force interpolation output size.")

Set torch._dynamo.config.verbose=True for more information
```


### System Info

sd_xl diffusers branch.

- `diffusers` version: 0.18.0.dev0
- Python version: 3.9.16
- PyTorch version (GPU?): 2.0.1+cu117 (True)
- Huggingface_hub version: 0.14.1
- Transformers version: 4.30.2
- Accelerate version: 0.18.0
- xFormers version: 0.0.20.dev526

### Who can help?

@patrickvonplaten 


Discussion:
Hey @bghira,

I can't really reproduce the error. The following works for me on `torch==2.0.1`:

```py
from diffusers import StableDiffusionPipeline
import torch

path = "ptx0/pseudo-flex-base"

pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
pipe.unet = torch.compile(pipe.unet)

pipe = pipe.to("cuda")

prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"

generator = torch.Generator(device="cpu").manual_seed(0)
images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=4, num_inference_steps=25).images
```
```
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
```

is the actual method i called, i'm sorry. it's from the SDXL model card page. i will look again, since now i have everything working otherwise.
seems to be some issue unrelated to this part, possibly when i was messing with text embeds
I was able successfully call torch.compile but I am now getting this error as well. Not sure why. I'm using torch nightly and cuda 12.2 fwiw.
yes, this has been an ongoing issue. i simply delete all of the logging calls upon startup now.
> yes, this has been an ongoing issue. i simply delete all of the logging calls upon startup now.

how are you deleting the logging calls?
```bash
PYTHONVERS="3.9"
sed -i '/logger\.info/d' venv/lib/python${PYTHONVERS}/site-packages/diffusers/models/unet_2d_condition.py
```
Very curious to know what happens here, is there any chance you can reproduce this error in a google colab or post a complete code snippet here? Would really like to try to fix this
typically no, it comes and goes, but deleting the log line resolves it perpetually
Is it also possible with 'StableDiffusionControlNetImg2ImgPipeline'?
@patrickvonplaten 
The same problem
I also have this error:
```
Unsupported
call_function UserDefinedClassVariable() [] {'sample': TensorVariable()}

from user code:
   File "/usr/local/lib/python3.10/dist-packages/diffusers/models/unet_2d_condition.py", line 1007, in forward
    return UNet2DConditionOutput(sample=sample)


You can suppress this exception and fall back to eager by setting:
    import torch._dynamo
    torch._dynamo.config.suppress_errors = True
```
@patrickvonplaten can i ask what is the value of having this log line? is it a bad thing happening? it offers no explanation, but my understanding after looking at the source is that a latent size not in multiples of 8 or 64 will have different behaviour than one that does not. is this a debug statement that merely serves to inform? or is it a warning condition where the user should know they are harming some aspect of the process?
Yeah I get your point here! I'd be ok with removing the logging statement - especially since it pops up every time one runs the forward pass. Should we remove it and just replace it with a comment in the code? Would you like to open a PR for this maybe @bghira ? 
it only pops up when running the forward pass if the image is a weird dimension, it doesn't happen with eg. 128x128 latent inputs. i can open a PR for that

Resolving patch:
diff --git a/src/diffusers/models/unet_2d_condition.py b/src/diffusers/models/unet_2d_condition.py
--- a/src/diffusers/models/unet_2d_condition.py
+++ b/src/diffusers/models/unet_2d_condition.py
@@ -784,7 +784,7 @@ def forward(
         upsample_size = None
 
         if any(s % default_overall_up_factor != 0 for s in sample.shape[-2:]):
-            logger.info("Forward upsample size to force interpolation output size.")
+            # Forward upsample size to force interpolation output size.
             forward_upsample_size = True
 
         # ensure attention_mask is a bias, and give it a singleton query_tokens dimension


Test patch: