Repository: huggingface/diffusers
Pull request: Remove logger.info statement from Unet2DCondition code to ensure torch compile reliably succeeds
# What does this PR do?

Fixes #3933 

Problem statement:
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

Hints from issue 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

Commit message: Convert logging statement to a comment for future archaeologists

Patch to review:
diff --git a/src/diffusers/models/unet_2d_condition.py b/src/diffusers/models/unet_2d_condition.py
index d695d182fa37..0a362406f2a2 100644
--- 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


Code review comments:
diff_hunk: @@ -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."""
path: src/diffusers/models/unet_2d_condition.py
text: @user1:
```suggestion
            # Forward upsample size to force interpolation output size.
```