Skip to content

Commit

Permalink
[refactor] refactor build script and ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Jun 7, 2024
1 parent 0e39c2c commit 68273bd
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 458 deletions.
79 changes: 0 additions & 79 deletions .github/model-test.yml

This file was deleted.

74 changes: 0 additions & 74 deletions .github/workflows/all.yml

This file was deleted.

37 changes: 10 additions & 27 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,20 @@ jobs:
build:
name: linux-build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack

- name: build
run: |
./script/build.sh
./script/package.sh package
zip -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
test:
needs: build
name: ${{ matrix.model }}-linux-test
runs-on: ubuntu-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: download_mode
run: |
wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/qwen1.5-0.5b-chat-mnn/Qwen1.5-0.5B-Chat-MNN.zip
unzip Qwen1.5-0.5B-Chat-MNN.zip
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: model-test
- name: test_model
run: |
cd workspace
unzip package.zip
cd package
./script/model_test.sh ${{ matrix.model }}
cd build
./cli_demo ../Qwen1.5-0.5B-Chat-MNN/config.json ../resource/prompt.txt
37 changes: 10 additions & 27 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,20 @@ jobs:
build:
name: macos-build
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack

- name: build
run: |
./script/build.sh
./script/package.sh package
zip -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
test:
needs: build
name: ${{ matrix.model }}-macos-test
runs-on: macos-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: download_mode
run: |
wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/qwen1.5-0.5b-chat-mnn/Qwen1.5-0.5B-Chat-MNN.zip
unzip Qwen1.5-0.5B-Chat-MNN.zip
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: model-test
- name: test_model
run: |
cd workspace
unzip package.zip
cd package
./script/model_test.sh ${{ matrix.model }} prompt.txt
cd build
./cli_demo ../Qwen1.5-0.5B-Chat-MNN/config.json ../resource/prompt.txt
38 changes: 9 additions & 29 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,21 @@ jobs:
build:
name: windows-build
runs-on: windows-latest

steps:
- uses: actions/checkout@v3
# build
- name: build-pack

- name: build
run: |
.\script\build.ps1
.\script\package.ps1 package
7z a -r package.zip package
# upload
- name: upload-zip
uses: actions/upload-artifact@v3
with:
path: ./*.zip
test:
needs: build
name: ${{ matrix.model }}-windows-test
runs-on: windows-latest
strategy:
matrix:
model: [qwen-1.8b, chatglm-6b, chatglm2-6b, chatglm3-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
- name: download_mode
run: |
Invoke-WebRequest -Uri https://github.com/wangzhaode/mnn-llm/releases/download/qwen1.5-0.5b-chat-mnn/Qwen1.5-0.5B-Chat-MNN.zip -OutFile Qwen1.5-0.5B-Chat-MNN.zip
unzip Qwen1.5-0.5B-Chat-MNN.zip
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: workspace
- name: windows-test
- name: test_model
run: |
cd workspace
7z x package.zip
cd package
echo ${{ matrix.model }}
./script/download_model.ps1 ${{ matrix.model }}
cd build
.\Release\cli_demo ..\${{ matrix.model }} prompt.txt
.\Release\cli_demo ..\Qwen1.5-0.5B-Chat-MNN\config.json ..\resource\prompt.txt
Exit 0
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()

# include dir
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)
# compile MNN first
set(MNN_LOW_MEMORY ON CACHE BOOL "Open MNN_LOW_MEMORY" FORCE)
set(MNN_SUPPORT_TRANSFORMER_FUSE ON CACHE BOOL "Open MNN_SUPPORT_TRANSFORMER_FUSE" FORCE)
# set(MNN_ARM82 ON CACHE BOOL "Open MNN_ARM82" FORCE)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/MNN)

# libs dir
link_directories(${CMAKE_CURRENT_LIST_DIR}/libs)
# include dir
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/MNN/include/
${CMAKE_CURRENT_LIST_DIR}/MNN/tools/cv/include/cv/
)

# source files
FILE(GLOB SRCS ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
Expand Down Expand Up @@ -53,8 +59,8 @@ 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)
# add_library(MNN SHARED IMPORTED)
# add_library(MNN_Express SHARED IMPORTED)
set_target_properties(
MNN
PROPERTIES IMPORTED_LOCATION
Expand Down
Empty file removed libs/.gitkeep
Empty file.
16 changes: 1 addition & 15 deletions script/android_build.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# 1. clone MNN
git clone https://github.com/alibaba/MNN.git --depth=1

# 2. build MNN
cd MNN/project/android
mkdir build
cd build
../build_64.sh -DMNN_LOW_MEMORY=ON
cd ../../../..

# 3. copy headers and libs
cp -r MNN/include/MNN include
cp MNN/project/android/build/libMNN.so MNN/project/android/build/libMNN_Express.so libs

# 4. build mnn-llm android
mkdir android_build
cd android_build
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_STL=c++_static \
-DANDROID_ABI="arm64-v8a" \
-DANDROID_NATIVE_API_LEVEL=android-21 \
-DMNN_ARM82=ON \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_FOR_ANDROID=ON
make -j4
Expand Down
19 changes: 1 addition & 18 deletions script/build.ps1
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
# 1. clone MNN
git clone https://github.com/alibaba/MNN.git --depth=1

# 2. build MNN
cd MNN
mkdir build
cd build
cmake -DMNN_LOW_MEMORY=ON -DMNN_WIN_RUNTIME_MT=ON ..
cmake --build . --config Release -j 4
cd ../..

# 3. copy headers and libs
cp -r MNN\include\MNN include
cp MNN\build\Release\MNN.lib libs
cp MNN\build\Release\MNN.dll libs

# 4. copy pthread
Expand-Archive .\resource\win_pthreads.zip
cp .\win_pthreads\Pre-built.2\lib\x64\pthreadVC2.lib libs
cp .\win_pthreads\Pre-built.2\lib\x64\pthreadVC2.lib build
cp .\win_pthreads\Pre-built.2\include\*.h .\include\

# 5. build mnn-llm
mkdir build
cd build
cmake ..
cmake --build . --config Release -j 4
Expand Down
Loading

0 comments on commit 68273bd

Please sign in to comment.