From ae91bfa48a640a169a334e45495deb8f19872cef Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Mon, 10 Apr 2023 16:33:14 -0400 Subject: [PATCH] Fixes for linux and macosx. --- CMakeLists.txt | 12 ++++++++++-- gptj.cpp | 2 +- llm.cpp | 12 ++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e1108cc..cb086a06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,13 +45,21 @@ install(TARGETS chat DESTINATION bin COMPONENT ${COMPONENT_NAME_MAIN}) set(CPACK_GENERATOR "IFW") -if (WIN32) +if(${CMAKE_SYSTEM_NAME} MATCHES Linux) + find_program(LINUXDEPLOYQT linuxdeployqt HINTS ${_qt_bin_dir}) + message(AUTHOR_WARNING "heeeeeee ${LINUXDEPLOYQT}") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deploy-qt-linux.cmake.in" + "${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake" @ONLY) + set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-linux.cmake) + set(CPACK_IFW_ROOT "~/Qt/Tools/QtInstallerFramework/4.5") +elseif(${CMAKE_SYSTEM_NAME} MATCHES Windows) find_program(WINDEPLOYQT windeployqt HINTS ${_qt_bin_dir}) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/deploy-qt-windows.cmake.in" "${CMAKE_BINARY_DIR}/cmake/deploy-qt-windows.cmake" @ONLY) set(CPACK_PRE_BUILD_SCRIPTS ${CMAKE_BINARY_DIR}/cmake/deploy-qt-windows.cmake) set(CPACK_IFW_ROOT "C:/Qt/Tools/QtInstallerFramework/4.5") -endif (WIN32) +elseif(${CMAKE_SYSTEM_NAME} MATCHES Darwin) +endif() set(CPACK_PACKAGE_VERSION_MAJOR "0") set(CPACK_PACKAGE_VERSION_MINOR "1") diff --git a/gptj.cpp b/gptj.cpp index ee29538b..9a7720bc 100644 --- a/gptj.cpp +++ b/gptj.cpp @@ -650,7 +650,7 @@ bool GPTJ::loadModel(const std::string &modelPath, std::istream &fin) { // load the model if (!gptj_model_load(modelPath, fin, d_ptr->model, d_ptr->vocab)) { - std::cerr << "GPT-J ERROR: failed to load model from" << modelPath; + std::cerr << "GPT-J ERROR: failed to load model from " << modelPath; return false; } diff --git a/llm.cpp b/llm.cpp index 1bf4e287..acd8cefd 100644 --- a/llm.cpp +++ b/llm.cpp @@ -4,6 +4,7 @@ #include #include #include +#include class MyLLM: public LLM { }; Q_GLOBAL_STATIC(MyLLM, llmInstance) @@ -28,13 +29,12 @@ bool GPTJObject::loadModel() return true; QString modelName("ggml-model-q4_0.bin"); - QFile file(QCoreApplication::applicationDirPath() + QDir::separator() + modelName); - if (file.open(QIODevice::ReadOnly)) { + QString fileName = QCoreApplication::applicationDirPath() + QDir::separator() + modelName; + QFile file(fileName); + if (file.exists()) { - QByteArray data = file.readAll(); - std::istringstream iss(data.toStdString()); - - m_gptj->loadModel(modelName.toStdString(), iss); + auto fin = std::ifstream(fileName.toStdString(), std::ios::binary); + m_gptj->loadModel(modelName.toStdString(), fin); emit isModelLoadedChanged(); }