TinyLLaVA / TinyLLaVA_Factory

A Framework of Small-scale Large Multimodal Models
https://arxiv.org/abs/2402.14289
Apache License 2.0
569 stars 53 forks source link

loss always zero #38

Closed ovvo20 closed 5 months ago

ovvo20 commented 5 months ago

Great job! I have found the finetune script without lora, and I only have one modal data so I set group_by_modality_length to False, but loss is always 0. Do you know why?

baichuanzhou commented 5 months ago

Can you provide some more details?

ovvo20 commented 5 months ago

my custom dataset have 2087 items, and the the format is as follows:

image

my finetune script is as follows:

!/bin/bash

DATA_PATH="data/updated_data.json" IMAGE_PATH="data/flickr30k-images/" OUTPUT_DIR="TinyLLaVA-1.5B-finetune"

deepspeed tinyllava/train/train.py \ --deepspeed scripts/tiny_llava/zero3.json \ --model_name_or_path TinyLLaVA-1.5B \ --version phi \ --data_path $DATA_PATH \ --image_folder $IMAGE_PATH\ --vision_tower TinyLLaVA-1.5B-SigLIP \ --mm_projector_type mlp2x_gelu \ --mm_vision_select_layer -2 \ --mm_use_im_start_end False \ --mm_use_im_patch_token False \ --image_aspect_ratio pad \ --group_by_modality_length False \ --fp16 True \ --output_dir $OUTPUT_DIR \ --num_train_epochs 1 \ --per_device_train_batch_size 8 \ --per_device_eval_batch_size 4 \ --gradient_accumulation_steps 2 \ --evaluation_strategy "no" \ --save_strategy "steps" \ --save_steps 50000 \ --save_total_limit 1 \ --learning_rate 2e-5 \ --weight_decay 0. \ --warmup_ratio 0.03 \ --lr_scheduler_type "cosine" \ --logging_steps 1 \ --tf32 False \ --model_max_length 3072 \ --gradient_checkpointing True \ --dataloader_num_workers 15 \ --lazy_preprocess True \ --report_to wandb \

partial screenshot of training details:

image image
baichuanzhou commented 5 months ago

It's because the conv_mode you set caused every target to be -100. You should change your conv_mode to v1

ovvo20 commented 5 months ago

Is the conv_mode you mentioned modified here? Is the v0 and v0.5 here changed to v1 in train.py? Thank you!

if model_args.version == "v0":
    if tokenizer.pad_token is None:
        smart_tokenizer_and_embedding_resize(
            special_tokens_dict=dict(pad_token="[PAD]"),
            tokenizer=tokenizer,
            model=model,
        )
elif model_args.version == "v0.5":
    tokenizer.pad_token = tokenizer.unk_token
else:
    tokenizer.pad_token = tokenizer.unk_token

    model.config.pad_token_id = tokenizer.pad_token_id
    model.config.pad_token = tokenizer.pad_token

    if model_args.version in conversation_lib.conv_templates:
        conversation_lib.default_conversation = conversation_lib.conv_templates[model_args.version]
    else:
        conversation_lib.default_conversation = conversation_lib.conv_templates["vicuna_v1"]
baichuanzhou commented 5 months ago

Change the --version from phi to v1. It is in your finetune.sh

ovvo20 commented 5 months ago

oh! loss is no longer 0, thanks!

baichuanzhou commented 5 months ago

I guess we can close this issue then?

ggcr commented 2 months ago

@baichuanzhou Will this full finetune work if we change the connector to, say qformer and use as model jiajunlong/TinyLLaVA-OpenELM-450M-SigLIP-0.89B? Or we need to use the same connector as the baseline model?

Thanks in advance