Unable to save the unet weights after finetuning the model using text_to_image.py (ValueError: You are trying to save a non contiguous tensor: `conv_in.weight` which is not allowed))

#4
by Palawat - opened

I want to finetune tiny-sd on a different dataset by following text_to_image training (https://huggingface.co/docs/diffusers/main/en/training/text2image) and change the model_name to "segmind/tiny-sd". However, once I run the following code, I get this error.
export MODEL_NAME="segmind/tiny-sd"
export dataset_name="lambdalabs/pokemon-blip-captions"

accelerate launch examples/text_to_image/train_text_to_image.py
--pretrained_model_name_or_path=$MODEL_NAME
--dataset_name=$dataset_name
--use_ema
--resolution=512 --center_crop --random_flip
--train_batch_size=1
--gradient_accumulation_steps=4
--gradient_checkpointing
--mixed_precision="fp16"
--max_train_steps=20
--learning_rate=1e-05
--max_grad_norm=1
--lr_scheduler="constant" --lr_warmup_steps=0
--output_dir="sd-pokemon-model"

======================Error=====================================

image.png

Note that the small-sd version doesn't have this problem. Only the tiny-sd version has this issue.
Thank you,

same problem, Only the tiny-sd version has this issue.
segmind/small-sd don't have issue

Same. What the hell bro? :(

Here is a simple reproducible example:

from diffusers import UNet2DConditionModel


unet = UNet2DConditionModel.from_pretrained(
    "segmind/tiny-sd", subfolder="unet"
)

unet.save_pretrained("/test")

@Palawat @neurlang ChatGPT helped me to fix it:

for param in unet.parameters():
    param.data = param.data.contiguous()

Sign up or log in to comment