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
20.46k stars 2.26k forks source link

[Usage] Tokenization mismatch while finetuning Llama 3.1 #1710

Open wentaoyuan opened 2 months ago

wentaoyuan commented 2 months ago

Describe the issue

Issue: I ran into tokenization mismatch errors when I tried to fine-tune from Llama-3.1. I pre-trained a new MLP adapter for Llama-3.1 and that seems to work, but the fine-tuning script produced lots of warnings like the following and the loss was always 0.

WARNING: tokenization mismatch: 384 vs. 392. (ignored)                                                                                                                                                             
WARNING: tokenization mismatch: 414 vs. 416. (ignored)                                                                                                                                                             
WARNING: tokenization mismatch: 268 vs. 270. (ignored)                                                                                                                                                             
WARNING: tokenization mismatch: 273 vs. 275. (ignored)                                                                                                                                                             
WARNING: tokenization mismatch: 284 vs. 286. (ignored)                                                                                                                                                             
WARNING: tokenization mismatch: 218 vs. 220. (ignored)

Command:

#!/bin/bash

deepspeed llava/train/train_mem.py \
    --deepspeed ./scripts/zero3.json \
    --model_name_or_path meta-llama/Meta-Llama-3.1-8B-Instruct \
    --version v1 \
    --data_path data/llava_v1_5_mix665k.json \
    --image_folder data \
    --vision_tower openai/clip-vit-large-patch14-336 \
    --pretrain_mm_mlp_adapter checkpoints/llava-mlp2x-336px-pretrain-llama-3.1-8b \
    --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-13b \
    --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

Environment: Here are the versions of some important packages in my conda environment.

tokenizers                0.19.1
torch                     2.1.2
torchvision               0.16.2
transformers              4.43.1
accelerate                0.33.0
datasets                  2.20.0
deepspeed                 0.14.4
nvidia-cublas-cu12        12.1.3.1
nvidia-cuda-cupti-cu12    12.1.105
nvidia-cuda-nvrtc-cu12    12.1.105
nvidia-cuda-runtime-cu12  12.1.105
nvidia-cudnn-cu12         8.9.2.26
nvidia-cufft-cu12         11.0.2.54
nvidia-curand-cu12        10.3.2.106
nvidia-cusolver-cu12      11.4.5.107
nvidia-cusparse-cu12      12.1.0.106
nvidia-ml-py              12.555.43
nvidia-nccl-cu12          2.18.1
nvidia-nvjitlink-cu12     12.5.82
nvidia-nvtx-cu12          12.1.105
cainiaoup commented 1 month ago

you can rewrite the preprocess_llama_2 funciton follow llava-next (preprocess_llama_3)