-
Notifications
You must be signed in to change notification settings - Fork 12k
support MiniCPM-V-2.6 #8967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
support MiniCPM-V-2.6 #8967
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
7a49a6f
init
tc-mb c536fa6
rename
tc-mb 2b91903
add run android for termux in readme
tc-mb 0480d5f
add android readme
tc-mb ec1cea7
add instructions in readme
tc-mb a491f45
change name in readme
tc-mb 7573b63
Update README.md
iceflame89 94dcaba
fixed line
harvestingmoon b31f51f
Merge pull request #1 from harvestingmoon/minicpm-v2.5
tc-mb 629420e
add result in readme
tc-mb b48708a
random pos_embed
tc-mb d9fbc1d
add positions index
tc-mb 18fe620
change for ollama
tc-mb 2997a68
change for ollama
tc-mb 8541e99
better pos_embed in clip
tc-mb d8974b8
support ollama
tc-mb e73a0c7
updata cmakelist
tc-mb 6366d62
updata cmakelist
tc-mb 056d178
rename wrapper
tc-mb 3c306f1
clear code
tc-mb 9495504
replace and organize code
tc-mb b37ab0b
add link
tc-mb 8767ce2
Merge branch 'prepare-PR-of-minicpm-v2.5' into prepare-PR
tc-mb 8bd47ce
Merge pull request #7 from OpenBMB/prepare-PR
tc-mb 28d4a7f
Merge pull request #8 from OpenBMB/master
tc-mb 02eb445
sync master
tc-mb 07f48f9
fix warnings
tc-mb c38d152
fix warnings
tc-mb 88f5e6a
fix bug in bicubic resize when need resize iamge smaller
tc-mb a913ca4
receive review comments and modify
tc-mb a95a6d9
receive review comments and modify
tc-mb c390dd4
Merge branch 'ggerganov:master' into prepare-PR-of-minicpm-v2.5
tc-mb efe4c61
put all code into llava dir
tc-mb ee5b850
Merge pull request #11 from OpenBMB/pr_add_all_in_llava
tc-mb 77beb4d
Merge branch 'prepare-PR-of-minicpm-v2.5' into master
tc-mb cb8cfb9
Merge pull request #15 from OpenBMB/master
tc-mb 8f03505
fix quality problem in pr code
tc-mb e68c8bc
change n_layer
tc-mb 4c67d7c
add space in "-1"
tc-mb 977941d
imitate reshape bug of python code
tc-mb 3e6348b
fix bug in clip
tc-mb c5b6851
fix issues for merging
tc-mb 5959b14
fix llama-minicpmv-cli in cmake file
tc-mb 292a469
change pr readme
tc-mb be8b5b2
fix code review
tc-mb 4c75583
remove in line 33 directory in the /cmakelists.txt (not in example, i…
tc-mb 62fa15b
fix cmakefile
tc-mb dad4abe
add warn
tc-mb 3642be9
fix KEY_HAS_MINICPMV_PROJ
tc-mb fcde997
remove load_image_size into clip_ctx
tc-mb 6fd0937
remove the extern "C", MINICPMV_API
tc-mb 107e1ed
fix uhd code for review comment
tc-mb 72b9629
delete minicpmv-wrapper in pr
tc-mb f3d400d
remove uhd_image_embed
tc-mb 65f7455
Modify 2 notes
tc-mb 6da5130
support minicpmv2.6
tc-mb 77c580d
modify convert script of minicpmv
tc-mb ea0c828
modify convert
tc-mb fc1c860
Merge branch 'prepare-PR-of-minicpm-v2.6' into master
tc-mb ce0d1a6
Merge pull request #24 from OpenBMB/master
tc-mb 6cad864
modify convert
tc-mb fe39ecc
add readme
tc-mb bffbe1c
add resampler of v2.6
tc-mb 28d6a0f
modify clip
tc-mb 4a87d1d
modify readme
tc-mb 32b47f6
fix type-check
tc-mb 662d4c1
fix type-check
tc-mb a945b3c
fix type-check
tc-mb 89d378c
fix type-check
tc-mb 1ec79f0
modify convert script and readme
tc-mb 1123376
fix convert script and readme
tc-mb f30c5e1
fix convert
tc-mb 47eb0a5
fix num in convert
tc-mb 1ca3f06
fix type-check
tc-mb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
## MiniCPM-V 2.6 | ||
|
||
### Prepare models and code | ||
|
||
Download [MiniCPM-V-2_6](https://huggingface.co/openbmb/MiniCPM-V-2_6) PyTorch model from huggingface to "MiniCPM-V-2_6" folder. | ||
|
||
Clone llama.cpp: | ||
```bash | ||
git clone git@github.com:OpenBMB/llama.cpp.git | ||
cd llama.cpp | ||
git checkout minicpmv-main | ||
``` | ||
|
||
### Usage of MiniCPM-V 2.6 | ||
|
||
Convert PyTorch model to gguf files (You can also download the converted [gguf](https://huggingface.co/openbmb/MiniCPM-V-2_6-gguf) by us) | ||
|
||
```bash | ||
python ./examples/llava/minicpmv-surgery.py -m ../MiniCPM-V-2_6 | ||
python ./examples/llava/minicpmv-convert-image-encoder-to-gguf.py -m ../MiniCPM-V-2_6 --minicpmv-projector ../MiniCPM-V-2_6/minicpmv.projector --output-dir ../MiniCPM-V-2_6/ --image-mean 0.5 0.5 0.5 --image-std 0.5 0.5 0.5 --minicpmv_version 3 | ||
python ./convert_hf_to_gguf.py ../MiniCPM-V-2_6/model | ||
|
||
# quantize int4 version | ||
./llama-quantize ../MiniCPM-V-2_6/model/ggml-model-f16.gguf ../MiniCPM-V-2_6/model/ggml-model-Q4_K_M.gguf Q4_K_M | ||
``` | ||
|
||
Build for Linux or Mac | ||
|
||
```bash | ||
make | ||
make llama-minicpmv-cli | ||
``` | ||
|
||
Inference on Linux or Mac | ||
``` | ||
# run f16 version | ||
./llama-minicpmv-cli -m ../MiniCPM-V-2_6/model/ggml-model-f16.gguf --mmproj ../MiniCPM-V-2_6/mmproj-model-f16.gguf -c 4096 --temp 0.7 --top-p 0.8 --top-k 100 --repeat-penalty 1.05 --image xx.jpg -p "What is in the image?" | ||
|
||
# run quantized int4 version | ||
./llama-minicpmv-cli -m ../MiniCPM-V-2_6/model/ggml-model-Q4_K_M.gguf --mmproj ../MiniCPM-V-2_6/mmproj-model-f16.gguf -c 4096 --temp 0.7 --top-p 0.8 --top-k 100 --repeat-penalty 1.05 --image xx.jpg -p "What is in the image?" | ||
|
||
# or run in interactive mode | ||
./llama-minicpmv-cli -m ../MiniCPM-V-2_6/model/ggml-model-Q4_K_M.gguf --mmproj ../MiniCPM-V-2_6/mmproj-model-f16.gguf -c 4096 --temp 0.7 --top-p 0.8 --top-k 100 --repeat-penalty 1.05 --image xx.jpg -i | ||
``` | ||
|
||
### Video | ||
Install FFmpeg | ||
``` | ||
brew install ffmpeg | ||
brew install pkg-config | ||
``` | ||
|
||
### Android | ||
|
||
#### Build on Android device using Termux | ||
We found that build on Android device would bring better runtime performance, so we recommend to build on device. | ||
|
||
[Termux](https://github.com/termux/termux-app#installation) is a terminal app on Android device (no root required). | ||
|
||
Install tools in Termux: | ||
``` | ||
apt update && apt upgrade -y | ||
apt install git make cmake | ||
``` | ||
|
||
It's recommended to move your model inside the `~/` directory for best performance: | ||
``` | ||
cd storage/downloads | ||
mv model.gguf ~/ | ||
``` | ||
|
||
#### Building the Project using Android NDK | ||
Obtain the [Android NDK](https://developer.android.com/ndk) and then build with CMake. | ||
|
||
Execute the following commands on your computer to avoid downloading the NDK to your mobile. Alternatively, you can also do this in Termux: | ||
|
||
```bash | ||
mkdir build-android | ||
cd build-android | ||
export NDK=/your_ndk_path | ||
cmake -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -DCMAKE_C_FLAGS=-march=armv8.4a+dotprod .. | ||
make | ||
``` | ||
|
||
Install [termux](https://github.com/termux/termux-app#installation) on your device and run `termux-setup-storage` to get access to your SD card (if Android 11+ then run the command twice). | ||
|
||
Finally, copy these built `llama` binaries and the model file to your device storage. Because the file permissions in the Android sdcard cannot be changed, you can copy the executable files to the `/data/data/com.termux/files/home/bin` path, and then execute the following commands in Termux to add executable permission: | ||
|
||
(Assumed that you have pushed the built executable files to the /sdcard/llama.cpp/bin path using `adb push`) | ||
``` | ||
$cp -r /sdcard/llama.cpp/bin /data/data/com.termux/files/home/ | ||
$cd /data/data/com.termux/files/home/bin | ||
$chmod +x ./* | ||
``` | ||
|
||
Download models and push them to `/sdcard/llama.cpp/`, then move it to `/data/data/com.termux/files/home/model/` | ||
|
||
``` | ||
$mv /sdcard/llama.cpp/ggml-model-Q4_K_M.gguf /data/data/com.termux/files/home/model/ | ||
$mv /sdcard/llama.cpp/mmproj-model-f16.gguf /data/data/com.termux/files/home/model/ | ||
``` | ||
|
||
Now, you can start chatting: | ||
``` | ||
$cd /data/data/com.termux/files/home/bin | ||
$./llama-minicpmv-cli -m ../model/ggml-model-Q4_K_M.gguf --mmproj ../model/mmproj-model-f16.gguf -c 4096 --temp 0.7 --top-p 0.8 --top-k 100 --repeat-penalty 1.05 --image xx.jpg -p "What is in the image?" | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.