Files
Timothy Nikkel e3bfebe1ae Bug 2063948. Make third_party/llama.cpp vendor again. r=padenot
Two things stop `./mach vendor` from reproducing the tree, both from the patch rebase in
bug 2043658.

exceptions.patch has a hunk for src/models/models.h that removes
`#include "moz-overrides.h"`, where its other fourteen hunks add that include. The patch is
the first one applied, so its base is pristine upstream, which has no such line and cannot
have it removed. patch reports

  1 out of 1 hunks ignored--saving rejects to 'src/models/models.h.rej'

and vendoring stops there, before the other twelve patches are applied at all. The tree has
the include, so only the patch file is wrong; regenerate the hunk to add it.

The include reordering in fifteen files is not in any patch. "Rebase patch 1 (exceptions)"
moved the system headers ahead of models.h in src/llama-model.cpp and fourteen
src/models/*.cpp, directly in the sources, so re-vendoring puts back upstream's order. That
ordering matters now that models.h pulls in moz-overrides.h, which redefines the catch
macros: the reorder keeps those out of the system headers. Capture it as include-order.patch,
listed last so it applies on top of the other thirteen.

Also point the moz.yaml at Core :: Machine Learning: General rather than Core :: xul, which
is what moz.build says for this directory. Updatebot files from the moz.yaml block, so its
update bugs were going to xul.

With both, `./mach vendor third_party/llama.cpp/moz.yaml -r
74ade52741203e5c8f81eaf06a96cb1cfe15f2a3 --patch-mode check --force` reproduces the
committed tree exactly.

Neither was visible without running the vendoring: the sources in the tree are correct, and
nothing checked that they could be regenerated from the manifest until now.

Differential Revision: https://phabricator.services.mozilla.com/D318988
2026-08-17 11:50:19 +00:00

219 lines
6.1 KiB
Diff

diff --git a/ggml/src/gguf.cpp b/ggml/src/gguf.cpp
index 5e1986182515..61026df1c6ab 100644
--- a/ggml/src/gguf.cpp
+++ b/ggml/src/gguf.cpp
@@ -15,6 +15,8 @@
#include <string>
#include <vector>
+#include "moz-overrides.h"
+
#define GGUF_MAX_STRING_LENGTH (1024*1024*1024)
#define GGUF_MAX_ARRAY_ELEMENTS (1024*1024*1024)
diff --git a/src/llama-adapter.cpp b/src/llama-adapter.cpp
index 3e0fe66afff7..95f50e05ccd8 100644
--- a/src/llama-adapter.cpp
+++ b/src/llama-adapter.cpp
@@ -9,6 +9,8 @@
#include <sstream>
#include <stdexcept>
+#include "moz-overrides.h"
+
// vec
ggml_tensor * llama_adapter_cvec::tensor_for(int il) const {
diff --git a/src/llama-chat.cpp b/src/llama-chat.cpp
index 6d822ec62d6b..c83e6b5ba0d4 100644
--- a/src/llama-chat.cpp
+++ b/src/llama-chat.cpp
@@ -6,6 +6,8 @@
#include <sstream>
#include <algorithm>
+#include "moz-overrides.h"
+
#if __cplusplus >= 202000L
#define LU8(x) (const char*)(u8##x)
#else
diff --git a/src/llama-context.cpp b/src/llama-context.cpp
index 168dbabd7667..2de0c7ad45f4 100644
--- a/src/llama-context.cpp
+++ b/src/llama-context.cpp
@@ -18,6 +18,8 @@
#include <limits>
#include <stdexcept>
+#include "moz-overrides.h"
+
//
// llama_context
//
diff --git a/src/llama-grammar.cpp b/src/llama-grammar.cpp
index badcbfd0fbb6..3872a7641f70 100644
--- a/src/llama-grammar.cpp
+++ b/src/llama-grammar.cpp
@@ -10,7 +10,10 @@
#include <set>
#include <stdexcept>
+#include "moz-overrides.h"
+
#define MAX_REPETITION_THRESHOLD 2000
+
//
// helpers
//
diff --git a/src/llama-kv-cache.cpp b/src/llama-kv-cache.cpp
index 2802103bdd82..289a6a0c086e 100644
--- a/src/llama-kv-cache.cpp
+++ b/src/llama-kv-cache.cpp
@@ -13,6 +13,8 @@
#include <map>
#include <stdexcept>
+#include "moz-overrides.h"
+
static bool ggml_is_power_of_2(int n) {
return (n & (n - 1)) == 0;
}
diff --git a/src/llama-memory-recurrent.cpp b/src/llama-memory-recurrent.cpp
index 6a4892fb471d..f300c1afacbb 100644
--- a/src/llama-memory-recurrent.cpp
+++ b/src/llama-memory-recurrent.cpp
@@ -13,6 +13,8 @@
#include <map>
#include <stdexcept>
+#include "moz-overrides.h"
+
//
// llama_memory_recurrent
//
diff --git a/src/llama-mmap.cpp b/src/llama-mmap.cpp
index ed572da7fb54..0e4c620c5dd4 100644
--- a/src/llama-mmap.cpp
+++ b/src/llama-mmap.cpp
@@ -40,6 +40,8 @@
#include <TargetConditionals.h>
#endif
+#include "moz-overrides.h"
+
#ifdef _WIN32
# define llama_mmap_ftell _ftelli64
# define llama_mmap_fseek _fseeki64
diff --git a/src/llama-model-loader.cpp b/src/llama-model-loader.cpp
index 474cabdfc095..4456259be12d 100644
--- a/src/llama-model-loader.cpp
+++ b/src/llama-model-loader.cpp
@@ -13,6 +13,8 @@
#include <future>
#include <regex>
+#include "moz-overrides.h"
+
static const size_t kiB = 1024;
static const size_t MiB = 1024*kiB;
static const size_t GiB = 1024*MiB;
diff --git a/src/llama-model-loader.h b/src/llama-model-loader.h
index c476026d3e51..1a1c4c4db4db 100644
--- a/src/llama-model-loader.h
+++ b/src/llama-model-loader.h
@@ -39,12 +39,14 @@ struct llama_model_loader {
llama_tensor_weight(const llama_file * file, uint16_t idx, const struct gguf_context * gguf_ctx, ggml_tensor * tensor) : idx(idx), tensor(tensor) {
const int tensor_idx = gguf_find_tensor(gguf_ctx, ggml_get_name(tensor));
if (tensor_idx < 0) {
- throw std::runtime_error(format("tensor '%s' not found in the model", ggml_get_name(tensor)));
+ // throw std::runtime_error(format("tensor '%s' not found in the model", ggml_get_name(tensor)));
+ std::abort();
}
offs = gguf_get_data_offset(gguf_ctx) + gguf_get_tensor_offset(gguf_ctx, tensor_idx);
if (offs + ggml_nbytes(tensor) < offs || offs + ggml_nbytes(tensor) > file->size()) {
- throw std::runtime_error(format("tensor '%s' data is not within the file bounds, model is corrupted or incomplete", ggml_get_name(tensor)));
+ //throw std::runtime_error(format("tensor '%s' data is not within the file bounds, model is corrupted or incomplete", ggml_get_name(tensor)));
+ std::abort();
}
}
};
diff --git a/src/llama-model.cpp b/src/llama-model.cpp
index c52875533905..f9a1a7a446b1 100644
--- a/src/llama-model.cpp
+++ b/src/llama-model.cpp
@@ -683,6 +683,8 @@ struct ggml_backend_meta_split_state llama_meta_device_get_split_state(const str
GGML_UNUSED(userdata);
}
+#include "moz-overrides.h"
+
const char * llm_type_name(llm_type type) {
switch (type) {
case LLM_TYPE_14M: return "14M";
diff --git a/src/llama-sampler.cpp b/src/llama-sampler.cpp
index 9bbc5dbde247..82f2babcab9b 100644
--- a/src/llama-sampler.cpp
+++ b/src/llama-sampler.cpp
@@ -20,6 +20,8 @@
#include <unordered_map>
#include <stdexcept>
+#include "moz-overrides.h"
+
// the ring buffer works similarly to std::deque, but with a fixed capacity
template<typename T>
struct ring_buffer {
diff --git a/src/llama-vocab.cpp b/src/llama-vocab.cpp
index 6e78a3f6c0ea..924957674a26 100644
--- a/src/llama-vocab.cpp
+++ b/src/llama-vocab.cpp
@@ -21,6 +21,8 @@
#include <set>
#include <unordered_map>
+#include "moz-overrides.h"
+
//
// helpers
//
diff --git a/src/llama.cpp b/src/llama.cpp
index a67fa8039a48..2b5726eb0f73 100644
--- a/src/llama.cpp
+++ b/src/llama.cpp
@@ -26,6 +26,8 @@
#include <stdexcept>
#include <vector>
+#include "moz-overrides.h"
+
#if defined(_MSC_VER)
#pragma warning(disable: 4244 4267) // possible loss of data
#endif
diff --git a/src/unicode.cpp b/src/unicode.cpp
index b02ecdc930fa..f7870412a3f4 100644
--- a/src/unicode.cpp
+++ b/src/unicode.cpp
@@ -13,6 +13,8 @@
#include <utility>
#include <vector>
+#include "moz-overrides.h"
+
size_t unicode_len_utf8(char src) {
const size_t lookup[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 4 };
uint8_t highbits = static_cast<uint8_t>(src) >> 4;
diff --git a/src/models/models.h b/src/models/models.h
index 19a4d3c5eaf4..2ac8415a3639 100644
--- a/src/models/models.h
+++ b/src/models/models.h
@@ -6,6 +6,8 @@
// note: almost all graphs require at least sqrtf, so include cmath globally
#include <cmath>
+
+#include "moz-overrides.h"
//
// base classes