Skip to content

Commit 9a99293

Browse files
committed
use sorted map, sort weights by layer
1 parent 13eba91 commit 9a99293

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/llama.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4284,7 +4284,21 @@ struct llama_model_loader {
42844284
}
42854285
};
42864286

4287-
std::unordered_map<std::string, struct llama_tensor_weight> weights_map;
4287+
// custom comparator to sort weights more nicely by layer
4288+
struct weight_name_comparer {
4289+
bool operator()(const std::string & a, const std::string & b) const {
4290+
int a_layer = -1;
4291+
int b_layer = -1;
4292+
sscanf(a.c_str(), "blk.%d.", &a_layer);
4293+
sscanf(b.c_str(), "blk.%d.", &b_layer);
4294+
if (a_layer != b_layer) {
4295+
return a_layer < b_layer;
4296+
}
4297+
return a < b;
4298+
}
4299+
};
4300+
4301+
std::map<std::string, struct llama_tensor_weight, weight_name_comparer> weights_map;
42884302
std::unordered_map<std::string, struct llama_model_kv_override> kv_overrides;
42894303

42904304
struct gguf_context * meta = NULL;

0 commit comments

Comments
 (0)