MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / get_key_or_arr

Method get_key_or_arr

subprojects/llama.cpp/src/llama-model-loader.cpp:429–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

427 // get array of n <= N_MAX elements, or a single element repeated n times
428 template<typename T, size_t N_MAX>
429 bool llama_model_loader::get_key_or_arr(const std::string & key, std::array<T, N_MAX> & result, uint32_t n, bool required) {
430 const int kid = gguf_find_key(meta.get(), key.c_str());
431
432 if (kid < 0) {
433 if (required) {
434 throw std::runtime_error(format("key not found in model: %s", key.c_str()));
435 }
436 return false;
437 }
438
439 if (n > N_MAX) {
440 throw std::runtime_error(format("n > N_MAX: %u > %u for key %s", (uint32_t) n, (uint32_t) N_MAX, key.c_str()));
441 }
442
443 if (gguf_get_kv_type(meta.get(), kid) == GGUF_TYPE_ARRAY) {
444 struct GGUFMeta::ArrayInfo arr_info =
445 GGUFMeta::GKV<GGUFMeta::ArrayInfo>::get_kv(meta.get(), kid);
446
447 if (n != arr_info.length) {
448 throw std::runtime_error(format("key %s has wrong array length; expected %u, got %u", key.c_str(), n, (uint32_t) arr_info.length));
449 }
450
451 return get_arr(key, result, required);
452 }
453
454 T value;
455
456 bool ok = get_key(key, value, required);
457 if (!ok) {
458 return false;
459 }
460
461 for (uint32_t i = 0; i < n; i++) {
462 result[i] = value;
463 }
464
465 return true;
466 }
467
468 template<typename T>
469 bool llama_model_loader::get_key_or_arr(enum llm_kv kid, T & result, uint32_t n, bool required) {

Callers 1

load_hparamsMethod · 0.80

Calls 5

gguf_find_keyFunction · 0.85
formatFunction · 0.85
gguf_get_kv_typeFunction · 0.85
llm_kvEnum · 0.70
getMethod · 0.65

Tested by

no test coverage detected