Repository: huggingface/diffusers

Issue:
Could not run train_lcm_distill_sd_wds with multi-GPU setting
### Describe the bug

Got the following error while running the train_lcm_distill_sd_wds.py script:
`AttributeError: 'DistributedDataParallel' object has no attribute 'config'`
Occurs only when multi-gpu setting is used.

Changing the line at 1178 from:
`w_embedding = guidance_scale_embedding(w, embedding_dim=unet.config.time_cond_proj_dim)` to
`w_embedding = guidance_scale_embedding(w, embedding_dim=accelerator.unwrap_model(unet).config.time_cond_proj_dim)` solved the issue. 

Attaching the referred source: 
https://github.com/huggingface/diffusers/pull/3673

### Reproduction

Follow full model distillation at [tutorial](https://github.com/huggingface/diffusers/tree/main/examples/consistency_distillation#full-model-distillation). Use `multi-gpu` while configuring `accelerate`.

### Logs

_No response_

### System Info

- diffusers version: 0.25.0.dev0
- Platform: Linux-4.18.0-48-x86_64
- Python version: 3.10.13
- PyTorch version (GPU?): 2.0.1+cu117 (True)
- Huggingface_hub version: 0.19.4
- Transformers version: 4.36.1
- Accelerate version: 0.25.0  
- xFormers version: 0.0.22
- Using GPU in script?: YES
- Using distributed or parallel set-up in script?: YES

### Who can help?

@sayakpaul @patrickvonplaten 


Discussion:
I think I might have introduced this bug in #5893 when fixing the `unet_time_cond_proj_dim` bug. I can open up a PR to fix this.

Resolving patch:
diff --git a/examples/consistency_distillation/train_lcm_distill_sd_wds.py b/examples/consistency_distillation/train_lcm_distill_sd_wds.py
--- a/examples/consistency_distillation/train_lcm_distill_sd_wds.py
+++ b/examples/consistency_distillation/train_lcm_distill_sd_wds.py
@@ -889,6 +889,7 @@ def main(args):
     # Add `time_cond_proj_dim` to the student U-Net if `teacher_unet.config.time_cond_proj_dim` is None
     if teacher_unet.config.time_cond_proj_dim is None:
         teacher_unet.config["time_cond_proj_dim"] = args.unet_time_cond_proj_dim
+    time_cond_proj_dim = teacher_unet.config.time_cond_proj_dim
     unet = UNet2DConditionModel(**teacher_unet.config)
     # load teacher_unet weights into unet
     unet.load_state_dict(teacher_unet.state_dict(), strict=False)
@@ -1175,7 +1176,7 @@ def compute_embeddings(prompt_batch, proportion_empty_prompts, text_encoder, tok
 
                 # 5. Sample a random guidance scale w from U[w_min, w_max] and embed it
                 w = (args.w_max - args.w_min) * torch.rand((bsz,)) + args.w_min
-                w_embedding = guidance_scale_embedding(w, embedding_dim=unet.config.time_cond_proj_dim)
+                w_embedding = guidance_scale_embedding(w, embedding_dim=time_cond_proj_dim)
                 w = w.reshape(bsz, 1, 1, 1)
                 # Move to U-Net device and dtype
                 w = w.to(device=latents.device, dtype=latents.dtype)
diff --git a/examples/consistency_distillation/train_lcm_distill_sdxl_wds.py b/examples/consistency_distillation/train_lcm_distill_sdxl_wds.py
--- a/examples/consistency_distillation/train_lcm_distill_sdxl_wds.py
+++ b/examples/consistency_distillation/train_lcm_distill_sdxl_wds.py
@@ -948,6 +948,7 @@ def main(args):
     # Add `time_cond_proj_dim` to the student U-Net if `teacher_unet.config.time_cond_proj_dim` is None
     if teacher_unet.config.time_cond_proj_dim is None:
         teacher_unet.config["time_cond_proj_dim"] = args.unet_time_cond_proj_dim
+    time_cond_proj_dim = teacher_unet.config.time_cond_proj_dim
     unet = UNet2DConditionModel(**teacher_unet.config)
     # load teacher_unet weights into unet
     unet.load_state_dict(teacher_unet.state_dict(), strict=False)
@@ -1273,7 +1274,7 @@ def compute_embeddings(
 
                 # 5. Sample a random guidance scale w from U[w_min, w_max] and embed it
                 w = (args.w_max - args.w_min) * torch.rand((bsz,)) + args.w_min
-                w_embedding = guidance_scale_embedding(w, embedding_dim=unet.config.time_cond_proj_dim)
+                w_embedding = guidance_scale_embedding(w, embedding_dim=time_cond_proj_dim)
                 w = w.reshape(bsz, 1, 1, 1)
                 # Move to U-Net device and dtype
                 w = w.to(device=latents.device, dtype=latents.dtype)


Test patch: