|
--- |
|
license: apache-2.0 |
|
tags: |
|
- llava |
|
pipeline_tag: image-text-to-text |
|
--- |
|
## Model |
|
llava-siglip-internlm2-1_8b-pretrain-v2 is a LLaVA checkpoint finetuned from [internlm2-1_8b](https://huggingface.co./internlm/internlm2-1_8b) and [siglip-so400m-patch14-384](https://huggingface.co./google/siglip-so400m-patch14-384) with [LLaVA-Pretrain](liuhaotian/LLaVA-Pretrain) by [Xtuner](https://github.com/InternLM/xtuner). The pretraining phase took 5.5 hours on 4 Nvidia GTX 4090 GPU (see this [intermediate checkpoint](https://huggingface.co./StarCycle/llava-siglip-internlm2-1_8b-pretrain-v2)). |
|
|
|
The total size of the model is around 2.2B, which is suitable for embedded applications like robotics. |
|
|
|
#### I just finished the pretrain phase of the model. I will release the full finetuned model soon. You can also finetune your own version based on the checkpoint here. |
|
|
|
## Installation |
|
``` |
|
# We need the newest version so clone from github |
|
git clone https://github.com/huggingface/transformers/ |
|
git clone https://github.com/huggingface/peft |
|
git clone https://github.com/InternLM/xtuner |
|
``` |
|
Now please replace the files in transformers and xtuner with the source code files in modified_transformers and modified_xtuner. |
|
|
|
Then run |
|
``` |
|
pip install -e ./xtuner[deepspeed] |
|
apt install git-lfs |
|
``` |
|
|
|
## Common Errors |
|
1. |
|
``` |
|
command error: 'libGL.so.1: cannot open shared object file: No such file or directory'! |
|
``` |
|
You can solve it by |
|
``` |
|
# For Ubuntu |
|
sudo apt-get update |
|
sudo apt-get install libgl1-mesa-glx |
|
|
|
# For CentOS and Fedora |
|
sudo yum install mesa-libGL |
|
``` |
|
|
|
2. |
|
``` |
|
Error: mkl-service + Intel(R) MKL: MKL_THREADING_LAYER=INTEL is incompatible with libgomp.so.1 library. |
|
Try to import numpy first or set the threading layer accordingly. Set MKL_SERVICE_FORCE_INTEL to force it. |
|
``` |
|
You can solve it by reinstall numpy. |
|
|
|
3. |
|
``` |
|
ImportError: |
|
InternLM2Converter requires the protobuf library but it was not found in your environment. Checkout the instructions on the |
|
``` |
|
You just need |
|
``` |
|
pip install protobuf |
|
``` |
|
4. |
|
To use tensorboard to visualize the training loss curve: |
|
``` |
|
pip install future tensorboard |
|
``` |
|
|
|
5. If your training process is killed during data preprocessing, you can modify the `map_num_proc` in xtuner/xtuner/dataset |
|
/huggingface.py |
|
``` |
|
def process(dataset, |
|
do_dataset_tokenization=True, |
|
tokenizer=None, |
|
max_length=None, |
|
dataset_map_fn=None, |
|
template_map_fn=None, |
|
max_dataset_length=None, |
|
split='train', |
|
remove_unused_columns=False, |
|
rename_maps=[], |
|
shuffle_before_pack=True, |
|
pack_to_max_length=True, |
|
use_varlen_attn=False, |
|
input_ids_with_output=True, |
|
with_image_token=False, |
|
map_num_proc=32): # modify it to a smaller number, e.g., 4 |
|
``` |
|
|
|
6. If you fail to load the model, check whether you installed git-lfs and actually downloaded the model file. |
|
|
|
## Data prepration |
|
1. File structure |
|
|
|
``` |
|
# . means the llava-clip-internlm2-1_8b-pretrain-v1 folder you clone |
|
./data/llava_data |
|
βββ LLaVA-Pretrain |
|
Β Β βββ blip_laion_cc_sbu_558k.json |
|
Β Β βββ blip_laion_cc_sbu_558k_meta.json |
|
Β Β βββ images |
|
|
|
``` |
|
|
|
2. Pretrain Data |
|
|
|
LLaVA-Pretrain |
|
|
|
```shell |
|
# Make sure you have git-lfs installed (https://git-lfs.com) |
|
git lfs install |
|
git clone https://huggingface.co./datasets/liuhaotian/LLaVA-Pretrain --depth=1 |
|
``` |
|
|
|
3. Finetune Data |
|
|
|
Please check the final release version |
|
|
|
## Cheers! Now train your own model! |
|
1. Alignment module pretraining |
|
``` |
|
# single GPU |
|
xtuner train ./pretrain.py --deepspeed deepspeed_zero2 |
|
|
|
# multiple GPU |
|
NPROC_PER_NODE=4 xtuner train ./pretrain.py --deepspeed deepspeed_zero2 |
|
``` |
|
|
|
#### Remember to change the batch size and gradient accumulation parameters to fit your hardware. So your GPU_num * batch_size * gradient_accumulation is roughly equal to mine to reproduce the result. |
|
|
|
The checkpoint and tensorboard logs are saved by default in ./work_dirs/. I only train it for 1 epoch to be same as the original LLaVA paper. Some researches also report that training for multiple epochs will make the model overfit the training dataset and perform worse in other domains. |
|
|
|
This is my loss curve for llava-siglip-internlm2-1_8b-pretrain-v2: |
|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/642a298ae5f33939cf3ee600/1vh2gsRzEFXia7zCRRIlz.png) |
|
|
|
And the learning rate curve: |
|
![image/png](https://cdn-uploads.huggingface.co/production/uploads/642a298ae5f33939cf3ee600/CdNSJcLCv9MmYG88AJFwB.png) |
|
|
|
2. Instruction following fine-tuning |
|
|
|
Please check the final release version |