From 9a99293174ccea2f0f989c8636f4e0df0ca1196f Mon Sep 17 00:00:00 2001 From: slaren Date: Thu, 31 Oct 2024 19:34:15 +0100 Subject: [PATCH] use sorted map, sort weights by layer --- src/llama.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/llama.cpp b/src/llama.cpp index 9002ccd24..bc94d7ff0 100644 --- a/src/llama.cpp +++ b/src/llama.cpp @@ -4284,7 +4284,21 @@ struct llama_model_loader { } }; - std::unordered_map weights_map; + // custom comparator to sort weights more nicely by layer + struct weight_name_comparer { + bool operator()(const std::string & a, const std::string & b) const { + int a_layer = -1; + int b_layer = -1; + sscanf(a.c_str(), "blk.%d.", &a_layer); + sscanf(b.c_str(), "blk.%d.", &b_layer); + if (a_layer != b_layer) { + return a_layer < b_layer; + } + return a < b; + } + }; + + std::map weights_map; std::unordered_map kv_overrides; struct gguf_context * meta = NULL;