Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @tetherto/ai-runtime-bk-models
19 changes: 19 additions & 0 deletions .github/workflows/approval-check-worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Approval Check Worker

on:
pull_request_review:
types: [submitted, dismissed]

jobs:
check-approvals:
permissions:
contents: write
pull-requests: write
statuses: write
issues: write

uses: tetherto/qvac-devops/.github/workflows/approval-check-worker.yml@production-workflows-tag
secrets: inherit
with:
pr_number: ${{ github.event.pull_request.number }}
pr_sha: ${{ github.event.pull_request.head.sha }}
62 changes: 52 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ option(LLAMA_BUILD_COMMON "llama: build common utils library" ${LLAMA_STANDALONE
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
option(LLAMA_BUILD_TOOLS "llama: build tools" ${LLAMA_STANDALONE})
option(LLAMA_BUILD_EXAMPLES "llama: build examples" ${LLAMA_STANDALONE})
option(LLAMA_BUILD_SERVER "llama: build server example" ${LLAMA_STANDALONE})
option(LLAMA_BUILD_SERVER "llama: build server example" OFF)

# specific extras
option(LLAMA_MTMD "llama: multimodal support" OFF)

# 3rd party libs
option(LLAMA_CURL "llama: use libcurl to download model from an URL" ON)
Expand Down Expand Up @@ -192,6 +195,10 @@ if (LLAMA_BUILD_COMMON)
add_subdirectory(common)
endif()

if(LLAMA_BUILD_EXAMPLES OR LLAMA_BUILD_TESTS)
add_subdirectory(common_test)
endif()

if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TESTS AND NOT CMAKE_JS_VERSION)
include(CTest)
add_subdirectory(tests)
Expand All @@ -206,14 +213,18 @@ if (LLAMA_BUILD_COMMON AND LLAMA_BUILD_TOOLS)
add_subdirectory(tools)
endif()

if (LLAMA_MTMD)
add_subdirectory(tools/mtmd)
endif()

#
# install
#

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

set(LLAMA_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
set(LLAMA_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}/llama CACHE PATH "Location of header files")
set(LLAMA_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
set(LLAMA_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")

Expand All @@ -225,15 +236,46 @@ set_target_properties(llama
PROPERTIES
PUBLIC_HEADER "${LLAMA_PUBLIC_HEADERS}")

install(TARGETS llama LIBRARY PUBLIC_HEADER)
install(
TARGETS llama
EXPORT llama-targets
PUBLIC_HEADER
DESTINATION ${LLAMA_INCLUDE_INSTALL_DIR})

if (LLAMA_BUILD_COMMON)

install(
TARGETS common build_info
EXPORT llama-targets
PUBLIC_HEADER
DESTINATION ${LLAMA_INCLUDE_INSTALL_DIR}/common)

endif()

if (LLAMA_MTMD)

install(
TARGETS mtmd
EXPORT llama-targets
PUBLIC_HEADER
DESTINATION ${LLAMA_INCLUDE_INSTALL_DIR}/mtmd)

endif()

install(
EXPORT llama-targets
FILE llama-targets.cmake
NAMESPACE llama::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/llama)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/llama)

configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/llama-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llama
PATH_VARS LLAMA_INCLUDE_INSTALL_DIR
LLAMA_LIB_INSTALL_DIR
LLAMA_BIN_INSTALL_DIR )
${CMAKE_CURRENT_SOURCE_DIR}/cmake/llama-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/llama)

write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake
Expand All @@ -242,7 +284,7 @@ write_basic_package_version_file(

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/llama-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/llama-version.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/llama)
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/llama)

