-
Notifications
You must be signed in to change notification settings - Fork 1
llama integration with exception safety #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
295bf64
430c854
63546cc
04443d2
ce6c8ba
4048bb7
f591e3f
8d75dd4
f1269f9
12c195a
b9e36fe
fd4e8a7
51412ae
535b884
5e7068f
6bcba54
937b6d3
61b6b0f
f55e5ab
eed0fda
ea10198
19b79a6
2c42539
2e07529
17f5457
53760c7
b38aa2d
183b577
89da06d
b80e807
e8a0078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,5 @@ version.h | |
| ports/docwire/.disable_binary_cache | ||
| .cache | ||
| compile_commands.json | ||
| .zed | ||
| .clang-format | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to modify/parametrize build.sh/build.ps1 instead of creating another script. If this is only for you that it should not be added to the repository. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #!/usr/bin/env bash | ||
| set -e # stop on first error | ||
|
|
||
| # ========================== | ||
| # CONFIGURATION — adjust paths | ||
| # ========================== | ||
| VCPKG_TOOLCHAIN=/home/reeshabh/coderepos/docwire/vcpkg/scripts/buildsystems/vcpkg.cmake | ||
| VCPKG_TRIPLET=x64-linux-dynamic | ||
| DOCWIRE_DIR=/home/reeshabh/coderepos/docwire/vcpkg/installed/x64-linux-dynamic/share/docwire | ||
| BUILD_DIR=./build | ||
| DEMO_EXEC=demo | ||
|
|
||
|
|
||
| # ========================== | ||
| # CLEAN BUILD | ||
| # ========================== | ||
| echo "Cleaning old build folder..." | ||
| rm -rf "$BUILD_DIR" | ||
| mkdir "$BUILD_DIR" | ||
| cd "$BUILD_DIR" | ||
|
|
||
| # ========================== | ||
| # CONFIGURE CMAKE | ||
| # ========================== | ||
| echo "Configuring CMake..." | ||
| cmake .. \ | ||
| -DCMAKE_TOOLCHAIN_FILE="$VCPKG_TOOLCHAIN" \ | ||
| -DVCPKG_TARGET_TRIPLET="$VCPKG_TRIPLET" \ | ||
| -Ddocwire_DIR="$DOCWIRE_DIR" \ | ||
| -DCMAKE_EXPORT_COMPILE_COMMANDS=ON | ||
|
|
||
| # ========================== | ||
| # BUILD | ||
| # ========================== | ||
| echo "Building project..." | ||
| cmake --build . | ||
|
|
||
| # ========================== | ||
| # SET LIBRARY PATH | ||
| # ========================== | ||
| export LD_LIBRARY_PATH=/home/reeshabh/coderepos/docwire/vcpkg/installed/x64-linux-dynamic/lib:$LD_LIBRARY_PATH | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RPATH is better on Linux/MacOS than LD_LIBRARY_PATH |
||
|
|
||
| # ========================== | ||
| # RUN DEMO | ||
| # ========================== | ||
| # echo "Running demo..." | ||
| # ./$DEMO_EXEC | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shell script is not good because of Windows. You would have to have two scripts: sh and ps1. What should be considered is downloading in CMake script (FetchContent etc) or using vcpkg ports. Currently we use vcpkg but this is open for discussion (can change in the future).
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, we will discuss, whether we auto download via vcpkg or let the user manage the model themselves. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| # Configurable defaults | ||
|
|
||
| MODEL_NAME="${MODEL_NAME:-qwen2-7b-instruct}" | ||
| MODEL_QUANT="${MODEL_QUANT:-q4_k_m}" | ||
| MODEL_REPO="${MODEL_REPO:-Qwen/Qwen2-7B-Instruct-GGUF}" | ||
|
|
||
| # Derived values | ||
| MODEL_FILE="${MODEL_NAME}.${MODEL_QUANT}.gguf" | ||
| OUTPUT_DIR="${OUTPUT_DIR:-models}" | ||
| HF_URL="https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILE}" | ||
|
|
||
| # Checks | ||
| if ! command -v wget &> /dev/null && ! command -v curl &> /dev/null; then | ||
| echo "Error: Neither wget nor curl is installed." | ||
| exit 1 | ||
| fi | ||
|
|
||
| mkdir -p "${OUTPUT_DIR}" | ||
| cd "${OUTPUT_DIR}" | ||
|
|
||
| if [ -f "${MODEL_FILE}" ]; then | ||
| echo "Model already exists: ${OUTPUT_DIR}/${MODEL_FILE}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Downloading model:" | ||
| echo " Repository : ${MODEL_REPO}" | ||
| echo " File : ${MODEL_FILE}" | ||
| echo " Destination: ${OUTPUT_DIR}" | ||
| echo "" | ||
|
|
||
| # Download | ||
|
|
||
| if command -v wget &> /dev/null; then | ||
| wget -c "${HF_URL}" | ||
| else | ||
| curl -L -C - -o "${MODEL_FILE}" "${HF_URL}" | ||
| fi | ||
|
|
||
| echo "" | ||
| echo "Download complete." | ||
| echo "Model saved to: ${OUTPUT_DIR}/${MODEL_FILE}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| set(MODEL_NAME "qwen2-7b-instruct") | ||
| set(MODEL_QUANT "q4_k_m") | ||
|
|
||
| set(MODEL_FILE "${MODEL_NAME}-${MODEL_QUANT}.gguf") | ||
|
reeshabh90 marked this conversation as resolved.
|
||
|
|
||
| vcpkg_download_distfile( | ||
| MODEL_ARCHIVE | ||
| URLS "https://huggingface.co/Qwen/Qwen2-7B-Instruct-GGUF/resolve/main/${MODEL_FILE}" | ||
| FILENAME "${MODEL_FILE}" | ||
| SHA512 39c1f9702856cf5faff13b672033c5c99246b5393550ed58ab9ba0eb2d5ce5d50cc2710b2d9f08d51ad6ce7f6b66826f5c916128fa06c3ac2f78865e167146b8 | ||
| ) | ||
|
|
||
| file(INSTALL | ||
| ${MODEL_ARCHIVE} | ||
| DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} | ||
| ) | ||
|
|
||
| file(WRITE | ||
| ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright | ||
| "Model weights from HuggingFace repository Qwen/Qwen2-7B-Instruct-GGUF." | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "qwen2-7b-instruct-q4-k-m", | ||
| "version": "1.0.0", | ||
| "description": "Qwen2 7B Instruct GGUF model", | ||
| "homepage": "https://huggingface.co/Qwen/Qwen2-7B-Instruct-GGUF", | ||
| "license": "Apache-2.0" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,19 @@ include(ocr.cmake) | |
| include(mail.cmake) | ||
| include(archives.cmake) | ||
| include(ai.cmake) | ||
| include(local_ai.cmake) | ||
|
|
||
| if(DOCWIRE_LOCAL_CT2) | ||
| include(ai_ct2.cmake) | ||
|
reeshabh90 marked this conversation as resolved.
|
||
| endif() | ||
|
|
||
| if(DOCWIRE_LLAMA) | ||
| include(ai_llama.cmake) | ||
| endif() | ||
|
|
||
| if(DOCWIRE_LOCAL_CT2 OR DOCWIRE_LLAMA) | ||
| include(local_ai.cmake) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should be included always because user can bring his own implementation
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but, I will cross verify this on my local build. |
||
| endif() | ||
|
|
||
| include(fuzzy_match.cmake) | ||
| include(content_type.cmake) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
|
|
||
| message(STATUS "DOCWIRE_LOCAL_CT2 enabled: Building CT2 backend.") | ||
|
|
||
| add_library(docwire_ai_ct2 SHARED ct2_runner.cpp tokenizer.cpp) | ||
|
|
||
| target_compile_definitions(docwire_ai_ct2 PUBLIC DOCWIRE_LOCAL_CT2) | ||
|
|
||
| find_package(Boost REQUIRED COMPONENTS filesystem system json) | ||
| find_package(ctranslate2 CONFIG REQUIRED) | ||
| find_library(sentencepiece_LIBRARIES sentencepiece REQUIRED) | ||
|
|
||
| if(MSVC) | ||
| find_package(absl CONFIG REQUIRED) | ||
| list(APPEND sentencepiece_LIBRARIES | ||
| absl::strings | ||
| absl::flags | ||
| absl::flags_parse | ||
| absl::log | ||
| absl::check) | ||
|
|
||
| find_package(protobuf CONFIG REQUIRED) | ||
| list(APPEND sentencepiece_LIBRARIES protobuf::libprotobuf-lite) | ||
| endif() | ||
|
|
||
| target_link_libraries(docwire_ai_ct2 PRIVATE docwire_core docwire_ai Boost::filesystem Boost::system Boost::json CTranslate2::ctranslate2 ${sentencepiece_LIBRARIES}) | ||
|
|
||
| docwire_find_resource(FLAN_T5_FULL_PATH REL_PATH "flan-t5-large-ct2-int8" REQUIRED) | ||
| docwire_target_resources(docwire_ai_ct2 "flan-t5-large-ct2-int8" SOURCE "${FLAN_T5_FULL_PATH}") | ||
|
|
||
| docwire_find_resource(E5_MODEL_FULL_PATH REL_PATH "multilingual-e5-small-ct2-int8" REQUIRED) | ||
| docwire_target_resources(docwire_ai_ct2 "multilingual-e5-small-ct2-int8" SOURCE "${E5_MODEL_FULL_PATH}") | ||
|
|
||
| if(MSVC) | ||
| install(FILES $<TARGET_PDB_FILE:docwire_ai_ct2> DESTINATION bin CONFIGURATIONS Debug) | ||
| endif() | ||
|
|
||
| include(GenerateExportHeader) | ||
|
|
||
| generate_export_header(docwire_ai_ct2 EXPORT_FILE_NAME ai_ct2_export.h) | ||
|
|
||
| target_include_directories(docwire_ai_ct2 PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
| $<INSTALL_INTERFACE:include/docwire> | ||
| ) | ||
|
|
||
| install(TARGETS docwire_ai_ct2 EXPORT docwire_targets) | ||
|
|
||
| install(FILES | ||
| ${CMAKE_CURRENT_BINARY_DIR}/ai_ct2_export.h | ||
| DESTINATION include/docwire | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.