2023-05-12 11:04:53 +00:00
# miniGPT4
[Chineses version ](README_cn.md ) < p > 🚀🚀</ p >
This project has modified demo.py and conversation.py to support direct text conversation without the need to upload an image first.
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
**TODO: Support multiple images uploading.**
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
exmple:

2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
The following is the process for configuring the project environment. If you have already completed this step, you can skip the environment configuration and directly run demo.py.
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
[Offcial repo ](https://github.com/Vision-CAIR/MiniGPT-4 )
supports two pretrained weights [13B ](https://drive.google.com/file/d/1a4zLvaiDBr-36pasffmgpvH5P7CKmpze/view ) and [7B ](https://drive.google.com/file/d/1a4zLvaiDBr-36pasffmgpvH5P7CKmpze/view ) can be used fintuning
2023-04-20 19:57:41 +00:00
2023-05-12 11:04:53 +00:00
**GPU Memory needed**
2023-04-20 19:57:41 +00:00
2023-05-12 11:04:53 +00:00
* 13B: 23G
* 7B: 11.5G
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
### Getting start
**0.Environment setup**
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
make sure you install docker first
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
pull up [docker image ](https://hub.docker.com/r/bewithmeallmylife/mini-gpt4-runtime-cuda-10.2 )
```commandline
docker pull bewithmeallmylife/mini-gpt4-runtime-cuda-10.2:1.0.0
```
Build the container, expose the corresponding port to enable launching the frontend UI for local use.
```commandline
2023-06-07 01:41:06 +00:00
docker run -v /data:/projects -v /data2:/data2 -p 1118:7778 --shm-size 8G --name minigpt4 -d bewithmeallmylife/mini-gpt4-runtime-cuda-10.2:1.0.0 tail -f /dev/null
2023-05-12 11:04:53 +00:00
```
Get into docker
```commandline
docker exec -it minigpt4 bash
2023-04-16 22:04:16 +00:00
```
2023-05-12 11:04:53 +00:00
conda environment **mini-gpt4** already have
```commandline
conda activate mini-gpt4
```
note: make sure torch is compatible with your cuda version, in this image, the torch version is 1.12.1+cu10.2
if your cuda is above 11, then execute this step.
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
The inference environment required for miniGPT4 is already included in the image, with PyTorch version 1.12.1+cu10.2, which does not support the sm86 architecture. If the GPU model is RTX A6000 with an architecture of 8.6, a version that supports this architecture such as torch1.12.1+cu11.3 needs to be reinstalled.
```commandline
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
```
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
**1.Prepare the pretrained model weights.**
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
A total of three pretrained model weights need to be prepared: **vicuna** (7B/14G), **llama** (7B/12.5G), and **miniGPT4** (7B).
* vicuna
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
Pretrained weights in two sizes, 13B and 7B, are available for download.
```commandline
git lfs install
git clone https://huggingface.co/lmsys/vicuna-13b-delta-v0 # more powerful, need at least 24G gpu memory
# or
git clone https://huggingface.co/lmsys/vicuna-7b-delta-v0 # smaller, need 12G gpu memory
```
These two weights are not working, we still need llama pretrained wieght.
* llama
To download the llama weights, which are not officially available for download, a third-party download form is used. Choose between 7B or 13B.
```commandline
wget https://agi.gpt4.org/llama/LLaMA/tokenizer.model -O ./tokenizer.model
wget https://agi.gpt4.org/llama/LLaMA/tokenizer_checklist.chk -O ./tokenizer_checklist.chk
wget https://agi.gpt4.org/llama/LLaMA/7B/consolidated.00.pth -O ./7B/consolidated.00.pth
wget https://agi.gpt4.org/llama/LLaMA/7B/params.json -O ./7B/params.json
wget https://agi.gpt4.org/llama/LLaMA/7B/checklist.chk -O ./7B/checklist.chk
wget https://agi.gpt4.org/llama/LLaMA/13B/consolidated.00.pth -O ./13B/consolidated.00.pth
wget https://agi.gpt4.org/llama/LLaMA/13B/consolidated.01.pth -O ./13B/consolidated.01.pth
wget https://agi.gpt4.org/llama/LLaMA/13B/params.json -O ./13B/params.json
wget https://agi.gpt4.org/llama/LLaMA/13B/checklist.chk -O ./13B/checklist.chk
```
After downloading llama, we need to transform it to Huggingface format
```commandline
git clone https://github.com/huggingface/transformers.git
python transformers/src/transformers/models/llama/convert_llama_weights_to_hf.py \
--input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path/to/llama-13bOR7b-hf/
2023-04-16 22:04:16 +00:00
```
2023-05-12 11:04:53 +00:00
After both the vicuna and llama weights are prepared, they need to be combined to obtain the vicuna weights that can be used.
```commandline
pip install git+https://github.com/lm-sys/FastChat.git@v0.1.10
python -m fastchat.model.apply_delta --base /path/to/llama-13bOR7b-hf/ --target /path/to/save/working/vicuna/weight/ --delta /path/to/vicuna-13bOR7b-delta-v0/
```
Finally get a working weight, the weight folder is like below:
```commandline
2023-04-16 22:04:16 +00:00
vicuna_weights
├── config.json
├── generation_config.json
├── pytorch_model.bin.index.json
├── pytorch_model-00001-of-00003.bin
...
```
2023-05-12 11:04:53 +00:00
Then, set the path to the vicuna weight in the model config file [here ](minigpt4/configs/models/minigpt4.yaml ) at Line 16.
* minigpt4 checkpoints
2023-04-16 22:04:16 +00:00
2023-05-12 11:04:53 +00:00
[13B checkpoint ](https://drive.google.com/file/d/1a4zLvaiDBr-36pasffmgpvH5P7CKmpze/view?usp=share_link )
[7B checkpoint ](https://drive.google.com/file/d/1RY9jV0dyqLX-o38LrumkKRh6Jtaop58R/view?usp=sharing )
2023-04-20 19:03:34 +00:00
2023-05-12 11:04:53 +00:00
Then, set the path to the pretrained checkpoint in the evaluation config file in [eval_configs/minigpt4_eval.yaml ](eval_configs/minigpt4_eval.yaml ) at Line 11.
2023-04-20 19:03:34 +00:00
2023-05-12 11:04:53 +00:00
**2.run demo.py**
```commandline
2023-04-19 17:00:25 +00:00
python demo.py --cfg-path eval_configs/minigpt4_eval.yaml --gpu-id 0
2023-04-16 22:04:16 +00:00
```