Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

train_text_to_image_sdxl.py ema not working #5783

Closed
Jack000 opened this issue Nov 13, 2023 · 9 comments · Fixed by #7048
Closed

train_text_to_image_sdxl.py ema not working #5783

Jack000 opened this issue Nov 13, 2023 · 9 comments · Fixed by #7048
Labels
bug Something isn't working

Comments

@Jack000
Copy link

Jack000 commented Nov 13, 2023

Describe the bug

I did a few training runs with train_text_to_image_sdxl.py before realizing that the EMA checkpoint never changed.

Looking at train_text_to_image.py - it seems that there is no ema_unet.step() in the sdxl training code so the ema model is never updated.

it's also missing this bit at the start:

if args.use_ema:
    ema_unet.to(accelerator.device)

Reproduction

just the huggingface sample code

Logs

No response

System Info

latest version of diffusers

Who can help?

No response

@Jack000 Jack000 added the bug Something isn't working label Nov 13, 2023
@linnanwang
Copy link

I felt the same issue here.

@patrickvonplaten
Copy link
Contributor

Can you please add a reproducible code snippet?

@Jack000
Copy link
Author

Jack000 commented Nov 15, 2023

I guess just the sample code, but with --use_ema turned on
from https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/README_sdxl.md

export MODEL_NAME="stabilityai/stable-diffusion-xl-base-1.0"
export VAE_NAME="madebyollin/sdxl-vae-fp16-fix"
export DATASET_NAME="lambdalabs/pokemon-blip-captions"

accelerate launch train_text_to_image_sdxl.py \
  --pretrained_model_name_or_path=$MODEL_NAME \
  --pretrained_vae_model_name_or_path=$VAE_NAME \
  --dataset_name=$DATASET_NAME \
  --enable_xformers_memory_efficient_attention \
  --resolution=512 --center_crop --random_flip \
  --proportion_empty_prompts=0.2 \
  --train_batch_size=1 \
  --gradient_accumulation_steps=4 --gradient_checkpointing \
  --max_train_steps=10000 \
  --use_8bit_adam \
  --learning_rate=1e-06 --lr_scheduler="constant" --lr_warmup_steps=0 \
  --mixed_precision="fp16" \
  --report_to="wandb" \
  --validation_prompt="a cute Sundar Pichai creature" --validation_epochs 5 \
  --checkpointing_steps=5000 \
  --output_dir="sdxl-pokemon-model" \
  --use_ema

this will error out with "RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!"

because it's missing

if args.use_ema:
    ema_unet.to(accelerator.device)

@yiyixuxu
Copy link
Collaborator

hi @Jack000:
are you interested in open a PR?

Copy link

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.

@github-actions github-actions bot added the stale Issues that haven't received updates label Dec 26, 2023
@sayakpaul
Copy link
Member

So sorry for the delay here. Apologies. Could you please submit a PR fixing the issue? Looks like you have already found the bug.

Copy link

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.

@sayakpaul
Copy link
Member

Gentle bump :-)

@tolgacangoz
Copy link
Contributor

tolgacangoz commented Feb 21, 2024

Since nobody has done that for a while; I tried.

@yiyixuxu yiyixuxu removed the stale Issues that haven't received updates label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants