Open DurransEdward opened 1 year ago
same question
I am not a pro but I have seen similar errors when there is a conflict between dtype, eg. float16 and float32. In this case since you are using mixed precision it might be conflicting with line 44 in train_dreambooth_inpaint.py. Try modifying the code on that line to float16 and do a quick few steps to test and see if this lets you generate the samples.
laiyingxin2, could you link me to the question you are talking about, please.
jmaccall316, I will try that now, thank you.
Describe the bug
I am trying to get the train_inpainting_dreambooth.py file working in Google Colab. To do this, I have adjusted DreamBooth_Stable_Diffusion.ipynb script provided so it installs and runs the train_inpainting_dreambooth.py file instead of the train_dreambooth.py file.
All the Install Requirements are installing properly, logging into Hugging face is working properly, and my sample images are uploading properly.
When I run:โจโจ
!python3 train_inpainting_dreambooth.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --pretrained_vae_name_or_path="stabilityai/sd-vae-ft-mse" \ --output_dir=$OUTPUT_DIR \ --with_prior_preservation --prior_loss_weight=1.0 \ --seed=1337 \ --resolution=512 \ --train_batch_size=2 \ --train_text_encoder \ --mixed_precision="fp16" \ --gradient_accumulation_steps=1 \ --learning_rate=2e-6 \ --lr_scheduler="constant" \ --lr_warmup_steps=0 \ --num_class_images=50 \ --sample_batch_size=4 \ --max_train_steps=150 \ --save_interval=150 \ --save_min_steps=150 \ --save_infer_steps=3 \ --concepts_list="concepts_list.json" \ --not_cache_latents \ --hflip
โจit tells me that the model has been trained, however, when it tries to generate the sample images, I get this error: โจ โจโจโจGenerating samples: 0% 0/4 [00:00<?, ?it/s] โญโโโโโโโโโโโโโโโโโโโโโ Traceback (most recent call last) โโโโโโโโโโโโโโโโโโโโโโโฎ โ /content/train_inpainting_dreambooth.py:876 in โ
โ โ
โ 873 โ
โ 874 if name == "main": โ
โ 875 โ args = parse_args() โ
โ โฑ 876 โ main(args) โ
โ 877 โ
โ โ
โ /content/train_inpainting_dreambooth.py:859 in main โ
โ โ
โ 856 โ โ โ โ accelerator.log(logs, step=global_step) โ
โ 857 โ โ โ โ
โ 858 โ โ โ if global_step > 0 and not global_step % args.save_interva โ
โ โฑ 859 โ โ โ โ save_weights(global_step) โ
โ 860 โ โ โ โ
โ 861 โ โ โ progress_bar.update(1) โ
โ 862 โ โ โ global_step += 1 โ
โ โ
โ /content/train_inpainting_dreambooth.py:758 in save_weights โ
โ โ
โ 755 โ โ โ โ inp_mask = Image.new("L", (512, 512), color=255) โ
โ 756 โ โ โ โ with torch.inference_mode(): โ
โ 757 โ โ โ โ โ for i in tqdm(range(args.n_save_sample), desc="Gen โ
โ โฑ 758 โ โ โ โ โ โ images = pipeline( โ
โ 759 โ โ โ โ โ โ โ prompt=concept["instance_prompt"], โ
โ 760 โ โ โ โ โ โ โ image=inp_img, โ
โ 761 โ โ โ โ โ โ โ mask_image=inp_mask, โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/torch/utils/_contextlib.py:115 in โ
โ decorate_context โ
โ โ
โ 112 โ @functools.wraps(func) โ
โ 113 โ def decorate_context(*args, kwargs): โ
โ 114 โ โ with ctx_factory(): โ
โ โฑ 115 โ โ โ return func(*args, *kwargs) โ
โ 116 โ โ
โ 117 โ return decorate_context โ
โ 118 โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/diffusers/pipelines/stable_diffusion/ โ
โ pipeline_stable_diffusion_inpaint.py:818 in call โ
โ โ
โ 815 โ โ ) โ
โ 816 โ โ โ
โ 817 โ โ # 7. Prepare mask latent variables โ
โ โฑ 818 โ โ mask, masked_image_latents = self.prepare_mask_latents( โ
โ 819 โ โ โ mask, โ
โ 820 โ โ โ masked_image, โ
โ 821 โ โ โ batch_size num_images_per_prompt, โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/diffusers/pipelines/stable_diffusion/ โ
โ pipeline_stable_diffusion_inpaint.py:597 in prepare_mask_latents โ
โ โ
โ 594 โ โ โ ] โ
โ 595 โ โ โ masked_image_latents = torch.cat(masked_image_latents, dim โ
โ 596 โ โ else: โ
โ โฑ 597 โ โ โ masked_image_latents = self.vae.encode(masked_image).laten โ
โ 598 โ โ masked_image_latents = self.vae.config.scaling_factor masked โ
โ 599 โ โ โ
โ 600 โ โ # duplicate mask and masked_image_latents for each generation โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/diffusers/utils/accelerate_utils.py:4 โ
โ 6 in wrapper โ
โ โ
โ 43 โ def wrapper(self, args, kwargs): โ
โ 44 โ โ if hasattr(self, "_hf_hook") and hasattr(self._hf_hook, "pre_fo โ
โ 45 โ โ โ self._hf_hook.pre_forward(self) โ
โ โฑ 46 โ โ return method(self, *args, kwargs) โ
โ 47 โ โ
โ 48 โ return wrapper โ
โ 49 โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/diffusers/models/autoencoder_kl.py:16 โ
โ 4 in encode โ
โ โ
โ 161 โ โ if self.use_tiling and (x.shape[-1] > self.tile_sample_min_siz โ
โ 162 โ โ โ return self.tiled_encode(x, return_dict=return_dict) โ
โ 163 โ โ โ
โ โฑ 164 โ โ h = self.encoder(x) โ
โ 165 โ โ moments = self.quant_conv(h) โ
โ 166 โ โ posterior = DiagonalGaussianDistribution(moments) โ
โ 167 โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py:1501 in โ
โ _call_impl โ
โ โ
โ 1498 โ โ if not (self._backward_hooks or self._backward_pre_hooks or s โ
โ 1499 โ โ โ โ or _global_backward_pre_hooks or _global_backward_hoo โ
โ 1500 โ โ โ โ or _global_forward_hooks or _global_forward_pre_hooks โ
โ โฑ 1501 โ โ โ return forward_call(*args, *kwargs) โ
โ 1502 โ โ # Do not call functions when jit is used โ
โ 1503 โ โ full_backward_hooks, non_full_backward_hooks = [], [] โ
โ 1504 โ โ backward_pre_hooks = [] โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/diffusers/models/vae.py:109 in โ
โ forward โ
โ โ
โ 106 โ โ
โ 107 โ def forward(self, x): โ
โ 108 โ โ sample = x โ
โ โฑ 109 โ โ sample = self.conv_in(sample) โ
โ 110 โ โ โ
โ 111 โ โ if self.training and self.gradient_checkpointing: โ
โ 112 โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py:1501 in โ
โ _call_impl โ
โ โ
โ 1498 โ โ if not (self._backward_hooks or self._backward_pre_hooks or s โ
โ 1499 โ โ โ โ or _global_backward_pre_hooks or _global_backward_hoo โ
โ 1500 โ โ โ โ or _global_forward_hooks or _global_forward_pre_hooks โ
โ โฑ 1501 โ โ โ return forward_call(args, kwargs) โ
โ 1502 โ โ # Do not call functions when jit is used โ
โ 1503 โ โ full_backward_hooks, non_full_backward_hooks = [], [] โ
โ 1504 โ โ backward_pre_hooks = [] โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/torch/nn/modules/conv.py:463 in โ
โ forward โ
โ โ
โ 460 โ โ โ โ โ โ self.padding, self.dilation, self.groups) โ
โ 461 โ โ
โ 462 โ def forward(self, input: Tensor) -> Tensor: โ
โ โฑ 463 โ โ return self._conv_forward(input, self.weight, self.bias) โ
โ 464 โ
โ 465 class Conv3d(_ConvNd): โ
โ 466 โ doc = r"""Applies a 3D convolution over an input signal compo โ
โ โ
โ /usr/local/lib/python3.9/dist-packages/torch/nn/modules/conv.py:459 in โ
โ _conv_forward โ
โ โ
โ 456 โ โ โ return F.conv2d(F.pad(input, self._reversed_padding_repea โ
โ 457 โ โ โ โ โ โ โ weight, bias, self.stride, โ
โ 458 โ โ โ โ โ โ โ _pair(0), self.dilation, self.groups) โ
โ โฑ 459 โ โ return F.conv2d(input, weight, bias, self.stride, โ
โ 460 โ โ โ โ โ โ self.padding, self.dilation, self.groups) โ
โ 461 โ โ
โ 462 โ def forward(self, input: Tensor) -> Tensor: โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
RuntimeError: Input type (c10::Half) and bias type (float) should be the same
Steps: 40% 60/150 [00:55<01:22, 1.09it/s, loss=0.162, lr=2e-6]โจโจ
I think this is a bug in the train_inpainting_dreambooth.py code. Although it is possible that I am running the code incorrectly. Any guidance would be appreciated. Thanks!
Reproduction
!python3 train_inpainting_dreambooth.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --pretrained_vae_name_or_path="stabilityai/sd-vae-ft-mse" \ --output_dir=$OUTPUT_DIR \ --with_prior_preservation --prior_loss_weight=1.0 \ --seed=1337 \ --resolution=512 \ --train_batch_size=2 \ --train_text_encoder \ --mixed_precision="fp16" \ --gradient_accumulation_steps=1 \ --learning_rate=2e-6 \ --lr_scheduler="constant" \ --lr_warmup_steps=0 \ --num_class_images=50 \ --sample_batch_size=4 \ --max_train_steps=150 \ --save_interval=150 \ --save_min_steps=150 \ --save_infer_steps=3 \ --concepts_list="concepts_list.json" \ --not_cache_latents \ --hflip
Logs
System Info
2023-04-04 10:36:38.116239: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.
diffusers
version: 0.15.0.dev0I'm not exactly sure what the last two bullet points are, sorry. However, when I run:
!nvidia-smi --query-gpu=name,memory.total,memory.free --format=csv,noheader
This is the output:
NVIDIA A100-SXM4-40GB, 40960 MiB, 40513 MiB
I am running everything in Google Colab with Notebook settings: