ShivamShrirao / diffusers

๐Ÿค— Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch
https://huggingface.co/docs/diffusers
Apache License 2.0
1.89k stars 509 forks source link

Dreambooth enabling xformers and set_grads_to_none raises unrecognized arguments error #235

Open wjx008 opened 1 year ago

wjx008 commented 1 year ago

Describe the bug

using the train_dreambooth.py script, when I add flags for enabling xformers and set_grads_to_none, the following error happened: train_dreambooth.py: error: unrecognized arguments: --enable_xformers_memory_efficient_attention --set_grads_to_none

Reproduction

Followed the instructions in [https://github.com/ShivamShrirao/diffusers/tree/main/examples/dreambooth](dreambooth example readme) pip install git+https://github.com/ShivamShrirao/diffusers.git pip install -U -r requirements.txt and installed bitsandbytes with pip install bitsandbytes and installed xformer from source pip install ninja pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers Then accelerate config Then followed the steps for 12GB GPU, set all the variables and executed: `accelerate launch train_dreambooth.py \

--pretrained_model_name_or_path=$MODEL_NAME \ --instance_data_dir=$INSTANCE_DIR \ --class_data_dir=$CLASS_DIR \ --output_dir=$OUTPUT_DIR \ --with_prior_preservation --prior_loss_weight=1.0 \ --instance_prompt="a photo of sks dog" \ --class_prompt="a photo of dog" \ --resolution=512 \ --train_batch_size=1 \ --gradient_accumulation_steps=1 --gradient_checkpointing \ --use_8bit_adam \ --enable_xformers_memory_efficient_attention \ --set_grads_to_none \ --learning_rate=2e-6 \ --lr_scheduler="constant" \ --lr_warmup_steps=0 \ --num_class_images=200 \ --max_train_steps=800`

Logs

A matching Triton is not available, some optimizations will not be enabled.
Error caught was: No module named 'triton'
usage: train_dreambooth.py [-h] --pretrained_model_name_or_path
                           PRETRAINED_MODEL_NAME_OR_PATH
                           [--pretrained_vae_name_or_path PRETRAINED_VAE_NAME_OR_PATH]
                           [--revision REVISION]
                           [--tokenizer_name TOKENIZER_NAME]
                           [--instance_data_dir INSTANCE_DATA_DIR]
                           [--class_data_dir CLASS_DATA_DIR]
                           [--instance_prompt INSTANCE_PROMPT]
                           [--class_prompt CLASS_PROMPT]
                           [--save_sample_prompt SAVE_SAMPLE_PROMPT]
                           [--save_sample_negative_prompt SAVE_SAMPLE_NEGATIVE_PROMPT]
                           [--n_save_sample N_SAVE_SAMPLE]
                           [--save_guidance_scale SAVE_GUIDANCE_SCALE]
                           [--save_infer_steps SAVE_INFER_STEPS] [--pad_tokens]
                           [--with_prior_preservation]
                           [--prior_loss_weight PRIOR_LOSS_WEIGHT]
                           [--num_class_images NUM_CLASS_IMAGES]
                           [--output_dir OUTPUT_DIR] [--seed SEED]
                           [--resolution RESOLUTION] [--center_crop]
                           [--train_text_encoder]
                           [--train_batch_size TRAIN_BATCH_SIZE]
                           [--sample_batch_size SAMPLE_BATCH_SIZE]
                           [--num_train_epochs NUM_TRAIN_EPOCHS]
                           [--max_train_steps MAX_TRAIN_STEPS]
                           [--gradient_accumulation_steps GRADIENT_ACCUMULATION_STEPS]
                           [--gradient_checkpointing]
                           [--learning_rate LEARNING_RATE] [--scale_lr]
                           [--lr_scheduler LR_SCHEDULER]
                           [--lr_warmup_steps LR_WARMUP_STEPS] [--use_8bit_adam]
                           [--adam_beta1 ADAM_BETA1] [--adam_beta2 ADAM_BETA2]
                           [--adam_weight_decay ADAM_WEIGHT_DECAY]
                           [--adam_epsilon ADAM_EPSILON]
                           [--max_grad_norm MAX_GRAD_NORM] [--push_to_hub]
                           [--hub_token HUB_TOKEN] [--hub_model_id HUB_MODEL_ID]
                           [--logging_dir LOGGING_DIR]
                           [--log_interval LOG_INTERVAL]
                           [--save_interval SAVE_INTERVAL]
                           [--save_min_steps SAVE_MIN_STEPS]
                           [--mixed_precision {no,fp16,bf16}]
                           [--not_cache_latents] [--hflip]
                           [--local_rank LOCAL_RANK]
                           [--concepts_list CONCEPTS_LIST]
                           [--read_prompts_from_txts]
train_dreambooth.py: error: unrecognized arguments: --enable_xformers_memory_efficient_attention --set_grads_to_none
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ /home/test-gpu/anaconda3/envs/ldmclone/bin/accelerate:8 in <module>            โ”‚
โ”‚                                                                                โ”‚
โ”‚   5 from accelerate.commands.accelerate_cli import main                        โ”‚
โ”‚   6 if __name__ == '__main__':                                                 โ”‚
โ”‚   7 โ”‚   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])       โ”‚
โ”‚ โฑ 8 โ”‚   sys.exit(main())                                                       โ”‚
โ”‚   9                                                                            โ”‚
โ”‚                                                                                โ”‚
โ”‚ /home/test-gpu/anaconda3/envs/ldmclone/lib/python3.10/site-packages/accelerate โ”‚
โ”‚ /commands/accelerate_cli.py:45 in main                                         โ”‚
โ”‚                                                                                โ”‚
โ”‚   42 โ”‚   โ”‚   exit(1)                                                           โ”‚
โ”‚   43 โ”‚                                                                         โ”‚
โ”‚   44 โ”‚   # Run                                                                 โ”‚
โ”‚ โฑ 45 โ”‚   args.func(args)                                                       โ”‚
โ”‚   46                                                                           โ”‚
โ”‚   47                                                                           โ”‚
โ”‚   48 if __name__ == "__main__":                                                โ”‚
โ”‚                                                                                โ”‚
โ”‚ /home/test-gpu/anaconda3/envs/ldmclone/lib/python3.10/site-packages/accelerate โ”‚
โ”‚ /commands/launch.py:918 in launch_command                                      โ”‚
โ”‚                                                                                โ”‚
โ”‚   915 โ”‚   elif defaults is not None and defaults.compute_environment == Comput โ”‚
โ”‚   916 โ”‚   โ”‚   sagemaker_launcher(defaults, args)                               โ”‚
โ”‚   917 โ”‚   else:                                                                โ”‚
โ”‚ โฑ 918 โ”‚   โ”‚   simple_launcher(args)                                            โ”‚
โ”‚   919                                                                          โ”‚
โ”‚   920                                                                          โ”‚
โ”‚   921 def main():                                                              โ”‚
โ”‚                                                                                โ”‚
โ”‚ /home/test-gpu/anaconda3/envs/ldmclone/lib/python3.10/site-packages/accelerate โ”‚
โ”‚ /commands/launch.py:580 in simple_launcher                                     โ”‚
โ”‚                                                                                โ”‚
โ”‚   577 โ”‚   process.wait()                                                       โ”‚
โ”‚   578 โ”‚   if process.returncode != 0:                                          โ”‚
โ”‚   579 โ”‚   โ”‚   if not args.quiet:                                               โ”‚
โ”‚ โฑ 580 โ”‚   โ”‚   โ”‚   raise subprocess.CalledProcessError(returncode=process.retur โ”‚
โ”‚   581 โ”‚   โ”‚   else:                                                            โ”‚
โ”‚   582 โ”‚   โ”‚   โ”‚   sys.exit(1)                                                  โ”‚
โ”‚   583                                                                          โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
CalledProcessError: Command '['/home/test-gpu/anaconda3/envs/ldmclone/bin/python',
'train_dreambooth.py',
'--pretrained_model_name_or_path=CompVis/stable-diffusion-v1-4',
'--instance_data_dir=/home/test-gpu/code/training_data/test_1/data/training',
'--class_data_dir=/home/test-gpu/code/training_data/test_1/data/regularization',
'--output_dir=/home/test-gpu/code/model_checkpoints/test1',
'--with_prior_preservation', '--prior_loss_weight=1.0', '--instance_prompt=a photo
of sks man', '--class_prompt=a photo of man', '--resolution=512',
'--train_batch_size=1', '--gradient_accumulation_steps=1',
'--gradient_checkpointing', '--use_8bit_adam',
'--enable_xformers_memory_efficient_attention', '--set_grads_to_none',
'--learning_rate=2e-6', '--lr_scheduler=constant', '--lr_warmup_steps=0',
'--num_class_images=200', '--max_train_steps=800']' returned non-zero exit status
2.

System Info

jag-ermeister commented 11 months ago

@wjx008 those arguments are not present in this fork of diffusers. Those arguments were added to a later version in the original huggingface/diffusers repo. The train_dreambooth.py script in this forked repo enables xformers automatically with the following code in train_dreambooth.py:

if is_xformers_available():
    pipeline.enable_xformers_memory_efficient_attention()