cmake : do not include ./src as public for libllama (#13062)

* cmake : do not include ./src as public for libllama

ggml-ci

* cmake : rework tests

ggml-ci

* llguidance : remove unicode include

ggml-ci

* cmake : make c++17 private

ggml-ci
This commit is contained in:
Georgi Gerganov
2025-04-24 16:00:10 +03:00
committed by GitHub
parent 572b3141d3
commit 13b4548877
17 changed files with 64 additions and 69 deletions

View File

@ -994,7 +994,6 @@ static void common_params_print_completion(common_params_context & ctx_arg) {
"llama-embedding", "llama-embedding",
"llama-eval-callback", "llama-eval-callback",
"llama-export-lora", "llama-export-lora",
"llama-gbnf-validator",
"llama-gen-docs", "llama-gen-docs",
"llama-gguf", "llama-gguf",
"llama-gguf-hash", "llama-gguf-hash",
@ -1014,7 +1013,6 @@ static void common_params_print_completion(common_params_context & ctx_arg) {
"llama-perplexity", "llama-perplexity",
"llama-q8dot", "llama-q8dot",
"llama-quantize", "llama-quantize",
"llama-quantize-stats",
"llama-qwen2vl-cli", "llama-qwen2vl-cli",
"llama-retrieval", "llama-retrieval",
"llama-run", "llama-run",

View File

@ -21,11 +21,6 @@ else()
add_subdirectory(embedding) add_subdirectory(embedding)
add_subdirectory(eval-callback) add_subdirectory(eval-callback)
if (NOT WIN32)
# disabled on Windows because it uses internal functions not exported with LLAMA_API
add_subdirectory(gbnf-validator)
endif()
add_subdirectory(gguf-hash) add_subdirectory(gguf-hash)
add_subdirectory(gguf-split) add_subdirectory(gguf-split)
add_subdirectory(gguf) add_subdirectory(gguf)
@ -58,10 +53,6 @@ else()
add_subdirectory(convert-llama2c-to-ggml) add_subdirectory(convert-llama2c-to-ggml)
add_subdirectory(cvector-generator) add_subdirectory(cvector-generator)
add_subdirectory(export-lora) add_subdirectory(export-lora)
if (NOT WIN32)
# disabled on Windows because it uses internal functions not exported with LLAMA_API
add_subdirectory(quantize-stats)
endif()
add_subdirectory(llava) add_subdirectory(llava)
if (GGML_RPC) if (GGML_RPC)
add_subdirectory(rpc) add_subdirectory(rpc)

View File

@ -1,5 +0,0 @@
set(TARGET llama-gbnf-validator)
add_executable(${TARGET} gbnf-validator.cpp)
install(TARGETS ${TARGET} RUNTIME)
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
target_compile_features(${TARGET} PRIVATE cxx_std_17)

View File

@ -1,6 +0,0 @@
set(TARGET llama-quantize-stats)
add_executable(${TARGET} quantize-stats.cpp)
install(TARGETS ${TARGET} RUNTIME)
target_link_libraries(${TARGET} PRIVATE llama build_info ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(${TARGET} PRIVATE ../../common)
target_compile_features(${TARGET} PRIVATE cxx_std_17)

View File

@ -112,7 +112,7 @@ You can use GBNF grammars:
- In [llama-server](../examples/server)'s completion endpoints, passed as the `grammar` body field - In [llama-server](../examples/server)'s completion endpoints, passed as the `grammar` body field
- In [llama-cli](../examples/main), passed as the `--grammar` & `--grammar-file` flags - In [llama-cli](../examples/main), passed as the `--grammar` & `--grammar-file` flags
- With [llama-gbnf-validator](../examples/gbnf-validator) tool, to test them against strings. - With [test-gbnf-validator](../tests/test-gbnf-validator.cpp), to test them against strings.
## JSON Schemas → GBNF ## JSON Schemas → GBNF

View File

@ -32,8 +32,9 @@ add_library(llama
unicode.h unicode.h
) )
target_include_directories(llama PUBLIC . ../include) target_include_directories(llama PRIVATE .)
target_compile_features (llama PUBLIC cxx_std_17) # don't bump target_include_directories(llama PUBLIC ../include)
target_compile_features (llama PRIVATE cxx_std_17) # don't bump
target_link_libraries(llama PUBLIC ggml) target_link_libraries(llama PUBLIC ggml)

View File

@ -1,5 +1,17 @@
llama_add_compile_flags() llama_add_compile_flags()
function(llama_build source)
if (DEFINED LLAMA_TEST_NAME)
set(TEST_TARGET ${LLAMA_TEST_NAME})
else()
get_filename_component(TEST_TARGET ${source} NAME_WE)
endif()
add_executable(${TEST_TARGET} ${source})
target_link_libraries(${TEST_TARGET} PRIVATE common)
install(TARGETS ${TEST_TARGET} RUNTIME)
endfunction()
function(llama_test target) function(llama_test target)
include(CMakeParseArguments) include(CMakeParseArguments)
set(options) set(options)
@ -36,7 +48,7 @@ endfunction()
# - LABEL: label for the test (defaults to main) # - LABEL: label for the test (defaults to main)
# - ARGS: arguments to pass to the test executable # - ARGS: arguments to pass to the test executable
# - WORKING_DIRECTORY # - WORKING_DIRECTORY
function(llama_target_and_test source) function(llama_build_and_test source)
include(CMakeParseArguments) include(CMakeParseArguments)
set(options) set(options)
set(oneValueArgs NAME LABEL WORKING_DIRECTORY) set(oneValueArgs NAME LABEL WORKING_DIRECTORY)
@ -58,6 +70,7 @@ function(llama_target_and_test source)
add_executable(${TEST_TARGET} ${source} get-model.cpp) add_executable(${TEST_TARGET} ${source} get-model.cpp)
install(TARGETS ${TEST_TARGET} RUNTIME) install(TARGETS ${TEST_TARGET} RUNTIME)
target_link_libraries(${TEST_TARGET} PRIVATE common) target_link_libraries(${TEST_TARGET} PRIVATE common)
add_test( add_test(
NAME ${TEST_TARGET} NAME ${TEST_TARGET}
WORKING_DIRECTORY ${LLAMA_TEST_WORKING_DIRECTORY} WORKING_DIRECTORY ${LLAMA_TEST_WORKING_DIRECTORY}
@ -68,9 +81,7 @@ function(llama_target_and_test source)
endfunction() endfunction()
# build test-tokenizer-0 target once and add many tests # build test-tokenizer-0 target once and add many tests
add_executable(test-tokenizer-0 test-tokenizer-0.cpp) llama_build(test-tokenizer-0.cpp)
target_link_libraries(test-tokenizer-0 PRIVATE common)
install(TARGETS test-tokenizer-0 RUNTIME)
llama_test(test-tokenizer-0 NAME test-tokenizer-0-bert-bge ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-bert-bge.gguf) llama_test(test-tokenizer-0 NAME test-tokenizer-0-bert-bge ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-bert-bge.gguf)
llama_test(test-tokenizer-0 NAME test-tokenizer-0-command-r ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-command-r.gguf) llama_test(test-tokenizer-0 NAME test-tokenizer-0-command-r ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-command-r.gguf)
@ -87,27 +98,27 @@ llama_test(test-tokenizer-0 NAME test-tokenizer-0-refact ARGS ${CMAKE
llama_test(test-tokenizer-0 NAME test-tokenizer-0-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf) llama_test(test-tokenizer-0 NAME test-tokenizer-0-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
if (LLAMA_LLGUIDANCE) if (LLAMA_LLGUIDANCE)
llama_target_and_test(test-grammar-llguidance.cpp ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-bpe.gguf) llama_build_and_test(test-grammar-llguidance.cpp ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-bpe.gguf)
endif () endif ()
if (NOT WIN32) if (NOT WIN32)
# these tests are disabled on Windows because they use internal functions not exported with LLAMA_API # these tests are disabled on Windows because they use internal functions not exported with LLAMA_API
llama_target_and_test(test-sampling.cpp) llama_build_and_test(test-sampling.cpp)
llama_target_and_test(test-grammar-parser.cpp) llama_build_and_test(test-grammar-parser.cpp)
llama_target_and_test(test-grammar-integration.cpp) llama_build_and_test(test-grammar-integration.cpp)
llama_target_and_test(test-llama-grammar.cpp) llama_build_and_test(test-llama-grammar.cpp)
llama_target_and_test(test-chat.cpp) llama_build_and_test(test-chat.cpp)
# TODO: disabled on loongarch64 because the ggml-ci node lacks Python 3.8 # TODO: disabled on loongarch64 because the ggml-ci node lacks Python 3.8
if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64") if (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
llama_target_and_test(test-json-schema-to-grammar.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) llama_build_and_test(test-json-schema-to-grammar.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
target_include_directories(test-json-schema-to-grammar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../examples/server) target_include_directories(test-json-schema-to-grammar PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../examples/server)
endif() endif()
llama_build(test-quantize-stats.cpp)
llama_build(test-gbnf-validator.cpp)
# build test-tokenizer-1-bpe target once and add many tests # build test-tokenizer-1-bpe target once and add many tests
add_executable(test-tokenizer-1-bpe test-tokenizer-1-bpe.cpp) llama_build(test-tokenizer-1-bpe.cpp)
target_link_libraries(test-tokenizer-1-bpe PRIVATE common)
install(TARGETS test-tokenizer-1-bpe RUNTIME)
# TODO: disabled due to slowness # TODO: disabled due to slowness
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-aquila ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-aquila.gguf) #llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-aquila ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-aquila.gguf)
@ -120,37 +131,35 @@ if (NOT WIN32)
#llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf) #llama_test(test-tokenizer-1-bpe NAME test-tokenizer-1-starcoder ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-starcoder.gguf)
# build test-tokenizer-1-spm target once and add many tests # build test-tokenizer-1-spm target once and add many tests
add_executable(test-tokenizer-1-spm test-tokenizer-1-spm.cpp) llama_build(test-tokenizer-1-spm.cpp)
target_link_libraries(test-tokenizer-1-spm PRIVATE common)
install(TARGETS test-tokenizer-1-spm RUNTIME)
llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-llama-spm ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-spm.gguf) llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-llama-spm ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-llama-spm.gguf)
#llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-baichuan ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf) #llama_test(test-tokenizer-1-spm NAME test-tokenizer-1-baichuan ARGS ${CMAKE_CURRENT_SOURCE_DIR}/../models/ggml-vocab-baichuan.gguf)
# llama_target_and_test(test-double-float.cpp) # SLOW # llama_build_and_test(test-double-float.cpp) # SLOW
endif() endif()
llama_target_and_test(test-log.cpp) llama_build_and_test(test-log.cpp)
llama_target_and_test(test-chat-template.cpp) llama_build_and_test(test-chat-template.cpp)
# this fails on windows (github hosted runner) due to curl DLL not found (exit code 0xc0000135) # this fails on windows (github hosted runner) due to curl DLL not found (exit code 0xc0000135)
if (NOT WIN32) if (NOT WIN32)
llama_target_and_test(test-arg-parser.cpp) llama_build_and_test(test-arg-parser.cpp)
endif() endif()
# llama_target_and_test(test-opt.cpp) # SLOW # llama_build_and_test(test-opt.cpp) # SLOW
llama_target_and_test(test-gguf.cpp) llama_build_and_test(test-gguf.cpp)
llama_target_and_test(test-backend-ops.cpp) llama_build_and_test(test-backend-ops.cpp)
llama_target_and_test(test-model-load-cancel.cpp LABEL "model") llama_build_and_test(test-model-load-cancel.cpp LABEL "model")
llama_target_and_test(test-autorelease.cpp LABEL "model") llama_build_and_test(test-autorelease.cpp LABEL "model")
if (NOT GGML_BACKEND_DL) if (NOT GGML_BACKEND_DL)
# these tests use the backends directly and cannot be built with dynamic loading # these tests use the backends directly and cannot be built with dynamic loading
llama_target_and_test(test-barrier.cpp) llama_build_and_test(test-barrier.cpp)
llama_target_and_test(test-quantize-fns.cpp) llama_build_and_test(test-quantize-fns.cpp)
llama_target_and_test(test-quantize-perf.cpp) llama_build_and_test(test-quantize-perf.cpp)
llama_target_and_test(test-rope.cpp) llama_build_and_test(test-rope.cpp)
endif() endif()

View File

@ -11,8 +11,9 @@
#include <string> #include <string>
#include "chat.h" #include "chat.h"
#include "llama-grammar.h"
#include "unicode.h" #include "../src/unicode.h"
#include "../src/llama-grammar.h"
using json = nlohmann::ordered_json; using json = nlohmann::ordered_json;

View File

@ -1,5 +1,5 @@
#include "unicode.h" #include "../src/unicode.h"
#include "llama-grammar.h" #include "../src/llama-grammar.h"
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>

View File

@ -2,10 +2,11 @@
#undef NDEBUG #undef NDEBUG
#endif #endif
#include "unicode.h"
#include "llama-grammar.h"
#include "json-schema-to-grammar.h" #include "json-schema-to-grammar.h"
#include "../src/unicode.h"
#include "../src/llama-grammar.h"
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -2,7 +2,6 @@
# undef NDEBUG # undef NDEBUG
#endif #endif
#include "unicode.h"
#include "sampling.h" #include "sampling.h"
#include <cassert> #include <cassert>
@ -84,7 +83,7 @@ static void test(const std::string & test_desc, const std::string & grammar_str,
fprintf(stderr, fprintf(stderr,
"\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following " "\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following "
"command: ./llama-gbnf-validator test-grammar-integration.grammar.gbnf " "command: ./test-gbnf-validator test-grammar-integration.grammar.gbnf "
"test-grammar-integration.string.txt\n\n"); "test-grammar-integration.string.txt\n\n");
} else { } else {
fprintf(stdout, "✅︎\n"); fprintf(stdout, "✅︎\n");

View File

@ -3,7 +3,9 @@
#endif #endif
#include "llama.h" #include "llama.h"
#include "llama-grammar.h"
// TODO: shold not include libllama sources
#include "../src/llama-grammar.h"
#include <cassert> #include <cassert>

View File

@ -4,7 +4,7 @@
#include "json-schema-to-grammar.h" #include "json-schema-to-grammar.h"
#include "llama-grammar.h" #include "../src/llama-grammar.h"
#include <cassert> #include <cassert>
#include <fstream> #include <fstream>

View File

@ -3,7 +3,8 @@
#endif #endif
#include "llama.h" #include "llama.h"
#include "llama-grammar.h"
#include "../src/llama-grammar.h"
#include <cassert> #include <cassert>
#include <stdexcept> #include <stdexcept>

View File

@ -1,8 +1,9 @@
#include "ggml.h" #include "ggml.h"
#include "llama.h" #include "llama.h"
#include "llama-model.h"
#include "common.h" #include "common.h"
#include "../src/llama-model.h"
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
#include <cinttypes> #include <cinttypes>

View File

@ -1,8 +1,9 @@
#include "llama.h" #include "llama.h"
#include "common.h" #include "common.h"
#include "unicode.h"
#include "console.h" #include "console.h"
#include "../src/unicode.h"
#include <cassert> #include <cassert>
#include <codecvt> #include <codecvt>
#include <cstdio> #include <cstdio>

View File

@ -1,8 +1,9 @@
#include "llama.h" #include "llama.h"
#include "common.h" #include "common.h"
#include "unicode.h"
#include "console.h" #include "console.h"
#include "../src/unicode.h"
#include <cassert> #include <cassert>
#include <codecvt> #include <codecvt>
#include <cstdio> #include <cstdio>