microsoft / LLaVA-Med

Large Language-and-Vision Assistant for Biomedicine, built towards multimodal GPT-4 level capabilities.
Other
1.48k stars 180 forks source link

out of memory - even reduced the elements in the instruction following dataset to just one #43

Open mao1207 opened 8 months ago

mao1207 commented 8 months ago

I encountered an out of memory issue during model training, even though I had already reduced the elements in the instruction following dataset to just one and removed the contents of conversations:

[
    {
        "id": "35163262_ijms-23-01339-f006",
        "image": "35163262_ijms-23-01339-f006.jpg",
        "conversations": []
    }
]

Surprisingly, I still ran out of memory when training with a 48GB memory card. I suspect there might be some infinite loop or other strange occurrence in the middle of the process. Can you shed some light on this?

The training command I used was:

torchrun --nnodes=1 --nproc_per_node=1 --master_port=25001 \
    llava/train/train_mem.py \
    --model_name_or_path /local/scratch3/xfang31/xin/LLaVA-Med/data/LLaVA-7b-v0 \
    --data_path /local/scratch3/xfang31/xin/LLaVA-Med/data/instruct/vision_instruction.json \
    --image_folder /local/scratch3/xfang31/xin/LLaVA-Med/data/images \
    --vision_tower openai/clip-vit-large-patch14 \
    --mm_vision_select_layer -2 \
    --mm_use_im_start_end True \
    --bf16 False \
    --output_dir /local/scratch3/xfang31/xin/LLaVA-Med/data/llava-vision \
    --num_train_epochs 3 \
    --per_device_train_batch_size 1 \
    --per_device_eval_batch_size 4 \
    --gradient_accumulation_steps 8 \
    --evaluation_strategy "no" \
    --save_strategy "steps" \
    --save_steps 5000 \
    --save_total_limit 3 \
    --learning_rate 2e-5 \
    --weight_decay 0. \
    --warmup_ratio 0.03 \
    --lr_scheduler_type "cosine" \
    --logging_steps 1 \
    --tf32 False \
    --fsdp "full_shard auto_wrap" \
    --fsdp_transformer_layer_cls_to_wrap 'LlamaDecoderLayer' \
    --model_max_length 2048 \
    --gradient_checkpointing True \
    --lazy_preprocess True \
    --report_to wandb
ntlm1686 commented 7 months ago

Hi @mao1207 , have you managed to solve this probelm? I am having the same issue with 48GB memory cards.

Edit: No OOM with more than 2 cards.

jzssz commented 7 months ago

hi, @mao1207 i have the same issue that shows error "CUDA out of memory" when run "model = model.to(device)" in "/anaconda3/envs/llava-med/lib/python3.10/site-packages/transformers/trainer.py -- class Trainer: def _move_model_to_device()". Have you solved this issue and how to solve it? thanks a lot !!!!!!!!