Skip to content

Commit

Permalink
[feat] android demo support qwen2-vl.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Sep 18, 2024
1 parent 2858626 commit c69a39b
Show file tree
Hide file tree
Showing 26 changed files with 385 additions and 1,100 deletions.
113 changes: 62 additions & 51 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if (LLM_SUPPORT_VISION)
set(MNN_BUILD_OPENCV ON CACHE BOOL "Open MNN_BUILD_OPENCV" FORCE)
set(MNN_IMGCODECS ON CACHE BOOL "Open MNN_IMGCODECS" FORCE)
endif()

add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/MNN)

# include dir
Expand Down Expand Up @@ -63,58 +64,68 @@ endif()

if (NOT (BUILD_JNI))

add_executable(cli_demo ${CMAKE_CURRENT_LIST_DIR}/demo/cli_demo.cpp)
add_executable(tokenizer_demo ${CMAKE_CURRENT_LIST_DIR}/demo/tokenizer_demo.cpp)
add_executable(embedding_demo ${CMAKE_CURRENT_LIST_DIR}/demo/embedding_demo.cpp)
add_executable(store_demo ${CMAKE_CURRENT_LIST_DIR}/demo/store_demo.cpp)
add_executable(document_demo ${CMAKE_CURRENT_LIST_DIR}/demo/document_demo.cpp)
add_executable(memory_demo ${CMAKE_CURRENT_LIST_DIR}/demo/memory_demo.cpp)
add_executable(knowledge_demo ${CMAKE_CURRENT_LIST_DIR}/demo/knowledge_demo.cpp)
add_executable(pipeline_demo ${CMAKE_CURRENT_LIST_DIR}/demo/pipeline_demo.cpp)
add_executable(cli_demo ${CMAKE_CURRENT_LIST_DIR}/demo/cli_demo.cpp)
add_executable(tokenizer_demo ${CMAKE_CURRENT_LIST_DIR}/demo/tokenizer_demo.cpp)
add_executable(embedding_demo ${CMAKE_CURRENT_LIST_DIR}/demo/embedding_demo.cpp)
add_executable(store_demo ${CMAKE_CURRENT_LIST_DIR}/demo/store_demo.cpp)
add_executable(document_demo ${CMAKE_CURRENT_LIST_DIR}/demo/document_demo.cpp)
add_executable(memory_demo ${CMAKE_CURRENT_LIST_DIR}/demo/memory_demo.cpp)
add_executable(knowledge_demo ${CMAKE_CURRENT_LIST_DIR}/demo/knowledge_demo.cpp)
add_executable(pipeline_demo ${CMAKE_CURRENT_LIST_DIR}/demo/pipeline_demo.cpp)

if (BUILD_FOR_ANDROID)
# add_library(MNN SHARED IMPORTED)
# add_library(MNN_Express SHARED IMPORTED)
set_target_properties(
MNN
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/libs/libMNN.so
)
set_target_properties(
MNN_Express
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/libs/libMNN_Express.so
)
target_link_libraries(cli_demo llm log)
target_link_libraries(tokenizer_demo llm log)
target_link_libraries(embedding_demo llm log)
target_link_libraries(store_demo llm log)
target_link_libraries(document_demo llm log)
target_link_libraries(memory_demo llm log)
target_link_libraries(knowledge_demo llm log)
target_link_libraries(pipeline_demo llm log)
else()
target_link_libraries(cli_demo llm)
target_link_libraries(tokenizer_demo llm)
target_link_libraries(embedding_demo llm)
target_link_libraries(store_demo llm)
target_link_libraries(document_demo llm)
target_link_libraries(memory_demo llm)
target_link_libraries(knowledge_demo llm)
target_link_libraries(pipeline_demo llm)
# web demo
add_executable(web_demo ${CMAKE_CURRENT_LIST_DIR}/demo/web_demo.cpp)
if (MSVC)
target_link_libraries(web_demo llm pthreadVC2)
add_custom_command(
TARGET cli_demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/build/MNN/Release/MNN.dll
$<TARGET_FILE_DIR:cli_demo>
)
if (BUILD_FOR_ANDROID)
# add_library(MNN SHARED IMPORTED)
# add_library(MNN_Express SHARED IMPORTED)
set_target_properties(
MNN
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/libs/libMNN.so
)
set_target_properties(
MNN_Express
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/libs/libMNN_Express.so
)
target_link_libraries(cli_demo llm log)
target_link_libraries(tokenizer_demo llm log)
target_link_libraries(embedding_demo llm log)
target_link_libraries(store_demo llm log)
target_link_libraries(document_demo llm log)
target_link_libraries(memory_demo llm log)
target_link_libraries(knowledge_demo llm log)
target_link_libraries(pipeline_demo llm log)
else()
target_link_libraries(web_demo llm pthread)
target_link_libraries(cli_demo llm)
target_link_libraries(tokenizer_demo llm)
target_link_libraries(embedding_demo llm)
target_link_libraries(store_demo llm)
target_link_libraries(document_demo llm)
target_link_libraries(memory_demo llm)
target_link_libraries(knowledge_demo llm)
target_link_libraries(pipeline_demo llm)
# web demo
add_executable(web_demo ${CMAKE_CURRENT_LIST_DIR}/demo/web_demo.cpp)
if (MSVC)
target_link_libraries(web_demo llm pthreadVC2)
add_custom_command(
TARGET cli_demo POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/build/MNN/Release/MNN.dll
$<TARGET_FILE_DIR:cli_demo>
)
else()
target_link_libraries(web_demo llm pthread)
endif()
endif()
endif()

else()
set(LLM_LIBS "")
list(APPEND LLM_LIBS $<TARGET_FILE:MNN>)
list(APPEND LLM_LIBS $<TARGET_FILE:MNN_Express>)
if (LLM_SUPPORT_VISION)
list(APPEND LLM_LIBS $<TARGET_FILE:MNNOpenCV>)
endif()
add_custom_command(TARGET llm POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${LLM_LIBS}
${CMAKE_CURRENT_LIST_DIR}/android/app/src/main/jni/libs)
endif()
2 changes: 1 addition & 1 deletion android/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments "-DBUILD_JNI=TRUE", "-DANDROID_STL=c++_shared"
arguments "-DBUILD_JNI=TRUE", "-DANDROID_STL=c++_shared", "-DLLM_SUPPORT_VISION=TRUE"
abiFilters 'arm64-v8a'
}
}
Expand Down
5 changes: 0 additions & 5 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
android:screenOrientation= "portrait"
android:theme="@style/AppTheme.Trans">
</activity>
<activity
android:name=".DownloadModel"
android:screenOrientation= "portrait"
android:theme="@style/AppTheme.Trans">
</activity>
</application>

<uses-permission android:name="android.permission.INTERNET"/>
Expand Down
2 changes: 0 additions & 2 deletions android/app/src/main/java/com/mnn/llm/Chat.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public class Chat implements Serializable {
public native boolean Init(String modelDir);
public native boolean Ready();
public native float Progress();
public native String Submit(String input);
public native byte[] Response();
public native void Done();
Expand Down
Loading

0 comments on commit c69a39b

Please sign in to comment.