haotian-liu / LLaVA

[NeurIPS'23 Oral] Visual Instruction Tuning (LLaVA) built towards GPT-4V level capabilities and beyond.
https://llava.hliu.cc
Apache License 2.0
19.93k stars 2.19k forks source link

[Question] Is this everything I need to do to properly fine-tune llava-v1.5-7b? #872

Closed rringham closed 11 months ago

rringham commented 11 months ago

Question

Hi - I'm trying to wrap my head around how I'd fine-tune LLaVA for a specific use case. As an experiment, I have 28k images that I've generated a dataset.json for (am just programmatically generating text descriptions based on already known classes).

My somewhat vague understanding is that I should be able to fine-tune llava-v1.5-7b by doing something like the following (and nothing more):

deepspeed llava/train/train_mem.py \
    --lora_enable True --lora_r 128 --lora_alpha 256 --mm_projector_lr 2e-5 \
    --deepspeed ./scripts/zero3.json \
    --model_name_or_path liuhaotian/llava-v1.5-7b \
    --version v1 \
    --data_path /code/datasets/labeled_images/dataset.json \
    --image_folder /code/datasets/labeled_images \
    --vision_tower openai/clip-vit-large-patch14-336 \
    --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 True \
    --bf16 True \
    --output_dir ./checkpoints/llava-v1.5-7b \
    --num_train_epochs 1 \
    --per_device_train_batch_size 16 \
    --per_device_eval_batch_size 4 \
    --gradient_accumulation_steps 1 \
    --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 True \
    --model_max_length 2048 \
    --gradient_checkpointing True \
    --dataloader_num_workers 4 \
    --lazy_preprocess True \
    --report_to wandb

However, when I go to use (see following command) it will complain that mm_projection.bin is missing.

python model_vqa.py \
    --model-base liuhaotian/llava-v1.5-7b \
    --model-path ./checkpoints/llava-v1.5-7b  \
    --question-file ./questions.json \
    --image-folder /code/datasets/labeled_images \
    --answers-file ./answers.json

I can get the above command to work if I manually rename ./checkpoints/llava-v1.5-7b/non_lora_trainables.bin to be ./checkpoints/llava-v1.5-7b/mm_projection.bin, but the responses I see written to answers.json don't really appear as though they have been fine-tuned on my dataset - they look like the kinds of responses I get from the stock liuhaotian/llava-v1.5-7b model.

It leaves doubt in my mind that I'm actually correctly fine-tuning. Am I missing any key steps?

haotian-liu commented 11 months ago

Please add a "lora" in the model path so that it knows that it is a lora trained weights. We're optimizing the parsing strategy, but currently this should solve your problem. And please do not rename the file.

--output_dir ./checkpoints/llava-v1.5-7b-mytask-lora \ --model-path ./checkpoints/llava-v1.5-7b-mytask-lora \

rringham commented 11 months ago

Thank you, that worked for me. Much appreciated!