Skip to content

Commit

Permalink
just test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzhaode committed Sep 22, 2023
1 parent 582ea1a commit f142197
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 54 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/android-build.yml

This file was deleted.

18 changes: 9 additions & 9 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [windows-latest]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -55,8 +55,8 @@ jobs:
PACAGE_FILE: ${{ matrix.os }}-package.zip
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
model: [chatglm-6b, chatglm2-6b, codegeex2-6b, qwen-7b-chat, baichuan2-7b-chat, llama2-7b-chat]
os: [windows-latest]
model: [chatglm-6b]

steps:
- uses: actions/download-artifact@v3
Expand All @@ -70,16 +70,16 @@ jobs:
unzip $PACAGE_FILE
cd $PACAGE_DIR
./script/model_test.sh ${{ matrix.model }}
- name: windows-download
- name: windows-test
if: matrix.os == 'windows-latest'
run: |
cd workspace
7z x windows-package.zip
cd windows-package
ls
echo ${{ matrix.model }}
./script/model_download.ps1 ${{ matrix.model }}
- name: windows-test
if: matrix.os == 'windows-latest'
run: |
./script/download_model.ps1 ${{ matrix.model }}
ls
cd build
.\Release\cli_demo -m ..\${{ matrix.model }}
.\Release\cli_demo -m ..\${{ matrix.model }}
ls
15 changes: 9 additions & 6 deletions script/download_model.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ param(
)
mkdir $model
cd $model
wget -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/embedding.mnn -OutFile embedding.mnn
wget -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/lm.mnn -OutFile lm.mnn
for($i=1; $i -lt 32; $i=$i+1)
{
wget -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/block_$i.mnn -OutFile block_$i.mnn
$block_num = 28
if ($model.Contains('7b')) {
$block_num = 32
}
cd ..
Invoke-WebRequest -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/embedding.mnn -OutFile embedding.mnn
Invoke-WebRequest -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/lm.mnn -OutFile lm.mnn
for ($i=1; $i -lt $block_num; $i=$i+1) {
Invoke-WebRequest -Uri https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/block_$i.mnn -OutFile block_$i.mnn
}
cd ..
12 changes: 11 additions & 1 deletion script/download_model.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
if [ $# -lt 1 ]; then
echo 'Usage: ./download_model.sh $model'
exit 1
fi

model=$1
mkdir $model
cd $model
is_7b=`echo $model | grep '7b'`
block_num=27
if [ $is_7b ]; then
block_num=31
fi
# download models
wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/embedding.mnn
wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/lm.mnn
for i in `seq 0 31`
for i in `seq 0 $block_num`
do
wget -c -nv https://github.com/wangzhaode/mnn-llm/releases/download/$model-mnn/block_$i.mnn
done
Expand Down
9 changes: 9 additions & 0 deletions src/llm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ Llm* Llm::createLLM(const std::string& path) {
}

std::string Llm::response(const std::string& query, std::ostream* os) {
printf("response\n");
// init status
if (is_single_) {
key_value_shape_.insert(key_value_shape_.begin(), layer_nums_);
past_key_values_.push_back(_Input(key_value_shape_, NCHW));
} else {
for (int i = 0; i < layer_nums_; i++) {
printf("past_key_values_ %d\n", i);
fflush(stdout);
past_key_values_.push_back(_Input(key_value_shape_, NCHW));
}
}
Expand Down Expand Up @@ -225,6 +228,7 @@ int Llm::forward(const std::vector<int>& input_ids) {
}
all_seq_len_ += seq_len;
gen_seq_len_++;
printf("id = %d\n", id);
return id;
}

Expand All @@ -250,22 +254,26 @@ VARP Llm::gen_embedding(const std::vector<int>& input_ids) {
}

std::vector<int> Llm::tokenizer_encode(std::string input_str) {
printf("tokenizer_encode start\n");
std::vector<int> ids;
std::vector<std::string> words;
std::string dict_path = tokenizer_dir_ + "/jieba.dict.utf8";
std::string model_path = tokenizer_dir_ + "/hmm_model.utf8";
std::string user_dict_path = tokenizer_dir_ + "/user.dict.utf8";
std::string idf_path = tokenizer_dir_ + "/idf.utf8";
std::string stopWord_path = tokenizer_dir_ + "/stop_words.utf8";
printf("jieba init\n");
cppjieba::Jieba jieba(
dict_path,
model_path,
user_dict_path,
idf_path,
stopWord_path
);
printf("jieba Cut\n");
jieba.Cut(input_str, words, true);
for (auto word : words) {
printf("word = %s\n", word.c_str());
const auto& iter = word_encoder_.find(word);
if (iter != word_encoder_.end()) {
ids.push_back(iter->second);
Expand All @@ -290,6 +298,7 @@ std::vector<int> Chatglm_6b::tokenizer(const std::string& query) {
context_len_ = ids.size();
ids.push_back(130001);
ids.push_back(130004);
printf("ids = ["); for (auto id : ids) printf("%d, "); printf("]\n");
return ids;
}

Expand Down

0 comments on commit f142197

Please sign in to comment.