Skip to content

Commit

Permalink
Merge pull request #2 from ZHEQIUSHUI/qt_ui
Browse files Browse the repository at this point in the history
Qt UI
  • Loading branch information
ZHEQIUSHUI authored Apr 24, 2024
2 parents c84a9a7 + 88ed688 commit 612e940
Show file tree
Hide file tree
Showing 29 changed files with 448,949 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ weights
.vscode
build*
tools/test.cpp
!build.sh
!build.sh
qtproj/LLM-Chat/CMakeLists.txt.user
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ endif()
cmake_minimum_required(VERSION 3.0)
project(LLAMA-AX650-CPP)

# 添加 FLAGS 检查代码是否有明显 bug
# include(cmake/overlook.cmake)
include(overlook.cmake)

add_compile_options(-std=c++17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


# bsp
if(NOT BSP_MSP_DIR)
set(BSP_MSP_DIR ${CMAKE_SOURCE_DIR}/bsp_msp_out/msp/out)
# 判断 /soc/lib/libax_engine.so 是否存在,以确定是否为板端编译
if(EXISTS /soc/lib/libax_engine.so)
message(STATUS "Detected board,BSP_MSP_DIR = /soc")
set(BSP_MSP_DIR /soc)
else()
set(BSP_MSP_DIR ${CMAKE_SOURCE_DIR}/bsp_msp_out/msp/out)
endif()
endif()
message(STATUS "BSP_MSP_DIR = ${BSP_MSP_DIR}")
include_directories(${BSP_MSP_DIR}/include)
Expand All @@ -44,6 +46,9 @@ include_directories(third_party/abseil-cpp)
include_directories(third_party/re2)
link_directories(${CMAKE_BINARY_DIR}/lib)

# 添加 FLAGS 检查代码是否有明显 bug
include(overlook.cmake)

include_directories(src)
include_directories(src/runner)
include_directories(src/runner/utils)
Expand All @@ -54,7 +59,8 @@ function(build_exec name main_source)
src/runner/utils/memory_utils.cpp
src/runner/utils/cqdm.cpp
src/runner/Tokenizer/Tokenizer.cpp
src/runner/Tokenizer/QwenTokenizer.cpp)
src/runner/Tokenizer/QwenTokenizer.cpp
src/runner/Tokenizer/chatglm.cpp)

target_link_libraries(${name} ax_engine ax_interpreter ax_sys ax_ivps)
target_link_libraries(${name} sentencepiece re2::re2)
Expand Down
75 changes: 75 additions & 0 deletions qtproj/LLM-Chat/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
cmake_minimum_required(VERSION 3.5)

project(LLM-Chat LANGUAGES CXX)

add_compile_options(-std=c++17)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(SPM_ENABLE_SHARED OFF)
add_subdirectory(third_party/sentencepiece)
include_directories(third_party/sentencepiece/src)
include_directories(third_party/sentencepiece/third_party/protobuf-lite)

set(ABSL_ENABLE_INSTALL ON)
set(ABSL_PROPAGATE_CXX_STD ON)
add_subdirectory(third_party/abseil-cpp)
add_subdirectory(third_party/re2)
include_directories(third_party/abseil-cpp)
include_directories(third_party/re2)
link_directories(${CMAKE_BINARY_DIR}/lib)

include_directories(src)
include_directories(src/runner)
include_directories(src/runner/utils)

# bsp
if(NOT BSP_MSP_DIR)
# 判断 /soc/lib/libax_engine.so 是否存在,以确定是否为板端编译
if(EXISTS /soc/lib/libax_engine.so)
message(STATUS "Detected board,BSP_MSP_DIR = /soc")
set(BSP_MSP_DIR /soc)
else()
set(BSP_MSP_DIR ${CMAKE_SOURCE_DIR}/bsp_msp_out/msp/out)
endif()
endif()

message(STATUS "BSP_MSP_DIR = ${BSP_MSP_DIR}")
include_directories(${BSP_MSP_DIR}/include)
link_directories(${BSP_MSP_DIR}/lib)

add_library(axllm STATIC
src/runner/ax_model_runner/ax_model_runner_ax650.cpp
src/runner/utils/memory_utils.cpp
src/runner/utils/cqdm.cpp
src/runner/Tokenizer/Tokenizer.cpp
src/runner/Tokenizer/QwenTokenizer.cpp
)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(Qt6 COMPONENTS Widgets)
if(Qt6_FOUND)
message(STATUS "Found Qt6")
set(QTWidget Qt6::Widgets)
else()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
set(QTWidget Qt5::Widgets)
endif()

