diff --git a/LLAMA_CPP_VERSION b/LLAMA_CPP_VERSION index 7f559d93..38e2f857 100644 --- a/LLAMA_CPP_VERSION +++ b/LLAMA_CPP_VERSION @@ -1 +1 @@ -b9509 +b9626 diff --git a/llama/compat/llama-cpp-hooks.patch b/llama/compat/001-llama-cpp-hooks.patch similarity index 100% rename from llama/compat/llama-cpp-hooks.patch rename to llama/compat/001-llama-cpp-hooks.patch diff --git a/llama/compat/002-llama-cpp-ui-empty-assets.patch b/llama/compat/002-llama-cpp-ui-empty-assets.patch new file mode 100644 index 00000000..31e90898 --- /dev/null +++ b/llama/compat/002-llama-cpp-ui-empty-assets.patch @@ -0,0 +1,15 @@ +diff --git a/tools/ui/embed.cpp b/tools/ui/embed.cpp +--- a/tools/ui/embed.cpp ++++ b/tools/ui/embed.cpp +@@ -147,9 +147,9 @@ int main(int argc, char ** argv) { + + const std::string out_cpp = argv[1]; + const std::string out_h = argv[2]; +- const std::string asset_dir = argv[3]; ++ const std::string asset_dir = argc == 4 ? argv[3] : ""; + +- const bool use_gzip = std::filesystem::exists(asset_dir + "/_gzip"); ++ const bool use_gzip = !asset_dir.empty() && std::filesystem::exists(asset_dir + "/_gzip"); + const std::string in_dir = use_gzip ? (asset_dir + "/_gzip") : asset_dir; + + std::vector assets; diff --git a/llama/compat/README.md b/llama/compat/README.md index 8c356a7d..a944c89b 100644 --- a/llama/compat/README.md +++ b/llama/compat/README.md @@ -23,11 +23,14 @@ intentionally skipped so a developer can iterate on a local llama.cpp tree. - `llama-ollama-compat-util.h`, `llama-ollama-compat-util.cpp` - helpers for KV edits, tensor renames, skip-prefix tracking, tensor load operations, and small tensor repacking primitives. -- `llama-cpp-hooks.patch` - small additive call-site edits in llama.cpp files. +- `001-llama-cpp-hooks.patch` - small additive call-site edits in llama.cpp files. It currently touches `src/llama-model-loader.cpp` and `tools/mtmd/clip.cpp`. +- `002-llama-cpp-ui-empty-assets.patch` - lets the llama.cpp UI embed helper + generate an empty asset table when no UI assets are present. - `compat.cmake`, `apply-patch.cmake` - CMake glue and an idempotent applier (used by `llama/server/CMakeLists.txt`) that applies every `*.patch` under - this directory — the hooks patch plus each `models/` architecture patch. + this directory by numeric filename order — the hooks patch plus each + `models/` architecture patch. - `models/` - the sibling **new-architecture** layer: implementations of architectures llama.cpp doesn't support yet, each added via a small registration patch. (Those files *add* archs; the files above *translate* @@ -116,7 +119,7 @@ cd /path/to/llama.cpp git diff -- \ src/llama-model-loader.cpp \ tools/mtmd/clip.cpp \ - > /path/to/ollama/llama/compat/llama-cpp-hooks.patch + > /path/to/ollama/llama/compat/001-llama-cpp-hooks.patch ``` ## Implementation Notes diff --git a/llama/compat/apply-patch.cmake b/llama/compat/apply-patch.cmake index e7ca91af..1f557c2c 100644 --- a/llama/compat/apply-patch.cmake +++ b/llama/compat/apply-patch.cmake @@ -3,10 +3,11 @@ # Invocation (from a CMake PATCH_COMMAND): # cmake -DPATCH_DIR= -P apply-patch.cmake # -# Every *.patch under PATCH_DIR is applied in the current working directory -# (which ExternalProject / FetchContent sets to the fetched source's -# SOURCE_DIR). A patch already applied — detected via `git apply --reverse -# --check` — is skipped. This makes re-configuring and re-building safe. +# Every *.patch under PATCH_DIR is applied in numeric filename order in the +# current working directory (which ExternalProject / FetchContent sets to the +# fetched source's SOURCE_DIR). A patch already applied — detected via +# `git apply --reverse --check` — is skipped. This makes re-configuring and +# re-building safe. if(NOT DEFINED PATCH_DIR) message(FATAL_ERROR "apply-patch.cmake: PATCH_DIR not set") @@ -19,8 +20,17 @@ get_filename_component(_git_ceiling "${_patch_workdir}" DIRECTORY) set(_git_apply_env GIT_CEILING_DIRECTORIES=${_git_ceiling}) file(GLOB_RECURSE _patches "${PATCH_DIR}/*.patch") -list(SORT _patches) +set(_patch_entries) foreach(PATCH_FILE IN LISTS _patches) + get_filename_component(_patch_name "${PATCH_FILE}" NAME) + list(APPEND _patch_entries "${_patch_name}|${PATCH_FILE}") +endforeach() + +list(SORT _patch_entries) +foreach(_patch_entry IN LISTS _patch_entries) + string(REGEX REPLACE "^[^|]*\\|" "" PATCH_FILE "${_patch_entry}") + file(RELATIVE_PATH _patch_rel "${PATCH_DIR}" "${PATCH_FILE}") + # If the patch can be REVERSED cleanly, it's already applied. Skip. execute_process( COMMAND ${CMAKE_COMMAND} -E env ${_git_apply_env} @@ -29,7 +39,7 @@ foreach(PATCH_FILE IN LISTS _patches) OUTPUT_QUIET ERROR_QUIET ) if(_reverse_check EQUAL 0) - message(STATUS "llama/compat: patch already applied, skipping") + message(STATUS "llama/compat: ${_patch_rel} already applied, skipping") continue() endif() @@ -41,10 +51,10 @@ foreach(PATCH_FILE IN LISTS _patches) ) if(NOT _apply_result EQUAL 0) message(FATAL_ERROR - "llama/compat: failed to apply ${PATCH_FILE}\n" + "llama/compat: failed to apply ${_patch_rel}\n" "This usually means the pinned llama.cpp source has changed. " "Regenerate the patch against the pinned LLAMA_CPP_VERSION and retry.") endif() - message(STATUS "llama/compat: applied patch") + message(STATUS "llama/compat: applied ${_patch_rel}") endforeach() diff --git a/llama/compat/compat.cmake b/llama/compat/compat.cmake index d3da9815..02a5b56e 100644 --- a/llama/compat/compat.cmake +++ b/llama/compat/compat.cmake @@ -18,7 +18,7 @@ # The compat layer consists of: # 1. Ollama-owned compat source files linked into the fetched llama.cpp # targets from this directory. -# 2. A small patch file that adds call-sites in llama.cpp loaders. +# 2. A small ordered patch set that adds call-sites in llama.cpp loaders. set(_compat_dir ${CMAKE_CURRENT_LIST_DIR}) @@ -46,7 +46,7 @@ set(OLLAMA_LLAMA_CPP_COMPAT_DIR # Also export the individual paths in case callers want to do something # custom (e.g. emit a dependency on the patch so reconfigures re-apply). set(OLLAMA_LLAMA_CPP_COMPAT_PATCH_FILE - "${_compat_dir}/llama-cpp-hooks.patch" + "${_compat_dir}/001-llama-cpp-hooks.patch" CACHE INTERNAL "Path to the llama.cpp compat patch") set(OLLAMA_LLAMA_CPP_COMPAT_SOURCES diff --git a/llama/compat/models/llama-cpp-laguna.patch b/llama/compat/models/003-llama-cpp-laguna.patch similarity index 98% rename from llama/compat/models/llama-cpp-laguna.patch rename to llama/compat/models/003-llama-cpp-laguna.patch index 30b16170..13e162bf 100644 --- a/llama/compat/models/llama-cpp-laguna.patch +++ b/llama/compat/models/003-llama-cpp-laguna.patch @@ -16,8 +16,8 @@ diff --git a/src/llama-arch.cpp b/src/llama-arch.cpp diff --git a/src/llama-arch.h b/src/llama-arch.h --- a/src/llama-arch.h +++ b/src/llama-arch.h -@@ -140,2 +140,3 @@ enum llm_arch { - LLM_ARCH_MELLUM, +@@ -145,2 +145,3 @@ enum llm_arch { + LLM_ARCH_EAGLE3, + LLM_ARCH_LAGUNA, LLM_ARCH_UNKNOWN, @@ -382,2 +383,3 @@ enum llm_tensor { diff --git a/llama/compat/models/laguna.cpp b/llama/compat/models/laguna.cpp index 04947432..5a41142a 100644 --- a/llama/compat/models/laguna.cpp +++ b/llama/compat/models/laguna.cpp @@ -14,7 +14,7 @@ void llama_model_laguna::load_arch_hparams(llama_model_loader & ml) { ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa, false); hparams.swa_type = LLAMA_SWA_TYPE_STANDARD; - ml.get_key_or_arr("laguna.attention.layer_types", hparams.is_swa_impl, hparams.n_layer, false); + ml.get_key_or_arr("laguna.attention.layer_types", hparams.is_swa_impl, hparams.n_layer(), false); ml.get_key("laguna.rope.swa.dimension_count", hparams.n_rot_swa, false); ml.get_key("laguna.rope.swa.freq_base", hparams.rope_freq_base_train_swa, false);