Skip to content

Commit e71c68b

Browse files
committed
add minicpmv2.0
1 parent 7841fc7 commit e71c68b

File tree

11 files changed

+3799
-0
lines changed

11 files changed

+3799
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
add_library(minicpmv OBJECT
2+
minicpmv.cpp
3+
minicpmv.h
4+
clip.cpp
5+
clip.h
6+
)
7+
8+
target_link_libraries(minicpmv PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
9+
10+
target_include_directories(minicpmv PUBLIC .)
11+
target_include_directories(minicpmv PUBLIC ../..)
12+
target_include_directories(minicpmv PUBLIC ../../common)
13+
14+
target_compile_features(minicpmv PRIVATE cxx_std_17)
15+
16+
add_library(minicpmv_static STATIC $<TARGET_OBJECTS:minicpmv>)
17+
if (BUILD_SHARED_LIBS)
18+
set_target_properties(minicpmv PROPERTIES POSITION_INDEPENDENT_CODE ON)
19+
target_compile_definitions(minicpmv PRIVATE LLAMA_SHARED LLAMA_BUILD)
20+
add_library(minicpmv_shared SHARED $<TARGET_OBJECTS:minicpmv>)
21+
target_link_libraries(minicpmv_shared PRIVATE ggml llama ${CMAKE_THREAD_LIBS_INIT})
22+
install(TARGETS minicpmv_shared LIBRARY)
23+
endif()
24+
25+
if (NOT MSVC)
26+
target_compile_options(minicpmv PRIVATE -Wno-cast-qual) # stb_image.h
27+
endif()
28+
29+
if(TARGET BUILD_INFO)
30+
add_dependencies(minicpmv BUILD_INFO)
31+
endif()
32+
33+
set(TARGET minicpmv-cli)
34+
add_executable(${TARGET} minicpmv-cli.cpp)
35+
set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME minicpmv-cli)
36+
install(TARGETS ${TARGET} RUNTIME)
37+
target_link_libraries(${TARGET} PRIVATE common minicpmv ${CMAKE_THREAD_LIBS_INIT})
38+
target_compile_features(minicpmv PRIVATE cxx_std_17)

examples/minicpmv2.0/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 所有命令在 llama.cpp 根目录执行,模型位于根目录上级目录处
2+
# All command should be executed under the root path of llama.cpp repo. We assume the MiniCPM-V-2 model are put in its parent folder.
3+
4+
```bash
5+
make
6+
make minicpmv-cli
7+
8+
python ./examples/minicpmv/minicpm-surgery.py -m ../MiniCPM-V-2
9+
python ./examples/minicpmv/convert-image-encoder-to-gguf.py -m ../MiniCPM-V-2 --llava-projector ../MiniCPM-V-2/llava.projector --output-dir ../MiniCPM-V-2 --image-mean 0.5 0.5 0.5 --image-std 0.5 0.5 0.5
10+
python ./convert-hf-to-gguf.py ../MiniCPM-V-2/MiniCPM
11+
./minicpmv-cli -m ../MiniCPM-V-2/MiniCPM/ggml-model-f16.gguf --mmproj ../MiniCPM-V-2/mmproj-model-f16.gguf -c 4096 --temp 0.6 --top-p 0.8 --top-k 100 --repeat-penalty 1.0 --image ../test.jpg -p "这张图里有什么?"
12+
13+
# or run quantize int4 version
14+
./quantize ../MiniCPM-V-2/MiniCPM/ggml-model-f16.gguf ../MiniCPM-V-2/MiniCPM/ggml-model-Q4_K_M.gguf Q4_K_M
15+
./minicpmv-cli -m ../MiniCPM-V-2/MiniCPM/ggml-model-Q4_K_M.gguf --mmproj ../MiniCPM-V-2/mmproj-model-f16.gguf -c 4096 --temp 0.6 --top-p 0.8 --top-k 100 --repeat-penalty 1.0 --image ../test.jpg -p "这张图里有什么?"
16+
17+
# or run in interactive mode
18+
./minicpmv-cli -m ../MiniCPM-V-2/MiniCPM/ggml-model-Q4_K_M.gguf --mmproj ../MiniCPM-V-2/mmproj-model-f16.gguf -c 4096 --temp 0.6 --top-p 0.8 --top-k 100 --repeat-penalty 1.0 --image ../test.jpg -i
19+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
model_dir="/Users/cxt/model/llm/mobileVLM/MobileVLM-1.7B_processed"
4+
projector_name="mmproj-model-f16.gguf"
5+
llama_name="ggml-model-q4_k.gguf"
6+
img_dir="/Users/cxt/model/llm"
7+
img_name="demo.jpg"
8+
prompt="A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWho is the author of this book? \nAnswer the question using a single word or phrase. ASSISTANT:"
9+
# img_name="cat.jpeg"
10+
# prompt="A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: <image>\nWhat is in the image? ASSISTANT:"
11+
12+
program_dir="build_64/bin"
13+
binName="minicpmv-cli"
14+
n_threads=4
15+
16+
17+
deviceDir="/data/local/tmp"
18+
saveDir="output"
19+
if [ ! -d ${saveDir} ]; then
20+
mkdir ${saveDir}
21+
fi
22+
23+
24+
function android_run() {
25+
# # copy resource into device
26+
# adb push ${model_dir}/${projector_name} ${deviceDir}/${projector_name}
27+
# adb push ${model_dir}/${llama_name} ${deviceDir}/${llama_name}
28+
adb push ${img_dir}/${img_name} ${deviceDir}/${img_name}
29+
# copy program into device
30+
adb push ${program_dir}/${binName} ${deviceDir}/${binName}
31+
adb shell "chmod 0777 ${deviceDir}/${binName}"
32+
33+
# run
34+
adb shell "echo cd ${deviceDir} ${deviceDir}/${binName} \
35+
-m ${deviceDir}/${llama_name} \
36+
--mmproj ${deviceDir}/${projector_name} \
37+
-t ${n_threads} \
38+
--image ${deviceDir}/${img_name} \
39+
-p \"${prompt}\" \
40+
> ${deviceDir}/${modelName}_${projector_name}_${n_threads}_${img_name}.txt"
41+
adb shell "cd ${deviceDir}; pwd; ${deviceDir}/${binName} \
42+
-m ${deviceDir}/${llama_name} \
43+
--mmproj ${deviceDir}/${projector_name} \
44+
-t ${n_threads} \
45+
--image ${deviceDir}/${img_name} \
46+
-p \"${prompt}\" \
47+
>> ${deviceDir}/${modelName}_${projector_name}_${n_threads}_${img_name}.txt 2>&1"
48+
adb pull ${deviceDir}/${modelName}_${projector_name}_${n_threads}_${img_name}.txt ${saveDir}
49+
}
50+
51+
android_run
52+
53+
echo "android_run is Done!"

0 commit comments

Comments
 (0)