commit 6b0785b7328421fb726c2a12bb75f3c7712901b1
parent 98670ac352e21fabc898673125051c49cf46d694
Author: Vineet Kumar <git@vineetk.net>
Date: Wed, 18 Nov 2026 18:36:37 +0100
packages/machine-learning: patch llama.cpp to include support for pulpie eurobert's classification head
Diffstat:
1 file changed, 42 insertions(+), 1 deletion(-)
diff --git a/epistemia/packages/machine-learning.scm b/epistemia/packages/machine-learning.scm
@@ -95,7 +95,48 @@
(commit tag)))
(file-name (git-file-name name tag))
(sha256
- (base32 "0av95i8na29mh7jg5jl8v22k6bxhrzpwn0b0s73inlspwhf97nvw"))))
+ (base32 "0av95i8na29mh7jg5jl8v22k6bxhrzpwn0b0s73inlspwhf97nvw"))
+ (patches (list (plain-file "pulpie-eurobert.patch" "\
+diff --git a/src/models/eurobert.cpp b/src/models/eurobert.cpp
+index 7a42f0dbf..9047f1b97 100644
+--- a/src/models/eurobert.cpp
++++ b/src/models/eurobert.cpp
+@@ -15,6 +15,18 @@ void llama_model_eurobert::load_arch_tensors(llama_model_loader &) {
+
+ output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, \"weight\"), {n_embd}, 0);
+
++ // optional token-classification head (e.g. main-content extraction models).
++ // applied per position in the graph below, so it stays independent of the
++ // sequence pooling type.
++ cls_out = create_tensor(tn(LLM_TENSOR_CLS_OUT, \"weight\"), {n_embd, hparams.n_cls_out}, TENSOR_NOT_REQUIRED);
++ cls_out_b = create_tensor(tn(LLM_TENSOR_CLS_OUT, \"bias\"), {hparams.n_cls_out}, TENSOR_NOT_REQUIRED);
++
++ if (cls_out) {
++ // the graph below emits n_cls_out values per token, so the embedding
++ // output is no longer n_embd wide. covers GGUFs that omit embedding_length_out.
++ hparams.n_embd_out_impl = hparams.n_cls_out;
++ }
++
+ for (int i = 0; i < n_layer; ++i) {
+ auto & layer = layers[i];
+
+@@ -110,4 +122,16 @@ llama_model_eurobert::graph::graph(const llm_graph_params & params) : llm_graph_
+
+ cb(cur, \"result_embd\", -1);
+ res->t_embd = cur;
++
++ if (model.cls_out) {
++ // classify every position, not just the pooled sequence: the caller reads
++ // one n_cls_out-sized row per token.
++ ggml_tensor * embd = build_lora_mm(model.cls_out, cur);
++ if (model.cls_out_b) {
++ embd = ggml_add(ctx0, embd, model.cls_out_b);
++ }
++ cb(embd, \"result_embd_proj\", -1);
++ res->t_embd = embd;
++ ggml_build_forward_expand(gf, embd);
++ }
+ }\n")))))
(arguments
(substitute-keyword-arguments (package-arguments llama-cpp)
((#:configure-flags flags #~'())