add_executable(LLM-Chat
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
style/DarkStyle.cpp
)

target_link_libraries(LLM-Chat PRIVATE ${QTWidget})
target_link_libraries(LLM-Chat PRIVATE axllm)
target_link_libraries(LLM-Chat PRIVATE ax_engine ax_interpreter ax_sys ax_ivps)
target_link_libraries(LLM-Chat PRIVATE sentencepiece re2::re2)
24 changes: 24 additions & 0 deletions qtproj/LLM-Chat/SendTextEdit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <QTextEdit>
#include <QKeyEvent>

class SendTextEdit : public QTextEdit
{
Q_OBJECT
Q_SIGNALS:
void returnPressSignal();

public:
SendTextEdit(QWidget *parent) : QTextEdit(parent) {}

protected:
void keyReleaseEvent(QKeyEvent *e) override
{
if (e->key() == Qt::Key_Return)
{
emit returnPressSignal();
return;
}
}
};
65 changes: 65 additions & 0 deletions qtproj/LLM-Chat/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "mainwindow.h"
#include "style/DarkStyle.h"
#include <QApplication>
#include "src/runner/LLM.hpp"
#include "src/cmdline.hpp"

void llm_running_callback(int *p_token, int n_token, const char *p_str, float token_per_sec, void *reserve);

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QApplication::setStyle(new DarkStyle);
MainWindow w;

{
LLMAttrType attr;
attr.template_filename_axmodel = "tinyllama-bf16/tinyllama_l%d.axmodel";
attr.filename_post_axmodel = "tinyllama-bf16/tinyllama_post.axmodel";
attr.filename_tokenizer_model = "tokenizer.model";
attr.filename_tokens_embed = "tinyllama-bf16/tinyllama.model.embed_tokens.weight.bfloat16.bin";


cmdline::parser cmd;
cmd.add<std::string>("template_filename_axmodel", 0, "axmodel path template", false, attr.template_filename_axmodel);
cmd.add<std::string>("filename_post_axmodel", 0, "post axmodel path", false, attr.filename_post_axmodel);
cmd.add<int>("tokenizer_type", 0, "tokenizer type 0:LLaMa 1:Qwen", false, attr.tokenizer_type);
cmd.add<std::string>("filename_tokenizer_model", 0, "tokenizer model path", false, attr.filename_tokenizer_model);
cmd.add<std::string>("filename_tokens_embed", 0, "tokens embed path", false, attr.filename_tokens_embed);

cmd.add<bool>("bos", 0, "", false, attr.b_bos);
cmd.add<bool>("eos", 0, "", false, attr.b_eos);
cmd.add<int>("axmodel_num", 0, "num of axmodel(for template)", false, attr.axmodel_num);
cmd.add<int>("tokens_embed_num", 0, "tokens embed num", false, attr.tokens_embed_num);
cmd.add<int>("tokens_embed_size", 0, "tokens embed size", false, attr.tokens_embed_size);

cmd.add<bool>("use_mmap_load_embed", 0, "it can save os memory", false, attr.b_use_mmap_load_embed);
cmd.add<bool>("dynamic_load_axmodel_layer", 0, "it can save cmm memory", false, attr.b_dynamic_load_axmodel_layer);

cmd.parse_check(argc, argv);

attr.tokenizer_type = (TokenizerType)cmd.get<int>("tokenizer_type");
attr.filename_tokenizer_model = cmd.get<std::string>("filename_tokenizer_model");
attr.filename_tokens_embed = cmd.get<std::string>("filename_tokens_embed");
attr.filename_post_axmodel = cmd.get<std::string>("filename_post_axmodel");
attr.template_filename_axmodel = cmd.get<std::string>("template_filename_axmodel");
attr.b_bos = cmd.get<bool>("bos");
attr.b_eos = cmd.get<bool>("eos");
attr.axmodel_num = cmd.get<int>("axmodel_num");
attr.tokens_embed_num = cmd.get<int>("tokens_embed_num");
attr.tokens_embed_size = cmd.get<int>("tokens_embed_size");

attr.b_use_mmap_load_embed = cmd.get<bool>("use_mmap_load_embed");
attr.b_dynamic_load_axmodel_layer = cmd.get<bool>("dynamic_load_axmodel_layer");

attr.runing_callback = llm_running_callback;
attr.reserve = &w;
if (!w.InitLLM(attr))
{
return -1;
}
}

w.show();
return a.exec();
}
Loading

0 comments on commit 612e940

Please sign in to comment.