install(
FILES convert_hf_to_gguf.py
Expand Down
25 changes: 4 additions & 21 deletions cmake/llama-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@ set(LLAMA_SHARED_LIB @BUILD_SHARED_LIBS@)

@PACKAGE_INIT@

set_and_check(LLAMA_INCLUDE_DIR "@PACKAGE_LLAMA_INCLUDE_INSTALL_DIR@")
set_and_check(LLAMA_LIB_DIR "@PACKAGE_LLAMA_LIB_INSTALL_DIR@")
set_and_check(LLAMA_BIN_DIR "@PACKAGE_LLAMA_BIN_INSTALL_DIR@")
include(CMakeFindDependencyMacro)
find_dependency(ggml CONFIG REQUIRED)

find_package(ggml REQUIRED HINTS ${LLAMA_LIB_DIR}/cmake)
include("${CMAKE_CURRENT_LIST_DIR}/llama-targets.cmake")

find_library(llama_LIBRARY llama
REQUIRED
HINTS ${LLAMA_LIB_DIR}
NO_CMAKE_FIND_ROOT_PATH
)

add_library(llama UNKNOWN IMPORTED)
set_target_properties(llama
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LLAMA_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "ggml::ggml;ggml::ggml-base;"
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${llama_LIBRARY}"
INTERFACE_COMPILE_FEATURES c_std_90
POSITION_INDEPENDENT_CODE ON)

check_required_components(Llama)
check_required_components(llama)
40 changes: 27 additions & 13 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,43 @@ endif()

set(TARGET common)

set(${TARGET}_HEADERS
arg.h
base64.hpp
chat-parser.h
chat.h
common.h
console.h
json-partial.h
json-schema-to-grammar.h
log.h
ngram-cache.h
regex-partial.h
sampling.h
speculative.h
)

list(TRANSFORM ${TARGET}_HEADERS PREPEND ${CMAKE_SOURCE_DIR}/common/)

add_library(${TARGET} STATIC
arg.cpp
arg.h
base64.hpp
chat-parser.cpp
chat-parser.h
chat.cpp
chat.h
common.cpp
common.h
console.cpp
console.h
json-partial.cpp
json-partial.h
json-schema-to-grammar.cpp
llguidance.cpp
log.cpp
log.h
ngram-cache.cpp
ngram-cache.h
regex-partial.cpp
regex-partial.h
sampling.cpp
sampling.h
speculative.cpp
speculative.h
${${TARGET}_HEADERS}
)

set_target_properties(${TARGET} PROPERTIES PUBLIC_HEADER "${${TARGET}_HEADERS}")

if (BUILD_SHARED_LIBS)
set_target_properties(${TARGET} PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
Expand Down Expand Up @@ -133,7 +142,12 @@ if (LLAMA_LLGUIDANCE)
set(LLAMA_COMMON_EXTRA_LIBS ${LLAMA_COMMON_EXTRA_LIBS} llguidance ${LLGUIDANCE_PLATFORM_LIBS})
endif ()

target_include_directories(${TARGET} PUBLIC . ../vendor)
target_include_directories(
${TARGET}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/common$<SEMICOLON>${CMAKE_SOURCE_DIR}/vendor>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

target_compile_features (${TARGET} PUBLIC cxx_std_17)
target_link_libraries (${TARGET} PRIVATE ${LLAMA_COMMON_EXTRA_LIBS} PUBLIC llama Threads::Threads)

Expand Down
23 changes: 14 additions & 9 deletions common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,7 @@ std::string fs_get_cache_file(const std::string & filename) {
// Model utils
//

struct common_init_result common_init_from_params(common_params & params) {
common_init_result iparams;
auto mparams = common_model_params_to_llama(params);

llama_model * model = llama_model_load_from_file(params.model.path.c_str(), mparams);
if (model == NULL) {
LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.path.c_str());
return iparams;
}
struct common_init_result common_init_from_model_and_params(llama_model* model, common_init_result iparams, common_params & params) {

const llama_vocab * vocab = llama_model_get_vocab(model);

Expand Down Expand Up @@ -1074,6 +1066,19 @@ struct common_init_result common_init_from_params(common_params & params) {
return iparams;
}

struct common_init_result common_init_from_params(common_params & params) {
common_init_result iparams;
auto mparams = common_model_params_to_llama(params);

llama_model * model = llama_model_load_from_file(params.model.path.c_str(), mparams);
if (model == NULL) {
LOG_ERR("%s: failed to load model '%s'\n", __func__, params.model.path.c_str());
return iparams;
}

return common_init_from_model_and_params(model, std::move(iparams), params);
}

std::string get_model_endpoint() {
const char * model_endpoint_env = getenv("MODEL_ENDPOINT");
// We still respect the use of environment-variable "HF_ENDPOINT" for backward-compatibility.
Expand Down
2 changes: 2 additions & 0 deletions common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ struct common_init_result {
};

struct common_init_result common_init_from_params(common_params & params);
struct common_init_result common_init_from_model_and_params(llama_model * model, common_init_result iparams,
common_params & params);

struct llama_model_params common_model_params_to_llama ( common_params & params);
struct llama_context_params common_context_params_to_llama(const common_params & params);
Expand Down
15 changes: 15 additions & 0 deletions common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# common_test library for load_into_memory.h and uint8-buff-stream.h

set(TARGET llama-common-test)

add_library(${TARGET} INTERFACE)

target_include_directories(${TARGET} INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_compile_definitions(${TARGET} INTERFACE LLAMA_COMMON_TEST_HEADERS)

target_compile_features(${TARGET} INTERFACE cxx_std_17)

target_link_libraries(${TARGET} INTERFACE common)
Loading